Skip to content
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: Add dataset visuals for when a table is selected #21893

Merged
merged 7 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,46 @@
* under the License.
*/
import React from 'react';
import { t, styled } from '@superset-ui/core';
import { supersetTheme, t, styled } from '@superset-ui/core';
import Icons from 'src/components/Icons';
import { EmptyStateBig } from 'src/components/EmptyState';
import RefreshLabel from 'src/components/RefreshLabel';

type DatasetPanelProps = {
tableName?: string | null | undefined;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the null | undefined taking into account that the field is optional? Cannot just be :
tableName?: string ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah good call! Corrected in this commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this prop is null when a table isn't selected so I added it to the type in this commit. Undefined wasn't needed here though, so still a good call, thanks! 😁

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heheh ok ok 😄

};

const StyledEmptyStateBig = styled(EmptyStateBig)`
p {
width: ${({ theme }) => theme.gridUnit * 115}px;
}
`;

const renderDescription = () => (
const StyledDatasetPanel = styled.div`
padding: ${({ theme }) => theme.gridUnit * 8}px
${({ theme }) => theme.gridUnit * 6}px;

.table-name {
font-size: ${({ theme }) => theme.gridUnit * 6}px;
font-weight: ${({ theme }) => theme.typography.weights.medium};
padding-bottom: ${({ theme }) => theme.gridUnit * 20}px;
margin: 0;

.anticon:first-of-type {
margin-right: ${({ theme }) => theme.gridUnit * 4}px;
}

.anticon:nth-of-type(2) {
margin-left: ${({ theme }) => theme.gridUnit * 4}px;
}
}

span {
font-weight: ${({ theme }) => theme.typography.weights.bold};
}
`;

const renderEmptyDescription = () => (
<>
{t(
'Datasets can be created from database tables or SQL queries. Select a database table to the left or ',
Expand All @@ -44,12 +74,29 @@ const renderDescription = () => (
</>
);

export default function DatasetPanel() {
return (
const DatasetPanel = ({ tableName }: DatasetPanelProps) =>
tableName ? (
<StyledDatasetPanel>
<div className="table-name">
<Icons.Table iconColor={supersetTheme.colors.grayscale.base} />
{tableName}
<RefreshLabel
onClick={() => {
console.log(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this console log necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, it was more a flag/placeholder for when the functionality is added into the next ticket.

'This will refresh table columns once the table component is implemented',
);
}}
tooltipContent={t('Refresh table columns')}
/>
</div>
<span>{t('Table columns')}</span>
</StyledDatasetPanel>
) : (
<StyledEmptyStateBig
image="empty-dataset.svg"
title={t('Select dataset source')}
description={renderDescription()}
description={renderEmptyDescription()}
/>
);
}

export default DatasetPanel;
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export function datasetReducer(
}
}

const prevUrl =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still temporary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the status of this URL, I just moved it out so it didn't get lost in the middle of the other components.

'/tablemodelview/list/?pageIndex=0&sortColumn=changed_on_delta_humanized&sortOrder=desc';

export default function AddDataset() {
const [dataset, setDataset] = useReducer<
Reducer<Partial<DatasetObject> | null, DSReducerActionType>
Expand All @@ -81,8 +84,10 @@ export default function AddDataset() {
dbId={dataset?.db?.id}
/>
);
const prevUrl =
'/tablemodelview/list/?pageIndex=0&sortColumn=changed_on_delta_humanized&sortOrder=desc';

const DatasetPanelComponent = () => (
<DatasetPanel tableName={dataset?.table_name} />
);

const FooterComponent = () => (
<Footer url={prevUrl} datasetObject={dataset} />
Expand All @@ -92,7 +97,7 @@ export default function AddDataset() {
<DatasetLayout
header={HeaderComponent()}
leftPanel={LeftPanelComponent()}
datasetPanel={DatasetPanel()}
datasetPanel={DatasetPanelComponent()}
footer={FooterComponent()}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('DatasetLayout', () => {
});

it('renders a DatasetPanel when passed in', () => {
render(<DatasetLayout datasetPanel={DatasetPanel()} />);
render(<DatasetLayout datasetPanel={<DatasetPanel />} />);

const blankDatasetImg = screen.getByRole('img', { name: /empty/i });
const blankDatasetTitle = screen.getByText(/select dataset source/i);
Expand Down