From 94bd90486c8a33c0d78afdc54647daa59ddbde9c Mon Sep 17 00:00:00 2001 From: Davor Date: Fri, 5 Aug 2022 19:57:07 +0200 Subject: [PATCH] comment out versions on code editor remove configuration from install modal --- src/components/Form/CodeEditor/CodeEditor.tsx | 4 +- src/components/Tabs/Tabs.tsx | 5 +- src/components/Tabs/types.ts | 1 + .../components/AdvancedTab/AdvancedTab.tsx | 107 +++++++++--------- .../AppInstallModal/AppInstallModal.tsx | 50 +++----- .../apps/components/AppInstallModal/consts.ts | 5 +- src/modules/apps/consts.tsx | 4 +- src/services/apps/transformations.ts | 7 +- src/services/apps/types.ts | 5 +- 9 files changed, 84 insertions(+), 104 deletions(-) diff --git a/src/components/Form/CodeEditor/CodeEditor.tsx b/src/components/Form/CodeEditor/CodeEditor.tsx index e0ad33d..b395f8b 100644 --- a/src/components/Form/CodeEditor/CodeEditor.tsx +++ b/src/components/Form/CodeEditor/CodeEditor.tsx @@ -4,7 +4,7 @@ import { useController } from 'react-hook-form'; import Editor from 'react-simple-code-editor'; /* eslint-disable react/react-in-jsx-scope */ -export const CodeEditor = ({ control, name, required }: CodeEditorProps) => { +export const CodeEditor = ({ control, name, required, disabled = false }: CodeEditorProps) => { const { field, // fieldState: { invalid, isTouched, isDirty }, @@ -25,6 +25,7 @@ export const CodeEditor = ({ control, name, required }: CodeEditorProps) => { preClassName="font-mono whitespace-normal font-light" textareaClassName="font-mono overflow-auto font-light" className="font-mono text-sm font-light" + disabled={disabled} /> ); @@ -34,4 +35,5 @@ type CodeEditorProps = { control: any; name: string; required?: boolean; + disabled?: boolean; }; diff --git a/src/components/Tabs/Tabs.tsx b/src/components/Tabs/Tabs.tsx index 850dc17..92a1852 100644 --- a/src/components/Tabs/Tabs.tsx +++ b/src/components/Tabs/Tabs.tsx @@ -2,11 +2,14 @@ import React, { useState } from 'react'; import { TabPanel } from './TabPanel'; import { TabsProps } from './types'; -export const Tabs = ({ tabs }: TabsProps) => { +export const Tabs = ({ tabs, onTabClick }: TabsProps) => { const [activeTabIndex, setActiveTabIndex] = useState(0); const handleTabPress = (index: number) => () => { setActiveTabIndex(index); + if (onTabClick) { + onTabClick(index); + } }; function classNames(...classes: any) { diff --git a/src/components/Tabs/types.ts b/src/components/Tabs/types.ts index 342266a..00584fd 100644 --- a/src/components/Tabs/types.ts +++ b/src/components/Tabs/types.ts @@ -6,6 +6,7 @@ type Tab = { export interface TabsProps { tabs: Tab[]; + onTabClick?: (index: number) => void; } export interface TabPanelProps { diff --git a/src/modules/apps/components/AdvancedTab/AdvancedTab.tsx b/src/modules/apps/components/AdvancedTab/AdvancedTab.tsx index d538172..384392e 100644 --- a/src/modules/apps/components/AdvancedTab/AdvancedTab.tsx +++ b/src/modules/apps/components/AdvancedTab/AdvancedTab.tsx @@ -1,20 +1,33 @@ -import React, { Fragment } from 'react'; +import React from 'react'; +import _ from 'lodash'; import Editor from 'react-simple-code-editor'; -import { Menu, Transition } from '@headlessui/react'; -import { ChevronDownIcon } from '@heroicons/react/solid'; +// import { Menu, Transition } from '@headlessui/react'; +// import { ChevronDownIcon } from '@heroicons/react/solid'; import { highlight, languages } from 'prismjs'; import 'prismjs/components/prism-clike'; import 'prismjs/components/prism-yaml'; import 'prismjs/themes/prism.css'; +import { showToast } from 'src/common/util/show-toast'; +import { useApps } from 'src/services/apps'; import { initialEditorYaml } from '../../consts'; -// import { Secrets } from './components'; - -function classNames(...classes: any) { - return classes.filter(Boolean).join(' '); -} export const AdvancedTab = () => { const [code, setCode] = React.useState(initialEditorYaml); + const { app, editApp } = useApps(); + + const resetCode = () => { + setCode(initialEditorYaml); + showToast('Code was reset.'); + }; + + const vertifyCode = () => { + // call yaml verification (only format) + // const result = validateSchema(code, {}); + }; + + const saveChanges = () => { + editApp({ ...app, configuration: code }); + }; return ( <> @@ -22,41 +35,24 @@ export const AdvancedTab = () => {

Configuration

-
-
-
- Current Configuration -
-
-
-                {`luck: except
-natural: still
-near: though
-search:
-  - feature
-  - - 1980732354.689713
-    - hour
-    - butter:
-        ordinary: 995901949.8974948
-        teeth: true
-        whole:
-          - -952367353
-          - - talk: -1773961379
-              temperature: false
-              oxygen: true
-              laugh:
-                flag:
-                  in: 2144751662
-                  hospital: -1544066384.1973226
-                  law: congress
-                  great: stomach`}
-              
-
+
+
+ Current Configuration +
+
+ highlight(value, languages.js, 'yaml')} + preClassName="font-mono text-sm font-light" + textareaClassName="font-mono overflow-auto font-light" + className="font-mono text-sm font-light" + disabled + />
-
-
-
+
+ {/*
Edit Configuration @@ -121,30 +117,34 @@ search: -
-
- setCode(value)} - highlight={(value) => highlight(value, languages.js, 'yaml')} - preClassName="font-mono whitespace-normal font-light" - textareaClassName="font-mono overflow-auto font-light" - className="font-mono text-sm font-light" - /> -
+
*/} +
+ Edit Configuration +
+
+ setCode(value)} + highlight={(value) => highlight(value, languages.js, 'yaml')} + preClassName="font-mono whitespace-normal font-light" + textareaClassName="font-mono overflow-auto font-light" + className="font-mono text-sm font-light" + />
-
- +
+
+ +
diff --git a/src/modules/apps/components/AppInstallModal/consts.ts b/src/modules/apps/components/AppInstallModal/consts.ts index ee4b0b4..c3d5fa9 100644 --- a/src/modules/apps/components/AppInstallModal/consts.ts +++ b/src/modules/apps/components/AppInstallModal/consts.ts @@ -1,4 +1,4 @@ -import { AppForm } from 'src/services/apps'; +import { App } from 'src/services/apps'; export const initialCode = `luck: except natural: still @@ -24,5 +24,4 @@ search: export const initialAppForm = { subdomain: '', - configuration: initialCode, -} as AppForm; +} as App; diff --git a/src/modules/apps/consts.tsx b/src/modules/apps/consts.tsx index 4172b9c..1638007 100644 --- a/src/modules/apps/consts.tsx +++ b/src/modules/apps/consts.tsx @@ -3,8 +3,7 @@ import { CogIcon, PlusCircleIcon } from '@heroicons/react/outline'; import _ from 'lodash'; import { AppStatus } from 'src/services/apps'; -export const initialEditorYaml = () => { - return `luck: except +export const initialEditorYaml = `luck: except natural: still near: though search: @@ -25,7 +24,6 @@ search: hospital: -1544066384.1973226 law: congress great: stomach`; -}; const tableConsts = [ { diff --git a/src/services/apps/transformations.ts b/src/services/apps/transformations.ts index 0d66b28..aa4f0ed 100644 --- a/src/services/apps/transformations.ts +++ b/src/services/apps/transformations.ts @@ -1,4 +1,4 @@ -import { App, AppStatus, AppForm } from './types'; +import { App, AppStatus } from './types'; const transformAppStatus = (status: string) => { switch (status) { @@ -24,13 +24,14 @@ export const transformApp = (response: any): App => { }; }; -export const transformAppRequest = (data: AppForm) => { +export const transformAppRequest = (data: App) => { return { automatic_updates: data.automaticUpdates, + configuration: data.configuration, }; }; -export const transformInstallAppRequest = (data: AppForm) => { +export const transformInstallAppRequest = (data: App) => { return { subdomain: data.subdomain, configuration: data.configuration, diff --git a/src/services/apps/types.ts b/src/services/apps/types.ts index e3af6aa..317f171 100644 --- a/src/services/apps/types.ts +++ b/src/services/apps/types.ts @@ -5,10 +5,7 @@ export interface App { status?: AppStatus; subdomain?: string; automaticUpdates: boolean; -} - -export interface AppForm extends App { - configuration: string; + configuration?: string; } export interface DisableAppForm {