You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ly...@apache.org on 2023/01/19 16:36:02 UTC
[superset] 08/21: Delete AddDatasetModal
This is an automated email from the ASF dual-hosted git repository.
lyndsi pushed a commit to branch lyndsi/enable-dataset-creation
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 3e4568680558b5146e5f48b1bf1b9a7c36cf24a9
Author: lyndsiWilliams <kc...@gmail.com>
AuthorDate: Thu Jan 5 16:06:09 2023 -0600
Delete AddDatasetModal
---
.../views/CRUD/data/dataset/AddDatasetModal.tsx | 172 ---------------------
.../src/views/components/RightMenu.test.tsx | 3 -
2 files changed, 175 deletions(-)
diff --git a/superset-frontend/src/views/CRUD/data/dataset/AddDatasetModal.tsx b/superset-frontend/src/views/CRUD/data/dataset/AddDatasetModal.tsx
deleted file mode 100644
index d4b1470f38..0000000000
--- a/superset-frontend/src/views/CRUD/data/dataset/AddDatasetModal.tsx
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * 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, { FunctionComponent, useState, useEffect } from 'react';
-import { styled, t } from '@superset-ui/core';
-import { useSingleViewResource } from 'src/views/CRUD/hooks';
-import Modal from 'src/components/Modal';
-import TableSelector from 'src/components/TableSelector';
-import withToasts from 'src/components/MessageToasts/withToasts';
-import { DatabaseObject } from 'src/components/DatabaseSelector';
-import {
- getItem,
- LocalStorageKeys,
- setItem,
-} from 'src/utils/localStorageHelpers';
-import { isEmpty } from 'lodash';
-
-type DatasetAddObject = {
- id: number;
- database: number;
- schema: string;
- table_name: string;
-};
-interface DatasetModalProps {
- addDangerToast: (msg: string) => void;
- addSuccessToast: (msg: string) => void;
- onDatasetAdd?: (dataset: DatasetAddObject) => void;
- onHide: () => void;
- show: boolean;
- history?: any; // So we can render the modal when not using SPA
-}
-
-const TableSelectorContainer = styled.div`
- padding-bottom: 340px;
- width: 65%;
-`;
-
-const DatasetModal: FunctionComponent<DatasetModalProps> = ({
- addDangerToast,
- onDatasetAdd,
- onHide,
- show,
- history,
-}) => {
- const [currentDatabase, setCurrentDatabase] = useState<
- DatabaseObject | undefined
- >();
- const [currentSchema, setSchema] = useState<string | undefined>('');
- const [currentTableName, setTableName] = useState('');
- const [disableSave, setDisableSave] = useState(true);
- const {
- createResource,
- state: { loading },
- } = useSingleViewResource<Partial<DatasetAddObject>>(
- 'dataset',
- t('dataset'),
- addDangerToast,
- );
-
- useEffect(() => {
- setDisableSave(currentDatabase === undefined || currentTableName === '');
- }, [currentTableName, currentDatabase]);
-
- useEffect(() => {
- const currentUserSelectedDb = getItem(
- LocalStorageKeys.db,
- null,
- ) as DatabaseObject;
- if (currentUserSelectedDb) setCurrentDatabase(currentUserSelectedDb);
- }, []);
-
- const onDbChange = (db: DatabaseObject) => {
- setCurrentDatabase(db);
- };
-
- const onSchemaChange = (schema?: string) => {
- setSchema(schema);
- };
-
- const onTableChange = (tableName: string) => {
- setTableName(tableName);
- };
-
- const clearModal = () => {
- setSchema('');
- setTableName('');
- setCurrentDatabase(undefined);
- setDisableSave(true);
- };
-
- const cleanup = () => {
- clearModal();
- setItem(LocalStorageKeys.db, null);
- };
-
- const hide = () => {
- cleanup();
- onHide();
- };
-
- const onSave = () => {
- if (currentDatabase === undefined) {
- return;
- }
- const data = {
- database: currentDatabase.id,
- ...(currentSchema ? { schema: currentSchema } : {}),
- table_name: currentTableName,
- };
- createResource(data).then(response => {
- if (!response) {
- return;
- }
- if (onDatasetAdd) {
- onDatasetAdd({ id: response.id, ...response });
- }
- // We need to be able to work with no SPA routes opening the modal
- // So useHistory wont be available always thus we check for it
- if (!isEmpty(history)) {
- history?.push(`/chart/add?dataset=${currentTableName}`);
- cleanup();
- } else {
- window.location.href = `/chart/add?dataset=${currentTableName}`;
- cleanup();
- onHide();
- }
- });
- };
-
- return (
- <Modal
- disablePrimaryButton={disableSave}
- primaryButtonLoading={loading}
- onHandledPrimaryAction={onSave}
- onHide={hide}
- primaryButtonName={t('Add Dataset and Create Chart')}
- show={show}
- title={t('Add dataset')}
- >
- <TableSelectorContainer>
- <TableSelector
- clearable={false}
- formMode
- database={currentDatabase}
- schema={currentSchema}
- tableValue={currentTableName}
- onDbChange={onDbChange}
- onSchemaChange={onSchemaChange}
- onTableSelectChange={onTableChange}
- handleError={addDangerToast}
- />
- </TableSelectorContainer>
- </Modal>
- );
-};
-
-export default withToasts(DatasetModal);
diff --git a/superset-frontend/src/views/components/RightMenu.test.tsx b/superset-frontend/src/views/components/RightMenu.test.tsx
index ec12e644db..907c305ff6 100644
--- a/superset-frontend/src/views/components/RightMenu.test.tsx
+++ b/superset-frontend/src/views/components/RightMenu.test.tsx
@@ -30,9 +30,6 @@ jest.mock('react-redux', () => ({
}));
jest.mock('src/views/CRUD/data/database/DatabaseModal', () => () => <span />);
-jest.mock('src/views/CRUD/data/dataset/AddDatasetModal.tsx', () => () => (
- <span />
-));
const dropdownItems = [
{