From 35b057d4a8ccddbbe5d4385f8829fef78c76e233 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 12:10:21 -0600 Subject: simplify yaml parsing, fix null display --- src/web/src/components/System/Options/View.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js index 61651f8d..c3a62214 100644 --- a/src/web/src/components/System/Options/View.js +++ b/src/web/src/components/System/Options/View.js @@ -1,5 +1,5 @@ import React from 'react'; -import yaml from 'yaml'; +import YAML from 'yaml'; import { Icon, Button } from 'semantic-ui-react'; import CodeEditor from './CodeEditor'; @@ -7,10 +7,7 @@ import CodeEditor from './CodeEditor'; const View = ({ options, editAction }) => { const { remoteConfiguration } = options; - const doc = new yaml.Document(); - doc.contents = options; - - const optionsAsYaml = doc.toString(); + const optionsAsYaml = YAML.stringify(options, { simpleKeys: true }) return ( <> -- cgit v1.2.3 From 3b467854506556248350aaecba319cca35a7ab92 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 13:35:50 -0600 Subject: add an endpoint to retreive the location of the yaml file --- src/slskd/Core/API/Controllers/OptionsController.cs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index b4626cb9..60237878 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -73,6 +73,14 @@ namespace slskd.Core.API return Ok(OptionsAtStartup); } + [HttpGet] + [Authorize] + [Route("yaml/location")] + public IActionResult GetYamlFileLocation() + { + return Ok(Program.ConfigurationFile); + } + [HttpGet] [Authorize] [Route("yaml")] -- cgit v1.2.3 From 4a4314cb0fefc9bfbded5cfa3d628aab51cbadbf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 13:36:02 -0600 Subject: move CodeEditor to shared --- src/web/src/components/Shared/CodeEditor.js | 19 +++++++++++++++++++ src/web/src/components/System/Options/CodeEditor.js | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 src/web/src/components/Shared/CodeEditor.js delete mode 100644 src/web/src/components/System/Options/CodeEditor.js (limited to 'src') diff --git a/src/web/src/components/Shared/CodeEditor.js b/src/web/src/components/Shared/CodeEditor.js new file mode 100644 index 00000000..77867a12 --- /dev/null +++ b/src/web/src/components/Shared/CodeEditor.js @@ -0,0 +1,19 @@ +import React from 'react'; + +import CodeMirror from '@uiw/react-codemirror'; +import { StreamLanguage } from '@codemirror/stream-parser'; +import { yaml } from '@codemirror/legacy-modes/mode/yaml'; +import { defaultHighlightStyle } from '@codemirror/highlight'; + +const CodeEditor = ({ value, onChange = () => {}, ...rest}) => { + return ( + onChange(value)} + { ...rest} + /> + ); +} + +export default CodeEditor; \ No newline at end of file diff --git a/src/web/src/components/System/Options/CodeEditor.js b/src/web/src/components/System/Options/CodeEditor.js deleted file mode 100644 index 77867a12..00000000 --- a/src/web/src/components/System/Options/CodeEditor.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; - -import CodeMirror from '@uiw/react-codemirror'; -import { StreamLanguage } from '@codemirror/stream-parser'; -import { yaml } from '@codemirror/legacy-modes/mode/yaml'; -import { defaultHighlightStyle } from '@codemirror/highlight'; - -const CodeEditor = ({ value, onChange = () => {}, ...rest}) => { - return ( - onChange(value)} - { ...rest} - /> - ); -} - -export default CodeEditor; \ No newline at end of file -- cgit v1.2.3 From 415c5e37fe5edbe47293f216dac7ec91726faabb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 13:36:44 -0600 Subject: add function to get yaml location --- src/web/src/lib/options.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/web/src/lib/options.js b/src/web/src/lib/options.js index e299996d..da198bd8 100644 --- a/src/web/src/lib/options.js +++ b/src/web/src/lib/options.js @@ -8,6 +8,10 @@ export const getYaml = async () => { return (await api.get('/options/yaml')).data; }; +export const getYamlLocation = async () => { + return (await api.get('/options/yaml/location')).data; +} + export const validateYaml = async ({ yaml }) => { return (await api.post('/options/yaml/validate', yaml)).data; }; -- cgit v1.2.3 From 10e6ca2e889e59ab4d0d93856f15468eeacd3634 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 13:37:18 -0600 Subject: add message indicating editing of yaml file, sort yaml --- src/web/src/components/System/Options/Edit.js | 24 ++++++++++++++---------- src/web/src/components/System/Options/View.js | 6 +++--- src/web/src/components/System/System.css | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js index 0092279a..67739c98 100644 --- a/src/web/src/components/System/Options/Edit.js +++ b/src/web/src/components/System/Options/Edit.js @@ -1,14 +1,14 @@ import React, { useState, useEffect } from 'react'; import { Button, Icon, Message } from 'semantic-ui-react'; -import CodeEditor from './CodeEditor'; +import CodeEditor from '../../Shared/CodeEditor'; -import { getYaml, validateYaml, updateYaml } from '../../../lib/options'; +import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options'; import PlaceholderSegment from '../../Shared/PlaceholderSegment'; -const Edit = ({ cancelAction }) => { +const Edit = ({ filename, cancelAction }) => { const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); - const [{ yaml, isDirty }, setYaml] = useState({ yaml: undefined, isDirty: false }); + const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); const [yamlError, setYamlError] = useState(); useEffect(() => { @@ -19,8 +19,9 @@ const Edit = ({ cancelAction }) => { setLoading({ loading: true, error: false }); try { - const yaml = await getYaml(); - setYaml({ yaml: yaml, isDirty: false }) + const [location, yaml] = await Promise.all([getYamlLocation(), getYaml()]); + + setYaml({ location, yaml, isDirty: false }) setLoading({ loading: false, error: false }) } catch (error) { setLoading({ loading: false, error: error.message }) @@ -28,7 +29,7 @@ const Edit = ({ cancelAction }) => { } const update = async (yaml) => { - setYaml({ yaml, isDirty: true }); + setYaml({ location, yaml, isDirty: true }); validate(yaml); } @@ -56,16 +57,19 @@ const Edit = ({ cancelAction }) => { return ( <> + + Editing {location} +
update(value)} />
- {yamlError && {yamlError}} + {yamlError && {yamlError}}
diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js index c3a62214..83b24a88 100644 --- a/src/web/src/components/System/Options/View.js +++ b/src/web/src/components/System/Options/View.js @@ -2,16 +2,16 @@ import React from 'react'; import YAML from 'yaml'; import { Icon, Button } from 'semantic-ui-react'; -import CodeEditor from './CodeEditor'; +import CodeEditor from '../../Shared/CodeEditor'; const View = ({ options, editAction }) => { const { remoteConfiguration } = options; - const optionsAsYaml = YAML.stringify(options, { simpleKeys: true }) + const optionsAsYaml = YAML.stringify(options, { simpleKeys: true, sortMapEntries: true }) return ( <> -
+
Date: Sat, 27 Nov 2021 13:37:31 -0600 Subject: remove unused lifecycle functions --- src/web/src/components/System/System.js | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js index 08253c7a..8b0ea4d4 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -6,13 +6,6 @@ import Logs from './Logs'; import Options from './Options'; class System extends Component { - componentDidMount = () => { - } - - componentWillUnmount = () => { - - } - render = () => { return (
-- cgit v1.2.3 From de76cbf2b466362cf03fda3b2c52b74d4d96dd10 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 27 Nov 2021 13:40:55 -0600 Subject: display state as yaml --- src/web/src/components/System/Info.js | 27 +++++++++++++++++---------- src/web/src/components/System/System.css | 6 +++++- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info.js index ee132aec..8d7db123 100644 --- a/src/web/src/components/System/Info.js +++ b/src/web/src/components/System/Info.js @@ -1,13 +1,20 @@ -import React, { Component } from 'react'; - -class Info extends Component { - render = () => { - return ( -
-
{JSON.stringify(this.props.state, null, 2)}
-
- ); - } +import React from 'react'; +import YAML from 'yaml'; + +import CodeEditor from '../Shared/CodeEditor'; + +const Info = ({ state }) => { + const stateAsYaml = YAML.stringify(state, { simpleKeys: true, sortMapEntries: true }) + + return ( +
+ +
+ ); } export default Info; \ No newline at end of file diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css index 3d1594b7..1e9c4a5d 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -38,11 +38,15 @@ text-align: right; } -.view-code-container, .edit-code-container, .edit-code-container-error { +.state-code-editor, .view-code-container, .edit-code-container, .edit-code-container-error { border: 1px solid #d4d4d5; overflow: auto; } +.state-code-container { + height: calc(100vh - 204px); +} + .view-code-container { height: calc(100vh - 254px); } -- cgit v1.2.3