Skip to content

Commit

Permalink
fix: show Import button only if has perms (apache#16763)
Browse files Browse the repository at this point in the history
* fix: show Import button only if has perms

* Fix tests
  • Loading branch information
betodealmeida authored Sep 23, 2021
1 parent bde6b60 commit ca2958d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/chart/ChartList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('RTL', () => {
});

it('renders an "Import Chart" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton);

await screen.findByRole('tooltip');
Expand Down
31 changes: 16 additions & 15 deletions superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,21 +586,22 @@ function ChartList(props: ChartListProps) {
window.location.assign('/chart/add');
},
});
}
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import charts')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openChartImportModal,
});

if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import charts')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openChartImportModal,
});
}
}
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('RTL', () => {
});

it('renders an "Import Dashboard" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton);

await screen.findByRole('tooltip');
Expand Down
31 changes: 16 additions & 15 deletions superset-frontend/src/views/CRUD/dashboard/DashboardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,22 @@ function DashboardList(props: DashboardListProps) {
window.location.assign('/dashboard/new');
},
});
}
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import dashboards')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openDashboardImportModal,
});

if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import dashboards')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openDashboardImportModal,
});
}
}
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('RTL', () => {
});

it('renders an "Import Database" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton);

await screen.findByRole('tooltip');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe('RTL', () => {
});

it('renders an "Import Dataset" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton);

await screen.findByRole('tooltip');
Expand Down
30 changes: 15 additions & 15 deletions superset-frontend/src/views/CRUD/data/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,22 +512,22 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
onClick: () => setDatasetAddModalOpen(true),
buttonStyle: 'primary',
});
}

if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
buttonArr.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import datasets')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openDatasetImportModal,
});
if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
buttonArr.push({
name: (
<Tooltip
id="import-tooltip"
title={t('Import datasets')}
placement="bottomRight"
>
<Icons.Import data-test="import-button" />
</Tooltip>
),
buttonStyle: 'link',
onClick: openDatasetImportModal,
});
}
}

menuData.buttons = buttonArr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ describe('RTL', () => {
expect(exportTooltip).toBeInTheDocument();
});

it('renders an import button in the submenu', () => {
it('renders an import button in the submenu', async () => {
// Grab and assert that import saved query button is visible
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
expect(importButton).toBeVisible();
});

it('renders an "Import Saved Query" tooltip under import button', async () => {
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.hover(importButton);
waitFor(() => {
expect(importButton).toHaveClass('ant-tooltip-open');
Expand All @@ -303,9 +303,9 @@ describe('RTL', () => {
});
});

it('renders an import model when import button is clicked', async () => {
it('renders an import modal when import button is clicked', async () => {
// Grab and click import saved query button to reveal modal
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.click(importButton);

// Grab and assert that saved query import modal's heading is visible
Expand All @@ -315,9 +315,9 @@ describe('RTL', () => {
expect(importSavedQueryModalHeading).toBeVisible();
});

it('imports a saved query', () => {
it('imports a saved query', async () => {
// Grab and click import saved query button to reveal modal
const importButton = screen.getByTestId('import-button');
const importButton = await screen.findByTestId('import-button');
userEvent.click(importButton);

// Grab "Choose File" input from import modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function SavedQueryList({
refreshData();
};

const canCreate = hasPerm('can_write');
const canEdit = hasPerm('can_write');
const canDelete = hasPerm('can_write');
const canExport =
Expand Down Expand Up @@ -185,7 +186,7 @@ function SavedQueryList({
buttonStyle: 'primary',
});

if (isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
if (canCreate && isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT)) {
subMenuButtons.push({
name: (
<Tooltip
Expand Down

0 comments on commit ca2958d

Please sign in to comment.