From 59623e20ac93565bf377457f70cff87fc4b6e459 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 26 May 2022 16:52:36 -0500 Subject: refactor System components --- src/web/src/components/System/Info.js | 70 -------------- src/web/src/components/System/Info/index.js | 74 +++++++++++++++ src/web/src/components/System/Logs.js | 83 ----------------- .../src/components/System/Options/DebugModal.js | 67 ++++++++++++++ src/web/src/components/System/Options/Edit.js | 87 ------------------ src/web/src/components/System/Options/EditModal.js | 101 +++++++++++++++++++++ src/web/src/components/System/Options/View.js | 30 ------ src/web/src/components/System/Options/index.js | 74 +++++++++++++-- src/web/src/components/System/System.css | 36 +++----- src/web/src/components/System/System.js | 37 +++++++- 10 files changed, 355 insertions(+), 304 deletions(-) delete mode 100644 src/web/src/components/System/Info.js create mode 100644 src/web/src/components/System/Info/index.js delete mode 100644 src/web/src/components/System/Logs.js create mode 100644 src/web/src/components/System/Options/DebugModal.js delete mode 100644 src/web/src/components/System/Options/Edit.js create mode 100644 src/web/src/components/System/Options/EditModal.js delete mode 100644 src/web/src/components/System/Options/View.js (limited to 'src') diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info.js deleted file mode 100644 index d9ce8813..00000000 --- a/src/web/src/components/System/Info.js +++ /dev/null @@ -1,70 +0,0 @@ -import React from 'react'; -import YAML from 'yaml'; - -import { restart, shutdown, getVersion } from '../../lib/application'; - -import { Modal, Header } from 'semantic-ui-react'; -import CodeEditor from '../Shared/CodeEditor'; -import ShrinkableButton from '../Shared/ShrinkableButton'; - -const Info = ({ state }) => { - const stateAsYaml = YAML.stringify(state, { simpleKeys: true, sortMapEntries: true }); - - return ( - <> -
- -
-
-
- getVersion({ forceCheck: true })} - > - Check for Updates - -
- - Shut Down - - } - centered - size='mini' - header={
} - content="Are you sure you want to shut the application down? You'll need to manually start it again." - actions={['Cancel', { key: 'done', content: 'Shut Down', negative: true, onClick: shutdown }]} - /> - - Restart - - } - centered - size='mini' - header={
} - content='Are you sure you want restart the application?' - actions={['Cancel', { key: 'done', content: 'Restart', negative: true, onClick: restart }]} - /> -
- - ); -}; - -export default Info; \ No newline at end of file diff --git a/src/web/src/components/System/Info/index.js b/src/web/src/components/System/Info/index.js new file mode 100644 index 00000000..f640716e --- /dev/null +++ b/src/web/src/components/System/Info/index.js @@ -0,0 +1,74 @@ +import React from 'react'; +import YAML from 'yaml'; + +import { restart, shutdown, getVersion } from '../../../lib/application'; + +import { Modal, Header, Divider } from 'semantic-ui-react'; + +import { + CodeEditor, + ShrinkableButton, +} from '../../Shared'; + +const Info = ({ state }) => { + const stateAsYaml = YAML.stringify(state, { simpleKeys: true, sortMapEntries: true }); + + return ( + <> +
+
+ getVersion({ forceCheck: true })} + > + Check for Updates + +
+ + Shut Down + + } + centered + size='mini' + header={
} + content="Are you sure you want to shut the application down? You'll need to manually start it again." + actions={['Cancel', { key: 'done', content: 'Shut Down', negative: true, onClick: shutdown }]} + /> + + Restart + + } + centered + size='mini' + header={
} + content='Are you sure you want restart the application?' + actions={['Cancel', { key: 'done', content: 'Restart', negative: true, onClick: restart }]} + /> +
+ +
+ +
+ + ); +}; + +export default Info; \ No newline at end of file diff --git a/src/web/src/components/System/Logs.js b/src/web/src/components/System/Logs.js deleted file mode 100644 index 4a118414..00000000 --- a/src/web/src/components/System/Logs.js +++ /dev/null @@ -1,83 +0,0 @@ -import React, { Component } from 'react'; -import { Table, Loader, Dimmer } from 'semantic-ui-react'; - -import { createLogsHubConnection } from '../../lib/hubFactory'; - -import './System.css'; - -const initialState = { - logs: [], - connected: false, -}; - -const levels = { - 'Debug': 'DBG', - 'Warning': 'WRN', - 'Error': 'ERR', - 'Information': 'INF', -}; - -const maxLogs = 500; - -class Logs extends Component { - state = initialState; - - componentDidMount = () => { - const logsHub = createLogsHubConnection(); - - logsHub.on('buffer', (buffer) => { - this.setState({ connected: true, logs: buffer.reverse().slice(0, maxLogs) }); - }); - - logsHub.on('log', (log) => { - this.setState({ connected: true, logs: [log].concat(this.state.logs).slice(0, maxLogs) }); - }); - - logsHub.onreconnecting(() => this.setState({ connected: false })); - logsHub.onclose(() => this.setState({ connected: false })); - logsHub.onreconnected(() => this.setState({ connected: true })); - - logsHub.start(); - }; - - formatTimestamp = (timestamp) => { - const date = new Date(timestamp); - return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`; // eslint-disable-line max-len - }; - - render = () => { - const { connected, logs } = this.state; - - return ( -
- {!connected && } - {connected && - - - - Timestamp - Level - Message - - - - {logs.map((log, index) => - - {this.formatTimestamp(log.timestamp)} - {levels[log.level] || log.level} - {log.message} - )} - -
- } -
- ); - }; -} - -export default Logs; \ No newline at end of file diff --git a/src/web/src/components/System/Options/DebugModal.js b/src/web/src/components/System/Options/DebugModal.js new file mode 100644 index 00000000..2f01eb16 --- /dev/null +++ b/src/web/src/components/System/Options/DebugModal.js @@ -0,0 +1,67 @@ +import React, { useState, useEffect } from 'react'; +import { toast } from 'react-toastify'; + +import { + Modal, + Button, + Icon, +} from 'semantic-ui-react'; + +import { getCurrentDebugView } from '../../../lib/options'; +import { CodeEditor, PlaceholderSegment, Switch } from '../../Shared'; + +const DebugModal = ({ open, onClose }) => { + const [loading, setLoading] = useState(true); + const [debugView, setDebugView] = useState(); + + useEffect(() => { + if (open) { + get(); + } + }, [open]); + + const get = async () => { + setLoading(true); + + try { + setDebugView(await getCurrentDebugView()); + } catch (error) { + console.error(error); + toast.error(error?.response?.data ?? error?.message ?? error); + } finally { + setLoading(false); + } + }; + + return ( + + + + Options (Debug View) + + + } + > +
+ +
+
+
+ + + +
); +}; + +export default DebugModal; \ 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 deleted file mode 100644 index f9657022..00000000 --- a/src/web/src/components/System/Options/Edit.js +++ /dev/null @@ -1,87 +0,0 @@ -import React, { useState, useEffect } from 'react'; - -import { Button, Icon, Message } from 'semantic-ui-react'; -import CodeEditor from '../../Shared/CodeEditor'; - -import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options'; -import PlaceholderSegment from '../../Shared/PlaceholderSegment'; - -const Edit = ({ cancelAction }) => { - const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); - const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); - const [yamlError, setYamlError] = useState(); - const [updateError, setUpdateError] = useState(); - - useEffect(() => { - get(); - }, []); - - const get = async () => { - setLoading({ loading: true, error: false }); - - try { - 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 }); - } - }; - - const update = async (yaml) => { - setYaml({ location, 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) { - try { - await updateYaml({ yaml }); - cancelAction(); - } - catch (error) { - setUpdateError(error.response.data); - } - } - }; - - if (loading) { - return ; - } - - if (error) { - return ; - } - - return ( - <> - - Editing {location} - -
- update(value)} - /> -
- {(yamlError || updateError) && - {(yamlError ?? '') + (updateError ?? '')}} -
- - -
- - ); -}; - -export default Edit; \ No newline at end of file diff --git a/src/web/src/components/System/Options/EditModal.js b/src/web/src/components/System/Options/EditModal.js new file mode 100644 index 00000000..b02cbf99 --- /dev/null +++ b/src/web/src/components/System/Options/EditModal.js @@ -0,0 +1,101 @@ +import React, { useState, useEffect } from 'react'; + +import { Button, Icon, Message, Modal } from 'semantic-ui-react'; +import CodeEditor from '../../Shared/CodeEditor'; + +import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options'; +import { + PlaceholderSegment, + Switch, +} from '../../Shared'; + +const EditModal = ({ open, onClose }) => { + const [{ loading, error }, setLoading] = useState({ loading: true, error: false }); + const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false }); + const [yamlError, setYamlError] = useState(); + const [updateError, setUpdateError] = useState(); + + useEffect(() => { + if (open) { + get(); + } + }, [open]); + + const get = async () => { + setLoading({ loading: true, error: false }); + + try { + 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 }); + } + }; + + const update = async (yaml) => { + setYaml({ location, 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) { + try { + await updateYaml({ yaml }); + onClose(); + } + catch (error) { + setUpdateError(error.response.data); + } + } + }; + + return ( + + + + Edit Options + + Editing {location} + + + + } + error={error && } + > +
+ update(value)} + /> +
+
+
+ + {(yamlError || updateError) && + + {(yamlError ?? '') + (updateError ?? '')} + } + + + +
+ ); +}; + +export default EditModal; \ 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 deleted file mode 100644 index 9d4d7635..00000000 --- a/src/web/src/components/System/Options/View.js +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import YAML from 'yaml'; - -import { Icon, Button } from 'semantic-ui-react'; -import CodeEditor from '../../Shared/CodeEditor'; - -const View = ({ options, editAction }) => { - const { remoteConfiguration } = options; - - const optionsAsYaml = YAML.stringify(options, { simpleKeys: true, sortMapEntries: true }); - - return ( - <> -
- -
-
- {remoteConfiguration ? - : - } -
- - ); -}; - -export default View; \ No newline at end of file diff --git a/src/web/src/components/System/Options/index.js b/src/web/src/components/System/Options/index.js index 92535b95..894199e9 100644 --- a/src/web/src/components/System/Options/index.js +++ b/src/web/src/components/System/Options/index.js @@ -1,16 +1,76 @@ import React, { useState } from 'react'; +import YAML from 'yaml'; -import Edit from './Edit'; -import View from './View'; +import DebugModal from './DebugModal'; +import EditModal from './EditModal'; + +import { Divider } from 'semantic-ui-react'; +import { + CodeEditor, + ShrinkableButton, +} from '../../Shared'; const Index = ({ options }) => { - const [mode, setMode] = useState('view'); + const [debugModal, setDebugModal] = useState(false); + const [editModal, setEditModal] = useState(false); + + const { remoteConfiguration, debug } = options; + + const optionsAsYaml = YAML.stringify(options, { simpleKeys: true, sortMapEntries: true }); + + const DebugButton = () => { + if (!debug) return <>; + + return setDebugModal(true)} + > + Debug View + ; + }; + + const EditButton = () => { + if (!remoteConfiguration) { + return Remote Configuration Disabled; + } - if (mode === 'edit') { - return setMode('view')}/>; - } + return setEditModal(true)} + >Edit; + }; - return setMode('edit')}/>; + return ( + <> +
+ + +
+ +
+ +
+ setDebugModal(false)} + /> + setEditModal(false)} + /> + + ); }; export default Index; \ 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 560cc21a..cbcddf81 100644 --- a/src/web/src/components/System/System.css +++ b/src/web/src/components/System/System.css @@ -24,15 +24,24 @@ min-height: 100px; } -.full-height { - height: calc(100vh - 175px); -} - .no-grow { white-space: nowrap; overflow: overlay; } +.edit-code-header { + margin-top: 1em !important; + font-size: initial !important; +} + +.edit-code-content, .debug-view-content { + padding: 0px !important; +} + +.left-align { + text-align: left; +} + .footer-buttons { margin-top: 14px; text-align: right; @@ -43,23 +52,6 @@ text-align: right; } -.state-code-editor, .view-code-container, .edit-code-container, .edit-code-container-error { - border: 1px solid #d4d4d5; +.edit-code-container, .edit-code-container-error { overflow: auto; -} - -.state-code-container { - height: calc(100vh - 204px); -} - -.view-code-container { - height: calc(100vh - 254px); -} - -.edit-code-container { - height: calc(100vh - 316px); -} - -.edit-code-container-error { - height: calc(100vh - 378px); } \ 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 8955b212..73904006 100644 --- a/src/web/src/components/System/System.js +++ b/src/web/src/components/System/System.js @@ -15,15 +15,42 @@ const System = ({ state = {}, options = {} }) => { const history = useHistory(); const panes = [ - { route: 'info', menuItem: 'Info', render: () => }, + { + route: 'info', + menuItem: { + key: 'info', + icon: 'info', + content: 'Info', + }, + render: () => , + }, { - route: 'options', menuItem: 'Options', render: () => - , + route: 'options', + menuItem: { + key: 'options', + icon: 'options', + content: 'Options', + }, + render: () => , }, { - route: 'shares', menuItem: 'Shares', render: () => , + route: 'shares', + menuItem: { + key: 'shares', + icon: 'share external', + content: 'Shares', + }, + render: () => , + }, + { + route: 'logs', + menuItem: { + key: 'logs', + icon: 'file outline', + content: 'Logs', + }, + render: () => , }, - { route: 'logs', menuItem: 'Logs', render: () => }, ]; const activeIndex = panes.findIndex(pane => pane.route === tab); -- cgit v1.2.3