From fa40115bb69a64416b30459473be3ebd7e0f9dba Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 18 Nov 2021 21:39:30 -0600 Subject: consolidate option edit and view --- src/web/src/components/System/Options/Edit.js | 8 +++----- src/web/src/components/System/Options/View.js | 12 +++++++++--- src/web/src/components/System/Options/index.js | 16 ++++++++++++++++ src/web/src/components/System/System.js | 6 ++---- 4 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/web/src/components/System/Options/index.js (limited to 'src') diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js index 78ad3c80..6623e034 100644 --- a/src/web/src/components/System/Options/Edit.js +++ b/src/web/src/components/System/Options/Edit.js @@ -6,7 +6,7 @@ import CodeEditor from '@uiw/react-textarea-code-editor'; import { getYaml, validateYaml, updateYaml } from '../../../lib/options'; import PlaceholderSegment from '../../Shared/PlaceholderSegment'; -const Edit = ({ options }) => { +const Edit = ({ cancelAction }) => { const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); const [{ yaml, isDirty }, setYaml] = useState({ yaml: undefined, isDirty: false }); const [yamlError, setYamlError] = useState(); @@ -42,12 +42,10 @@ const Edit = ({ options }) => { if (!yamlError) { await updateYaml({ yaml }); - await get(); + cancelAction(); } } - const cancel = () => get(); - if (loading) { return } @@ -60,7 +58,7 @@ const Edit = ({ options }) => { <>
- {isDirty && } +
{yamlError && {yamlError}} { + const { remoteConfiguration } = options; -const View = ({ options }) => { return ( -
+ <> + {remoteConfiguration &&
+ +
}
{JSON.stringify(options, null, 2)}
-
+ ); } diff --git a/src/web/src/components/System/Options/index.js b/src/web/src/components/System/Options/index.js new file mode 100644 index 00000000..9e92b423 --- /dev/null +++ b/src/web/src/components/System/Options/index.js @@ -0,0 +1,16 @@ +import React, { useState } from 'react'; + +import Edit from './Edit'; +import View from './View'; + +const Index = ({ options }) => { + const [mode, setMode] = useState('view'); + + if (mode === 'edit') { + return setMode('view')}/> + } + + return setMode('edit')}/> +} + +export default Index; \ No newline at end of file diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 037e6ea3..bbba292d 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -3,8 +3,7 @@ import { Segment, Tab } from 'semantic-ui-react'; import './System.css'; import Info from './Info'; import Logs from './Logs'; -import OptionsView from './Options/View'; -import OptionsEdit from './Options/Edit'; +import Options from './Options'; class System extends Component { componentDidMount = () => { @@ -20,8 +19,7 @@ class System extends Component { }, - { menuItem: 'Options', render: () => }, - { menuItem: 'Edit', render: () => }, + { menuItem: 'Options', render: () => }, { menuItem: 'Logs', render: () => }, ]}/> -- cgit v1.2.3