From 22f6374f119d9fbaa3699bac3d85d5aa6d529bee Mon Sep 17 00:00:00 2001 From: Victor Malai Date: Wed, 9 Dec 2020 10:04:52 +0200 Subject: [PATCH 1/4] Transform code modal to tsx --- .../{CodeModal.jsx => CodeModal.tsx} | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) rename superset-frontend/src/dashboard/components/{CodeModal.jsx => CodeModal.tsx} (77%) diff --git a/superset-frontend/src/dashboard/components/CodeModal.jsx b/superset-frontend/src/dashboard/components/CodeModal.tsx similarity index 77% rename from superset-frontend/src/dashboard/components/CodeModal.jsx rename to superset-frontend/src/dashboard/components/CodeModal.tsx index 0fab40b77de49..efbbb2ca9f2a5 100644 --- a/superset-frontend/src/dashboard/components/CodeModal.jsx +++ b/superset-frontend/src/dashboard/components/CodeModal.tsx @@ -17,24 +17,30 @@ * under the License. */ import React from 'react'; -import PropTypes from 'prop-types'; import { t } from '@superset-ui/core'; -import ModalTrigger from '../../components/ModalTrigger'; +import ModalTrigger from 'src/components/ModalTrigger'; -const propTypes = { - triggerNode: PropTypes.node.isRequired, - code: PropTypes.string, - codeCallback: PropTypes.func, +type CodeModalProps = { + triggerNode: JSX.Element; + code?: string; + codeCallback: () => string; }; -const defaultProps = { - codeCallback: () => {}, - code: '', +type CodeModalState = { + code?: string; }; -export default class CodeModal extends React.PureComponent { - constructor(props) { +export default class CodeModal extends React.PureComponent< + CodeModalProps, + CodeModalState +> { + static defaultProps = { + codeCallback: () => {}, + code: '', + }; + + constructor(props: CodeModalProps) { super(props); this.state = { code: props.code }; this.beforeOpen = this.beforeOpen.bind(this); @@ -64,5 +70,3 @@ export default class CodeModal extends React.PureComponent { ); } } -CodeModal.propTypes = propTypes; -CodeModal.defaultProps = defaultProps; From 051c1737c3c09198a9d0ccf302e06759ce3a8254 Mon Sep 17 00:00:00 2001 From: maloun96 Date: Wed, 16 Dec 2020 11:36:01 +0200 Subject: [PATCH 2/4] Fix --- superset-frontend/src/dashboard/components/CodeModal.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/CodeModal.tsx b/superset-frontend/src/dashboard/components/CodeModal.tsx index efbbb2ca9f2a5..713a980988a26 100644 --- a/superset-frontend/src/dashboard/components/CodeModal.tsx +++ b/superset-frontend/src/dashboard/components/CodeModal.tsx @@ -23,8 +23,8 @@ import ModalTrigger from 'src/components/ModalTrigger'; type CodeModalProps = { triggerNode: JSX.Element; - code?: string; - codeCallback: () => string; + code: string; + codeCallback: () => void; }; type CodeModalState = { From 52dad80688617451ce19114efb79977f6533b82e Mon Sep 17 00:00:00 2001 From: maloun96 Date: Wed, 16 Dec 2020 11:38:28 +0200 Subject: [PATCH 3/4] Fix --- superset-frontend/src/dashboard/components/CodeModal.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/CodeModal.tsx b/superset-frontend/src/dashboard/components/CodeModal.tsx index 713a980988a26..3edfd01bfedfa 100644 --- a/superset-frontend/src/dashboard/components/CodeModal.tsx +++ b/superset-frontend/src/dashboard/components/CodeModal.tsx @@ -24,7 +24,7 @@ import ModalTrigger from 'src/components/ModalTrigger'; type CodeModalProps = { triggerNode: JSX.Element; code: string; - codeCallback: () => void; + codeCallback?: () => string; }; type CodeModalState = { @@ -36,7 +36,6 @@ export default class CodeModal extends React.PureComponent< CodeModalState > { static defaultProps = { - codeCallback: () => {}, code: '', }; From 7acf19dc4b622110e042ac2a5a2895b59c22854e Mon Sep 17 00:00:00 2001 From: maloun96 Date: Wed, 16 Dec 2020 18:21:11 +0200 Subject: [PATCH 4/4] Remove unused modal --- .../dashboard/components/CodeModal_spec.jsx | 39 ---------- .../src/dashboard/components/CodeModal.tsx | 71 ------------------- 2 files changed, 110 deletions(-) delete mode 100644 superset-frontend/spec/javascripts/dashboard/components/CodeModal_spec.jsx delete mode 100644 superset-frontend/src/dashboard/components/CodeModal.tsx diff --git a/superset-frontend/spec/javascripts/dashboard/components/CodeModal_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/CodeModal_spec.jsx deleted file mode 100644 index 52239a60dece7..0000000000000 --- a/superset-frontend/spec/javascripts/dashboard/components/CodeModal_spec.jsx +++ /dev/null @@ -1,39 +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 from 'react'; -import { mount } from 'enzyme'; -import { supersetTheme, ThemeProvider } from '@superset-ui/core'; - -import CodeModal from 'src/dashboard/components/CodeModal'; - -describe('CodeModal', () => { - const mockedProps = { - triggerNode: , - }; - it('is valid', () => { - expect(React.isValidElement()).toBe(true); - }); - it('renders the trigger node', () => { - const wrapper = mount(, { - wrappingComponent: ThemeProvider, - wrappingComponentProps: { theme: supersetTheme }, - }); - expect(wrapper.find('.fa-edit')).toExist(); - }); -}); diff --git a/superset-frontend/src/dashboard/components/CodeModal.tsx b/superset-frontend/src/dashboard/components/CodeModal.tsx deleted file mode 100644 index 3edfd01bfedfa..0000000000000 --- a/superset-frontend/src/dashboard/components/CodeModal.tsx +++ /dev/null @@ -1,71 +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 from 'react'; -import { t } from '@superset-ui/core'; - -import ModalTrigger from 'src/components/ModalTrigger'; - -type CodeModalProps = { - triggerNode: JSX.Element; - code: string; - codeCallback?: () => string; -}; - -type CodeModalState = { - code?: string; -}; - -export default class CodeModal extends React.PureComponent< - CodeModalProps, - CodeModalState -> { - static defaultProps = { - code: '', - }; - - constructor(props: CodeModalProps) { - super(props); - this.state = { code: props.code }; - this.beforeOpen = this.beforeOpen.bind(this); - } - - beforeOpen() { - let { code } = this.props; - if (!code && this.props.codeCallback) { - code = this.props.codeCallback(); - } - this.setState({ code }); - } - - render() { - return ( - -
{this.state.code}
- - } - /> - ); - } -}