-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tabs to edit dataset page (#22043)
Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Co-authored-by: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com> Co-authored-by: lyndsiWilliams <kcatgirl@gmail.com>
- Loading branch information
1 parent
4b05a1e
commit c05871e
Showing
7 changed files
with
237 additions
and
75 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/EditDataset.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,43 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import fetchMock from 'fetch-mock'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import EditDataset from './index'; | ||
|
||
const DATASET_ENDPOINT = 'glob:*api/v1/dataset/1/related_objects'; | ||
|
||
const mockedProps = { | ||
id: '1', | ||
}; | ||
|
||
fetchMock.get(DATASET_ENDPOINT, { charts: { results: [], count: 2 } }); | ||
|
||
test('should render edit dataset view with tabs', async () => { | ||
render(<EditDataset {...mockedProps} />); | ||
|
||
const columnTab = await screen.findByRole('tab', { name: /columns/i }); | ||
const metricsTab = screen.getByRole('tab', { name: /metrics/i }); | ||
const usageTab = screen.getByRole('tab', { name: /usage/i }); | ||
|
||
expect(fetchMock.calls(DATASET_ENDPOINT)).toBeTruthy(); | ||
expect(columnTab).toBeInTheDocument(); | ||
expect(metricsTab).toBeInTheDocument(); | ||
expect(usageTab).toBeInTheDocument(); | ||
}); |
74 changes: 74 additions & 0 deletions
74
superset-frontend/src/views/CRUD/data/dataset/AddDataset/EditDataset/index.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,74 @@ | ||
/** | ||
* 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 { styled, t } from '@superset-ui/core'; | ||
import React from 'react'; | ||
import { useGetDatasetRelatedCounts } from 'src/views/CRUD/data/hooks'; | ||
import Badge from 'src/components/Badge'; | ||
import Tabs from 'src/components/Tabs'; | ||
|
||
const StyledTabs = styled(Tabs)` | ||
${({ theme }) => ` | ||
margin-top: ${theme.gridUnit * 8.5}px; | ||
padding-left: ${theme.gridUnit * 4}px; | ||
.ant-tabs-top > .ant-tabs-nav::before { | ||
width: ${theme.gridUnit * 50}px; | ||
} | ||
`} | ||
`; | ||
|
||
const TabStyles = styled.div` | ||
${({ theme }) => ` | ||
.ant-badge { | ||
width: ${theme.gridUnit * 8}px; | ||
margin-left: ${theme.gridUnit * 2.5}px; | ||
} | ||
`} | ||
`; | ||
|
||
interface EditPageProps { | ||
id: string; | ||
} | ||
|
||
const TRANSLATIONS = { | ||
USAGE_TEXT: t('Usage'), | ||
COLUMNS_TEXT: t('Columns'), | ||
METRICS_TEXT: t('Metrics'), | ||
}; | ||
|
||
const EditPage = ({ id }: EditPageProps) => { | ||
const { usageCount } = useGetDatasetRelatedCounts(id); | ||
|
||
const usageTab = ( | ||
<TabStyles> | ||
<span>{TRANSLATIONS.USAGE_TEXT}</span> | ||
{usageCount > 0 && <Badge count={usageCount} />} | ||
</TabStyles> | ||
); | ||
|
||
return ( | ||
<StyledTabs moreIcon={null} fullWidth={false}> | ||
<Tabs.TabPane tab={TRANSLATIONS.COLUMNS_TEXT} key="1" /> | ||
<Tabs.TabPane tab={TRANSLATIONS.METRICS_TEXT} key="2" /> | ||
<Tabs.TabPane tab={usageTab} key="3" /> | ||
</StyledTabs> | ||
); | ||
}; | ||
|
||
export default EditPage; |
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