-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
feat: Flow for tables that already have a dataset #22136
Changes from 7 commits
f5b01d5
16f1f6e
d697bbf
73c5950
4281a00
b58e689
8f47e55
8654966
ad13ff4
955ffc0
01f4ffa
f4a42c1
d77263d
0bed85a
5a3f188
11e2409
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,12 @@ | |
import React from 'react'; | ||
import { supersetTheme, t, styled } from '@superset-ui/core'; | ||
import Icons from 'src/components/Icons'; | ||
import Alert from 'src/components/Alert'; | ||
import Table, { ColumnsType, TableSize } from 'src/components/Table'; | ||
import { alphabeticalSort } from 'src/components/Table/sorters'; | ||
// @ts-ignore | ||
import LOADING_GIF from 'src/assets/images/loading.gif'; | ||
import { DatasetObject } from 'src/views/CRUD/data/dataset/AddDataset/types'; | ||
import { ITableColumn } from './types'; | ||
import MessageContent from './MessageContent'; | ||
|
||
|
@@ -54,8 +56,10 @@ const MARGIN_MULTIPLIER = 3; | |
|
||
const StyledHeader = styled.div<StyledHeaderProps>` | ||
position: ${(props: StyledHeaderProps) => props.position}; | ||
margin: ${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px; | ||
margin-top: ${({ theme }) => theme.gridUnit * (MARGIN_MULTIPLIER + 1)}px; | ||
margin: ${({ theme }) => theme.gridUnit * (MARGIN_MULTIPLIER + 1)}px | ||
${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px | ||
${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px | ||
${({ theme }) => theme.gridUnit * (MARGIN_MULTIPLIER + 3)}px; | ||
eschutho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
font-size: ${({ theme }) => theme.gridUnit * 6}px; | ||
font-weight: ${({ theme }) => theme.typography.weights.medium}; | ||
padding-bottom: ${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px; | ||
|
@@ -74,7 +78,7 @@ const StyledHeader = styled.div<StyledHeaderProps>` | |
`; | ||
|
||
const StyledTitle = styled.div` | ||
margin-left: ${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px; | ||
margin-left: ${({ theme }) => theme.gridUnit * (MARGIN_MULTIPLIER + 3)}px; | ||
margin-bottom: ${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px; | ||
font-weight: ${({ theme }) => theme.typography.weights.bold}; | ||
`; | ||
|
@@ -111,6 +115,7 @@ const StyledLoader = styled.div` | |
const TableContainer = styled.div` | ||
position: relative; | ||
margin: ${({ theme }) => theme.gridUnit * MARGIN_MULTIPLIER}px; | ||
margin-left: ${({ theme }) => theme.gridUnit * (MARGIN_MULTIPLIER + 3)}px; | ||
overflow: scroll; | ||
height: calc(100% - ${({ theme }) => theme.gridUnit * 36}px); | ||
`; | ||
|
@@ -123,6 +128,24 @@ const StyledTable = styled(Table)` | |
right: 0; | ||
`; | ||
|
||
const StyledAlert = styled(Alert)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to coment on line 20, we shuld repelase use of supertThem with: and replace all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIxed in |
||
border: 1px solid ${supersetTheme.colors.info.base}; | ||
padding: ${supersetTheme.gridUnit * 4}px; | ||
margin: ${supersetTheme.gridUnit * 6}px ${supersetTheme.gridUnit * 6}px | ||
${supersetTheme.gridUnit * 8}px; | ||
.view-dataset-button { | ||
position: absolute; | ||
top: ${supersetTheme.gridUnit * 4}px; | ||
right: ${supersetTheme.gridUnit * 4}px; | ||
font-weight: ${supersetTheme.typography.weights.normal}; | ||
|
||
&:hover { | ||
color: ${supersetTheme.colors.secondary.dark3}; | ||
text-decoration: underline; | ||
} | ||
} | ||
`; | ||
|
||
export const REFRESHING = t('Refreshing columns'); | ||
export const COLUMN_TITLE = t('Table columns'); | ||
export const ALT_LOADING = t('Loading'); | ||
|
@@ -168,15 +191,48 @@ export interface IDatasetPanelProps { | |
* Boolean indicating if the component is in a loading state | ||
*/ | ||
loading: boolean; | ||
linkedDatasets?: DatasetObject[] | undefined; | ||
} | ||
|
||
const renderExistingDatasetAlert = (linkedDataset: any) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put a type on this linkeddataset? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, good catch! Typed in |
||
<StyledAlert | ||
closable={false} | ||
type="info" | ||
showIcon | ||
message={t('This table already has a dataset')} | ||
description={ | ||
<> | ||
{t( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend defining all text using I am commenting once but recommend for anywhere Example can be seen on line 149, 150, 151 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation on this, I didn't realize it was running on each render/function call but it definitely makes sense! I fixed these spots and some others that I found in |
||
'You can only associate one dataset with one table. This table already has a dataset associated with it in Preset.\n', | ||
)} | ||
<span | ||
role="button" | ||
onClick={() => { | ||
window.open( | ||
linkedDataset.explore_url, | ||
'_blank', | ||
'noreferer noopener popup=false', | ||
); | ||
}} | ||
tabIndex={0} | ||
className="view-dataset-button" | ||
> | ||
{t('View Dataset')} | ||
</span> | ||
</> | ||
} | ||
/> | ||
); | ||
|
||
const DatasetPanel = ({ | ||
tableName, | ||
columnList, | ||
loading, | ||
hasError, | ||
linkedDatasets, | ||
}: IDatasetPanelProps) => { | ||
const hasColumns = columnList?.length > 0 ?? false; | ||
const linkedDatasetNames = linkedDatasets?.map(dataset => dataset.table_name); | ||
|
||
let component; | ||
if (loading) { | ||
|
@@ -217,17 +273,23 @@ const DatasetPanel = ({ | |
return ( | ||
<> | ||
{tableName && ( | ||
<StyledHeader | ||
position={ | ||
!loading && hasColumns ? EPosition.RELATIVE : EPosition.ABSOLUTE | ||
} | ||
title={tableName || ''} | ||
> | ||
{tableName && ( | ||
<Icons.Table iconColor={supersetTheme.colors.grayscale.base} /> | ||
)} | ||
{tableName} | ||
</StyledHeader> | ||
<> | ||
{linkedDatasetNames?.includes(tableName) && | ||
renderExistingDatasetAlert( | ||
linkedDatasets?.find(dataset => dataset.table_name === tableName), | ||
)} | ||
<StyledHeader | ||
position={ | ||
!loading && hasColumns ? EPosition.RELATIVE : EPosition.ABSOLUTE | ||
} | ||
title={tableName || ''} | ||
> | ||
{tableName && ( | ||
<Icons.Table iconColor={supersetTheme.colors.grayscale.base} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where I commented earlier use of supersetTheme directly is an anit pattern we did not catch in initial creation of this file. Above in the functional component we should have Then here use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIxed in |
||
)} | ||
{tableName} | ||
</StyledHeader> | ||
</> | ||
)} | ||
{component} | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
import React, { useEffect, useState, useRef } from 'react'; | ||
import { SupersetClient } from '@superset-ui/core'; | ||
import { DatasetObject } from 'src/views/CRUD/data/dataset/AddDataset/types'; | ||
import DatasetPanel from './DatasetPanel'; | ||
import { ITableColumn, IDatabaseTable, isIDatabaseTable } from './types'; | ||
|
||
|
@@ -53,13 +54,15 @@ export interface IDatasetPanelWrapperProps { | |
*/ | ||
schema?: string | null; | ||
setHasColumns?: Function; | ||
linkedDatasets?: DatasetObject[] | undefined; | ||
} | ||
|
||
const DatasetPanelWrapper = ({ | ||
tableName, | ||
dbId, | ||
schema, | ||
setHasColumns, | ||
linkedDatasets, | ||
}: IDatasetPanelWrapperProps) => { | ||
const [columnList, setColumnList] = useState<ITableColumn[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
|
@@ -110,7 +113,7 @@ const DatasetPanelWrapper = ({ | |
if (tableName && schema && dbId) { | ||
getTableMetadata({ tableName, dbId, schema }); | ||
} | ||
// getTableMetadata is a const and should not be independency array | ||
// getTableMetadata is a const and should not be in dependency array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! 😁 |
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [tableName, dbId, schema]); | ||
|
||
|
@@ -120,6 +123,7 @@ const DatasetPanelWrapper = ({ | |
hasError={hasError} | ||
loading={loading} | ||
tableName={tableName} | ||
linkedDatasets={linkedDatasets} | ||
/> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ interface FooterProps { | |
datasetObject?: Partial<DatasetObject> | null; | ||
onDatasetAdd?: (dataset: DatasetObject) => void; | ||
hasColumns?: boolean; | ||
linkedDatasets?: (string | null | undefined)[] | undefined; | ||
} | ||
|
||
const INPUT_FIELDS = ['db', 'schema', 'table_name']; | ||
|
@@ -52,6 +53,7 @@ function Footer({ | |
datasetObject, | ||
addDangerToast, | ||
hasColumns = false, | ||
linkedDatasets, | ||
}: FooterProps) { | ||
const { createResource } = useSingleViewResource<Partial<DatasetObject>>( | ||
'dataset', | ||
|
@@ -113,7 +115,11 @@ function Footer({ | |
<Button onClick={cancelButtonOnClick}>Cancel</Button> | ||
<Button | ||
buttonStyle="primary" | ||
disabled={!datasetObject?.table_name || !hasColumns} | ||
disabled={ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nit, but since this disabled check is getting kind of long it may be worth defining a variable doing this check before the return JSX block which will make the code easier to debug in future and keep the actual JSX portion cleaner. Example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah good call, much cleaner! Changed in |
||
!datasetObject?.table_name || | ||
!hasColumns || | ||
linkedDatasets?.includes(datasetObject?.table_name) | ||
} | ||
tooltip={!datasetObject?.table_name ? tooltipText : undefined} | ||
onClick={onSave} | ||
> | ||
|
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.
@lyndsiWilliams I missed this when we originally worked on DatasetPanel but using supersetTheme directly is an anti-pattern. We should remove this import, and instead bring in useTheme
import { useTheme, t, styled } from '@superset-ui/core';
At line 131-148, and line 288, anywhere else we directly use supersetTheme should be changed.
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.
FIxed in
this commit
.