-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(explore): missing column autocomplete in custom SQL #29672
Merged
justinpark
merged 2 commits into
apache:master
from
justinpark:fix--missing-column-autocomplete
Jul 26, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
superset-frontend/src/components/AsyncAceEditor/Tooltip.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import Tooltip, { getTooltipHTML } from './Tooltip'; | ||
|
||
test('should render a tooltip', () => { | ||
const expected = { | ||
title: 'tooltip title', | ||
icon: <div>icon</div>, | ||
body: <div>body</div>, | ||
meta: 'meta', | ||
footer: <div>footer</div>, | ||
}; | ||
render(<Tooltip {...expected} />); | ||
expect(screen.getByText(expected.title)).toBeInTheDocument(); | ||
expect(screen.getByText(expected.meta)).toBeInTheDocument(); | ||
expect(screen.getByText('icon')).toBeInTheDocument(); | ||
expect(screen.getByText('body')).toBeInTheDocument(); | ||
}); | ||
|
||
test('returns the tooltip HTML', () => { | ||
const html = getTooltipHTML({ | ||
title: 'tooltip title', | ||
icon: <div>icon</div>, | ||
body: <div>body</div>, | ||
meta: 'meta', | ||
footer: <div>footer</div>, | ||
}); | ||
expect(html).toContain('tooltip title'); | ||
}); |
57 changes: 57 additions & 0 deletions
57
superset-frontend/src/components/AsyncAceEditor/Tooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { Tag } from 'src/components'; | ||
|
||
type Props = { | ||
title: string; | ||
icon?: React.ReactNode; | ||
body?: React.ReactNode; | ||
meta?: string; | ||
footer?: React.ReactNode; | ||
}; | ||
|
||
export const Tooltip: React.FC<Props> = ({ | ||
title, | ||
icon, | ||
body, | ||
meta, | ||
footer, | ||
}) => ( | ||
<div className="tooltip-detail"> | ||
<div className="tooltip-detail-head"> | ||
<div className="tooltip-detail-title"> | ||
{icon} | ||
{title} | ||
</div> | ||
{meta && ( | ||
<span className="tooltip-detail-meta"> | ||
<Tag color="default">{meta}</Tag> | ||
</span> | ||
)} | ||
</div> | ||
{body && <div className="tooltip-detail-body">{body ?? title}</div>} | ||
{footer && <div className="tooltip-detail-footer">{footer}</div>} | ||
</div> | ||
); | ||
|
||
export const getTooltipHTML = (props: Props) => | ||
`${renderToStaticMarkup(<Tooltip {...props} />)}`; | ||
|
||
export default Tooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
superset-frontend/src/explore/controlUtils/getColumnKeywords.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getColumnKeywords } from './getColumnKeywords'; | ||
|
||
test('returns HTML for a column tooltip', () => { | ||
const expected = { | ||
column_name: 'test column1', | ||
verbose_name: null, | ||
is_certified: false, | ||
certified_by: null, | ||
description: 'test description', | ||
type: 'VARCHAR', | ||
}; | ||
expect(getColumnKeywords([expected])).toContainEqual({ | ||
name: expected.column_name, | ||
value: expected.column_name, | ||
docHTML: expect.stringContaining(expected.description), | ||
score: 50, | ||
meta: 'column', | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
superset-frontend/src/explore/controlUtils/getColumnKeywords.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ColumnMeta } from '@superset-ui/chart-controls'; | ||
import { t } from '@superset-ui/core'; | ||
import { getTooltipHTML } from 'src/components/AsyncAceEditor'; | ||
import { COLUMN_AUTOCOMPLETE_SCORE } from 'src/SqlLab/constants'; | ||
|
||
export function getColumnKeywords(columns: ColumnMeta[]) { | ||
return columns.map( | ||
({ | ||
column_name, | ||
verbose_name, | ||
is_certified, | ||
certified_by, | ||
description, | ||
type, | ||
}) => ({ | ||
name: verbose_name || column_name, | ||
value: column_name, | ||
docHTML: getTooltipHTML({ | ||
title: column_name, | ||
meta: type ? `column: ${type}` : 'column', | ||
body: `${description ?? ''}`, | ||
footer: is_certified ? ( | ||
<>{t('Certified by %s', certified_by)}</> | ||
) : undefined, | ||
}), | ||
score: COLUMN_AUTOCOMPLETE_SCORE, | ||
meta: 'column', | ||
}), | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinpark I noticed that
src/SqlLab/components/AceEditorWrapper/index.tsx
has similar logic as this code. Is it possible to avoid code duplication in this case and also ensure similar behavior for both editors by using a single component?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @michael-s-molina and I discussed offline, the SqlLab/AceEditorWrapper component has styles associated with the SqlLab Editor, and this section applies the global ace-editor styles.