Skip to content

Commit

Permalink
Revert "feat: Virtual dataset duplication (apache#20309)"
Browse files Browse the repository at this point in the history
This reverts commit 16032ed.
  • Loading branch information
jinghua-qa committed Sep 19, 2022
1 parent 973d870 commit d2d39fc
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 1,560 deletions.
1,263 changes: 203 additions & 1,060 deletions docs/static/resources/openapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const store = mockStore({});
const datasetsInfoEndpoint = 'glob:*/api/v1/dataset/_info*';
const datasetsOwnersEndpoint = 'glob:*/api/v1/dataset/related/owners*';
const datasetsSchemaEndpoint = 'glob:*/api/v1/dataset/distinct/schema*';
const datasetsDuplicateEndpoint = 'glob:*/api/v1/dataset/duplicate*';
const databaseEndpoint = 'glob:*/api/v1/dataset/related/database*';
const datasetsEndpoint = 'glob:*/api/v1/dataset/?*';

Expand All @@ -64,17 +63,14 @@ const mockUser = {
};

fetchMock.get(datasetsInfoEndpoint, {
permissions: ['can_read', 'can_write', 'can_duplicate'],
permissions: ['can_read', 'can_write'],
});
fetchMock.get(datasetsOwnersEndpoint, {
result: [],
});
fetchMock.get(datasetsSchemaEndpoint, {
result: [],
});
fetchMock.post(datasetsDuplicateEndpoint, {
result: [],
});
fetchMock.get(datasetsEndpoint, {
result: mockdatasets,
dataset_count: 3,
Expand Down Expand Up @@ -185,44 +181,6 @@ describe('DatasetList', () => {
wrapper.find('[data-test="bulk-select-copy"]').text(),
).toMatchInlineSnapshot(`"3 Selected (2 Physical, 1 Virtual)"`);
});

it('shows duplicate modal when duplicate action is clicked', async () => {
await waitForComponentToPaint(wrapper);
expect(
wrapper.find('[data-test="duplicate-modal-input"]').exists(),
).toBeFalsy();
act(() => {
wrapper
.find('#duplicate-action-tooltop')
.at(0)
.find('.action-button')
.props()
.onClick();
});
await waitForComponentToPaint(wrapper);
expect(
wrapper.find('[data-test="duplicate-modal-input"]').exists(),
).toBeTruthy();
});

it('calls the duplicate endpoint', async () => {
await waitForComponentToPaint(wrapper);
await act(async () => {
wrapper
.find('#duplicate-action-tooltop')
.at(0)
.find('.action-button')
.props()
.onClick();
await waitForComponentToPaint(wrapper);
wrapper
.find('[data-test="duplicate-modal-input"]')
.at(0)
.props()
.onPressEnter();
});
expect(fetchMock.calls(/dataset\/duplicate/)).toHaveLength(1);
});
});

jest.mock('react-router-dom', () => ({
Expand Down
70 changes: 3 additions & 67 deletions superset-frontend/src/views/CRUD/data/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
PASSWORDS_NEEDED_MESSAGE,
CONFIRM_OVERWRITE_MESSAGE,
} from './constants';
import DuplicateDatasetModal from './DuplicateDatasetModal';

const FlexRowContainer = styled.div`
align-items: center;
Expand Down Expand Up @@ -120,11 +119,6 @@ type Dataset = {
table_name: string;
};

interface VirtualDataset extends Dataset {
extra: Record<string, any>;
sql: string;
}

interface DatasetListProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
Expand Down Expand Up @@ -163,9 +157,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
const [datasetCurrentlyEditing, setDatasetCurrentlyEditing] =
useState<Dataset | null>(null);

const [datasetCurrentlyDuplicating, setDatasetCurrentlyDuplicating] =
useState<VirtualDataset | null>(null);

const [importingDataset, showImportModal] = useState<boolean>(false);
const [passwordFields, setPasswordFields] = useState<string[]>([]);
const [preparingExport, setPreparingExport] = useState<boolean>(false);
Expand All @@ -187,7 +178,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
const canEdit = hasPerm('can_write');
const canDelete = hasPerm('can_write');
const canCreate = hasPerm('can_write');
const canDuplicate = hasPerm('can_duplicate');
const canExport =
hasPerm('can_export') && isFeatureEnabled(FeatureFlag.VERSIONED_EXPORT);

Expand Down Expand Up @@ -251,10 +241,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
),
);

const openDatasetDuplicateModal = (dataset: VirtualDataset) => {
setDatasetCurrentlyDuplicating(dataset);
};

const handleBulkDatasetExport = (datasetsToExport: Dataset[]) => {
const ids = datasetsToExport.map(({ id }) => id);
handleResourceExport('dataset', ids, () => {
Expand Down Expand Up @@ -411,8 +397,7 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
const handleEdit = () => openDatasetEditModal(original);
const handleDelete = () => openDatasetDeleteModal(original);
const handleExport = () => handleBulkDatasetExport([original]);
const handleDuplicate = () => openDatasetDuplicateModal(original);
if (!canEdit && !canDelete && !canExport && !canDuplicate) {
if (!canEdit && !canDelete && !canExport) {
return null;
}
return (
Expand Down Expand Up @@ -471,32 +456,16 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
</span>
</Tooltip>
)}
{canDuplicate && original.kind === 'virtual' && (
<Tooltip
id="duplicate-action-tooltop"
title={t('Duplicate')}
placement="bottom"
>
<span
role="button"
tabIndex={0}
className="action-button"
onClick={handleDuplicate}
>
<Icons.Copy />
</span>
</Tooltip>
)}
</Actions>
);
},
Header: t('Actions'),
id: 'actions',
hidden: !canEdit && !canDelete && !canDuplicate,
hidden: !canEdit && !canDelete,
disableSortBy: true,
},
],
[canEdit, canDelete, canExport, openDatasetEditModal, canDuplicate],
[canEdit, canDelete, canExport, openDatasetEditModal],
);

const filterTypes: Filters = useMemo(
Expand Down Expand Up @@ -656,10 +625,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
setDatasetCurrentlyEditing(null);
};

const closeDatasetDuplicateModal = () => {
setDatasetCurrentlyDuplicating(null);
};

const handleDatasetDelete = ({ id, table_name: tableName }: Dataset) => {
SupersetClient.delete({
endpoint: `/api/v1/dataset/${id}`,
Expand Down Expand Up @@ -695,30 +660,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
);
};

const handleDatasetDuplicate = (newDatasetName: string) => {
if (datasetCurrentlyDuplicating === null) {
addDangerToast(t('There was an issue duplicating the dataset.'));
}

SupersetClient.post({
endpoint: `/api/v1/dataset/duplicate`,
postPayload: {
base_model_id: datasetCurrentlyDuplicating?.id,
table_name: newDatasetName,
},
}).then(
() => {
setDatasetCurrentlyDuplicating(null);
refreshData();
},
createErrorHandler(errMsg =>
addDangerToast(
t('There was an issue duplicating the selected datasets: %s', errMsg),
),
),
);
};

return (
<>
<SubMenu {...menuData} />
Expand Down Expand Up @@ -753,11 +694,6 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
show
/>
)}
<DuplicateDatasetModal
dataset={datasetCurrentlyDuplicating}
onHide={closeDatasetDuplicateModal}
onDuplicate={handleDatasetDuplicate}
/>
<ConfirmStatusChange
title={t('Please confirm')}
description={t(
Expand Down

This file was deleted.

Loading

0 comments on commit d2d39fc

Please sign in to comment.