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/web') 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 ( <> -
+