-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(explore): missing column autocomplete in custom SQL (#29672)
- Loading branch information
1 parent
5ed1931
commit 3c97145
Showing
9 changed files
with
268 additions
and
30 deletions.
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', | ||
}), | ||
); | ||
} |