aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-11-18 19:56:08 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-11-18 19:56:08 -0600
commitef2c6f879824cb12a0bea61dcc853257f03032d6 (patch)
tree657a6693b685ddcf0ed64f67e7170bb165b73bec /src
parent7f7217d12b800ab9979ffa202d67994e82c0e08d (diff)
downloadslskd-ef2c6f879824cb12a0bea61dcc853257f03032d6.tar.gz
rough in edit controls
Diffstat (limited to 'src')
-rw-r--r--src/web/src/components/System/Options.js13
-rw-r--r--src/web/src/components/System/Options/Edit.js82
-rw-r--r--src/web/src/components/System/Options/View.js11
-rw-r--r--src/web/src/components/System/System.js6
4 files changed, 97 insertions, 15 deletions
diff --git a/src/web/src/components/System/Options.js b/src/web/src/components/System/Options.js
deleted file mode 100644
index e822b11d..00000000
--- a/src/web/src/components/System/Options.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import React, { Component } from 'react';
-
-class Options extends Component {
- render = () => {
- return (
- <div>
- <pre>{JSON.stringify(this.props.options, null, 2)}</pre>
- </div>
- );
- }
-}
-
-export default Options; \ No newline at end of file
diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js
new file mode 100644
index 00000000..78ad3c80
--- /dev/null
+++ b/src/web/src/components/System/Options/Edit.js
@@ -0,0 +1,82 @@
+import React, { useState, useEffect } from 'react';
+
+import { Button, Icon, Message } from 'semantic-ui-react';
+import CodeEditor from '@uiw/react-textarea-code-editor';
+
+import { getYaml, validateYaml, updateYaml } from '../../../lib/options';
+import PlaceholderSegment from '../../Shared/PlaceholderSegment';
+
+const Edit = ({ options }) => {
+ const [{ loading, error }, setLoading] = useState({ loading: true, error: false });
+ const [{ yaml, isDirty }, setYaml] = useState({ yaml: undefined, isDirty: false });
+ const [yamlError, setYamlError] = useState();
+
+ useEffect(() => {
+ get();
+ }, [])
+
+ const get = async () => {
+ setLoading({ loading: true, error: false });
+
+ try {
+ const yaml = await getYaml();
+ setYaml({ yaml: yaml, isDirty: false })
+ setLoading({ loading: false, error: false })
+ } catch (error) {
+ setLoading({ loading: false, error: error.message })
+ }
+ }
+
+ const update = async (yaml) => {
+ setYaml({ yaml, isDirty: true });
+ validate(yaml);
+ }
+
+ const validate = async (yaml) => {
+ const response = await validateYaml({ yaml });
+ setYamlError(response);
+ }
+
+ const save = async (yaml) => {
+ await validate(yaml);
+
+ if (!yamlError) {
+ await updateYaml({ yaml });
+ await get();
+ }
+ }
+
+ const cancel = () => get();
+
+ if (loading) {
+ return <PlaceholderSegment loading={true}/>
+ }
+
+ if (error) {
+ return <PlaceholderSegment icon='close'/>
+ }
+
+ return (
+ <>
+ <div style={{textAlign: 'right'}}>
+ <Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button>
+ {isDirty && <Button onClick={cancel}><Icon name='close'/>Cancel</Button>}
+ </div>
+ {yamlError && <Message icon='x' negative>{yamlError}</Message>}
+ <CodeEditor
+ value={yaml}
+ language='yaml'
+ onChange={(e) => update(e.target.value)}
+ padding={10}
+ style={{
+ marginTop: 14,
+ border: '1px solid #d4d4d5',
+ backgroundColor: '#f5f5f5',
+ fontFamily: 'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace',
+ }}
+ />
+ </>
+ );
+}
+
+export default Edit; \ No newline at end of file
diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js
new file mode 100644
index 00000000..ba7cf426
--- /dev/null
+++ b/src/web/src/components/System/Options/View.js
@@ -0,0 +1,11 @@
+import React from 'react';
+
+const View = ({ options }) => {
+ return (
+ <div>
+ <pre>{JSON.stringify(options, null, 2)}</pre>
+ </div>
+ );
+}
+
+export default View; \ 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 bbba292d..037e6ea3 100644
--- a/src/web/src/components/System/System.js
+++ b/src/web/src/components/System/System.js
@@ -3,7 +3,8 @@ import { Segment, Tab } from 'semantic-ui-react';
import './System.css';
import Info from './Info';
import Logs from './Logs';
-import Options from './Options';
+import OptionsView from './Options/View';
+import OptionsEdit from './Options/Edit';
class System extends Component {
componentDidMount = () => {
@@ -19,7 +20,8 @@ class System extends Component {
<Segment raised>
<Tab panes={[
{ menuItem: 'Info', render: () => <Tab.Pane><Info state={this.props.state}/></Tab.Pane> },
- { menuItem: 'Options', render: () => <Tab.Pane><Options options={this.props.options}/></Tab.Pane> },
+ { menuItem: 'Options', render: () => <Tab.Pane><OptionsView options={this.props.options}/></Tab.Pane> },
+ { menuItem: 'Edit', render: () => <Tab.Pane><OptionsEdit/></Tab.Pane> },
{ menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> },
]}/>
</Segment>