forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Virtual dataset duplication (apache#20309)
* Inital duplicate functionality * Fix formatting * Create dedicated duplicate API * Make use of new API * Make use of new api permissions * Add integration tests for duplicating datasets * Add licenses * Fix linting errors * Change confirm button to 'Duplicate' * Fix HTTP status code and response * Add missing import * Use user id instead of user object * Remove stray debug print * Fix sqlite tests * Specify type of extra * Add frontend tests * Add match statement to test
- Loading branch information
1 parent
f09c432
commit 16032ed
Showing
9 changed files
with
1,567 additions
and
217 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
80 changes: 80 additions & 0 deletions
80
superset-frontend/src/views/CRUD/data/dataset/DuplicateDatasetModal.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,80 @@ | ||
/** | ||
* 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 { t } from '@superset-ui/core'; | ||
import React, { FunctionComponent, useEffect, useState } from 'react'; | ||
import { FormLabel } from 'src/components/Form'; | ||
import { Input } from 'src/components/Input'; | ||
import Modal from 'src/components/Modal'; | ||
import Dataset from 'src/types/Dataset'; | ||
|
||
interface DuplicateDatasetModalProps { | ||
dataset: Dataset | null; | ||
onHide: () => void; | ||
onDuplicate: (newDatasetName: string) => void; | ||
} | ||
|
||
const DuplicateDatasetModal: FunctionComponent<DuplicateDatasetModalProps> = ({ | ||
dataset, | ||
onHide, | ||
onDuplicate, | ||
}) => { | ||
const [show, setShow] = useState<boolean>(false); | ||
const [disableSave, setDisableSave] = useState<boolean>(false); | ||
const [newDuplicateDatasetName, setNewDuplicateDatasetName] = | ||
useState<string>(''); | ||
|
||
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const targetValue = event.target.value ?? ''; | ||
setNewDuplicateDatasetName(targetValue); | ||
setDisableSave(targetValue === ''); | ||
}; | ||
|
||
const duplicateDataset = () => { | ||
onDuplicate(newDuplicateDatasetName); | ||
}; | ||
|
||
useEffect(() => { | ||
setNewDuplicateDatasetName(''); | ||
setShow(dataset !== null); | ||
}, [dataset]); | ||
|
||
return ( | ||
<Modal | ||
show={show} | ||
onHide={onHide} | ||
title={t('Duplicate dataset')} | ||
disablePrimaryButton={disableSave} | ||
onHandledPrimaryAction={duplicateDataset} | ||
primaryButtonName={t('Duplicate')} | ||
> | ||
<FormLabel htmlFor="duplicate">{t('New dataset name')}</FormLabel> | ||
<Input | ||
data-test="duplicate-modal-input" | ||
type="text" | ||
id="duplicate" | ||
autoComplete="off" | ||
value={newDuplicateDatasetName} | ||
onChange={onChange} | ||
onPressEnter={duplicateDataset} | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default DuplicateDatasetModal; |
Oops, something went wrong.