comment out versions on code editor

remove configuration from install modal
This commit is contained in:
Davor 2022-08-05 19:57:07 +02:00
parent 198e926b4e
commit 94bd90486c
9 changed files with 84 additions and 104 deletions

View file

@ -4,7 +4,7 @@ import { useController } from 'react-hook-form';
import Editor from 'react-simple-code-editor'; import Editor from 'react-simple-code-editor';
/* eslint-disable react/react-in-jsx-scope */ /* eslint-disable react/react-in-jsx-scope */
export const CodeEditor = ({ control, name, required }: CodeEditorProps) => { export const CodeEditor = ({ control, name, required, disabled = false }: CodeEditorProps) => {
const { const {
field, field,
// fieldState: { invalid, isTouched, isDirty }, // fieldState: { invalid, isTouched, isDirty },
@ -25,6 +25,7 @@ export const CodeEditor = ({ control, name, required }: CodeEditorProps) => {
preClassName="font-mono whitespace-normal font-light" preClassName="font-mono whitespace-normal font-light"
textareaClassName="font-mono overflow-auto font-light" textareaClassName="font-mono overflow-auto font-light"
className="font-mono text-sm font-light" className="font-mono text-sm font-light"
disabled={disabled}
/> />
</> </>
); );
@ -34,4 +35,5 @@ type CodeEditorProps = {
control: any; control: any;
name: string; name: string;
required?: boolean; required?: boolean;
disabled?: boolean;
}; };

View file

@ -2,11 +2,14 @@ import React, { useState } from 'react';
import { TabPanel } from './TabPanel'; import { TabPanel } from './TabPanel';
import { TabsProps } from './types'; import { TabsProps } from './types';
export const Tabs = ({ tabs }: TabsProps) => { export const Tabs = ({ tabs, onTabClick }: TabsProps) => {
const [activeTabIndex, setActiveTabIndex] = useState<number>(0); const [activeTabIndex, setActiveTabIndex] = useState<number>(0);
const handleTabPress = (index: number) => () => { const handleTabPress = (index: number) => () => {
setActiveTabIndex(index); setActiveTabIndex(index);
if (onTabClick) {
onTabClick(index);
}
}; };
function classNames(...classes: any) { function classNames(...classes: any) {

View file

@ -6,6 +6,7 @@ type Tab = {
export interface TabsProps { export interface TabsProps {
tabs: Tab[]; tabs: Tab[];
onTabClick?: (index: number) => void;
} }
export interface TabPanelProps { export interface TabPanelProps {

View file

@ -1,20 +1,33 @@
import React, { Fragment } from 'react'; import React from 'react';
import _ from 'lodash';
import Editor from 'react-simple-code-editor'; import Editor from 'react-simple-code-editor';
import { Menu, Transition } from '@headlessui/react'; // import { Menu, Transition } from '@headlessui/react';
import { ChevronDownIcon } from '@heroicons/react/solid'; // import { ChevronDownIcon } from '@heroicons/react/solid';
import { highlight, languages } from 'prismjs'; import { highlight, languages } from 'prismjs';
import 'prismjs/components/prism-clike'; import 'prismjs/components/prism-clike';
import 'prismjs/components/prism-yaml'; import 'prismjs/components/prism-yaml';
import 'prismjs/themes/prism.css'; import 'prismjs/themes/prism.css';
import { showToast } from 'src/common/util/show-toast';
import { useApps } from 'src/services/apps';
import { initialEditorYaml } from '../../consts'; import { initialEditorYaml } from '../../consts';
// import { Secrets } from './components';
function classNames(...classes: any) {
return classes.filter(Boolean).join(' ');
}
export const AdvancedTab = () => { export const AdvancedTab = () => {
const [code, setCode] = React.useState(initialEditorYaml); 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 ( return (
<> <>
@ -22,41 +35,24 @@ export const AdvancedTab = () => {
<h1 className="text-2xl leading-6 font-medium text-gray-900">Configuration</h1> <h1 className="text-2xl leading-6 font-medium text-gray-900">Configuration</h1>
</div> </div>
<div className="grid grid-flow-col grid-cols-2 gap-8"> <div className="grid grid-flow-col grid-cols-2 gap-8">
<div> <div className="bg-gray-100 overflow-hidden rounded-lg">
<div className="bg-gray-100 overflow-hidden rounded-lg"> <div className="px-4 h-16 sm:px-6 bg-gray-200 flex items-center">
<div className="px-4 h-16 sm:px-6 bg-gray-200 flex items-center"> <span className="text-gray-600 text-lg leading-6 font-medium">Current Configuration</span>
<span className="text-gray-600 text-lg leading-6 font-medium">Current Configuration</span> </div>
</div> <div className="px-4 py-5 sm:p-6 overflow-x-auto">
<div className="px-4 py-5 sm:p-6 overflow-x-auto"> <Editor
<pre className="font-mono text-sm font-light"> value={initialEditorYaml}
{`luck: except onValueChange={_.noop}
natural: still highlight={(value) => highlight(value, languages.js, 'yaml')}
near: though preClassName="font-mono text-sm font-light"
search: textareaClassName="font-mono overflow-auto font-light"
- feature className="font-mono text-sm font-light"
- - 1980732354.689713 disabled
- 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`}
</pre>
</div>
</div> </div>
</div> </div>
<div> <div className="overflow-hidden rounded-lg">
<div> {/* <div className="px-4 h-16 sm:px-6 bg-gray-200 flex justify-between items-center rounded-t-lg">
<div className="px-4 h-16 sm:px-6 bg-gray-200 flex justify-between items-center rounded-t-lg">
<span className="text-gray-600 text-lg leading-6 font-medium">Edit Configuration</span> <span className="text-gray-600 text-lg leading-6 font-medium">Edit Configuration</span>
<Menu as="div" className="relative inline-block text-left"> <Menu as="div" className="relative inline-block text-left">
@ -121,30 +117,34 @@ search:
</Menu.Items> </Menu.Items>
</Transition> </Transition>
</Menu> </Menu>
</div> </div> */}
<div className="px-4 py-5 sm:p-6 border border-t-0 border-gray-200"> <div className="px-4 h-16 sm:px-6 bg-gray-200 flex items-center">
<Editor <span className="text-gray-600 text-lg leading-6 font-medium">Edit Configuration</span>
value={code} </div>
onValueChange={(value) => setCode(value)} <div className="px-4 py-5 sm:p-6 border border-t-0 border-gray-200">
highlight={(value) => highlight(value, languages.js, 'yaml')} <Editor
preClassName="font-mono whitespace-normal font-light" value={code}
textareaClassName="font-mono overflow-auto font-light" onValueChange={(value) => setCode(value)}
className="font-mono text-sm font-light" highlight={(value) => highlight(value, languages.js, 'yaml')}
/> preClassName="font-mono whitespace-normal font-light"
</div> textareaClassName="font-mono overflow-auto font-light"
className="font-mono text-sm font-light"
/>
</div> </div>
</div> </div>
</div> </div>
<div className="flex justify-end mt-10"> <div className="flex justify-end mt-10">
<button <button
type="button" type="button"
onClick={resetCode}
className="mr-3 inline-flex items-center px-4 py-2 border border-gray-200 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" className="mr-3 inline-flex items-center px-4 py-2 border border-gray-200 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
> >
Cancel Reset
</button> </button>
<button <button
type="button" type="button"
onClick={vertifyCode}
className="mr-3 inline-flex items-center px-4 py-2 shadow-sm text-sm font-medium rounded-md text-primary-700 bg-primary-100 hover:bg-primary-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" className="mr-3 inline-flex items-center px-4 py-2 shadow-sm text-sm font-medium rounded-md text-primary-700 bg-primary-100 hover:bg-primary-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
> >
Verify Verify
@ -152,6 +152,7 @@ search:
<button <button
type="button" type="button"
onClick={saveChanges}
className="inline-flex items-center px-4 py-2 shadow-sm text-sm font-medium rounded-md text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500" className="inline-flex items-center px-4 py-2 shadow-sm text-sm font-medium rounded-md text-white bg-primary-600 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
> >
Save changes Save changes

View file

@ -1,9 +1,9 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import _ from 'lodash'; import _ from 'lodash';
import { AppForm, useApps } from 'src/services/apps'; import { App, useApps } from 'src/services/apps';
import { Modal, Tabs } from 'src/components'; import { Modal } from 'src/components';
import { CodeEditor, Input } from 'src/components/Form'; import { Input } from 'src/components/Form';
import { appAccessList } from 'src/components/UserModal/consts'; import { appAccessList } from 'src/components/UserModal/consts';
import { AppInstallModalProps } from './types'; import { AppInstallModalProps } from './types';
import { initialAppForm, initialCode } from './consts'; import { initialAppForm, initialCode } from './consts';
@ -12,7 +12,7 @@ export const AppInstallModal = ({ open, onClose, appSlug }: AppInstallModalProps
const [appName, setAppName] = useState(''); const [appName, setAppName] = useState('');
const { app, appLoading, installApp, loadApp, clearSelectedApp } = useApps(); const { app, appLoading, installApp, loadApp, clearSelectedApp } = useApps();
const { control, reset, handleSubmit } = useForm<AppForm>({ const { control, reset, handleSubmit } = useForm<App>({
defaultValues: initialAppForm, defaultValues: initialAppForm,
}); });
@ -62,36 +62,6 @@ export const AppInstallModal = ({ open, onClose, appSlug }: AppInstallModalProps
} }
}; };
const renderSubdomain = () => {
return (
<div className="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
<div className="sm:col-span-3">
<Input control={control} name="subdomain" label="Subdomain" onKeyPress={handleKeyPress} required={false} />
</div>
</div>
);
};
const renderConfiguration = () => {
return (
<div>
<div className="bg-gray-100 overflow-hidden rounded-lg">
<div className="px-4 h-16 sm:px-6 bg-gray-200 flex items-center">
<span className="text-gray-600 text-lg leading-6 font-medium">App Configuration</span>
</div>
<div className="px-4 py-5 sm:p-6 overflow-x-auto">
<CodeEditor control={control} name="configuration" />
</div>
</div>
</div>
);
};
const tabs = [
{ name: 'Subdomain', component: renderSubdomain() },
{ name: 'Advanced Configuration', component: renderConfiguration() },
];
return ( return (
<> <>
<Modal onClose={handleClose} open={open} onSave={handleSave} isLoading={appLoading} useCancelButton> <Modal onClose={handleClose} open={open} onSave={handleSave} isLoading={appLoading} useCancelButton>
@ -102,8 +72,16 @@ export const AppInstallModal = ({ open, onClose, appSlug }: AppInstallModalProps
<h3 className="text-lg leading-6 font-medium text-gray-900">Install app {appName}</h3> <h3 className="text-lg leading-6 font-medium text-gray-900">Install app {appName}</h3>
</div> </div>
<div className="px-4 py-5 sm:p-6"> <div className="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
<Tabs tabs={tabs} /> <div className="sm:col-span-3">
<Input
control={control}
name="subdomain"
label="Subdomain"
onKeyPress={handleKeyPress}
required={false}
/>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,4 +1,4 @@
import { AppForm } from 'src/services/apps'; import { App } from 'src/services/apps';
export const initialCode = `luck: except export const initialCode = `luck: except
natural: still natural: still
@ -24,5 +24,4 @@ search:
export const initialAppForm = { export const initialAppForm = {
subdomain: '', subdomain: '',
configuration: initialCode, } as App;
} as AppForm;

View file

@ -3,8 +3,7 @@ import { CogIcon, PlusCircleIcon } from '@heroicons/react/outline';
import _ from 'lodash'; import _ from 'lodash';
import { AppStatus } from 'src/services/apps'; import { AppStatus } from 'src/services/apps';
export const initialEditorYaml = () => { export const initialEditorYaml = `luck: except
return `luck: except
natural: still natural: still
near: though near: though
search: search:
@ -25,7 +24,6 @@ search:
hospital: -1544066384.1973226 hospital: -1544066384.1973226
law: congress law: congress
great: stomach`; great: stomach`;
};
const tableConsts = [ const tableConsts = [
{ {

View file

@ -1,4 +1,4 @@
import { App, AppStatus, AppForm } from './types'; import { App, AppStatus } from './types';
const transformAppStatus = (status: string) => { const transformAppStatus = (status: string) => {
switch (status) { switch (status) {
@ -24,13 +24,14 @@ export const transformApp = (response: any): App => {
}; };
}; };
export const transformAppRequest = (data: AppForm) => { export const transformAppRequest = (data: App) => {
return { return {
automatic_updates: data.automaticUpdates, automatic_updates: data.automaticUpdates,
configuration: data.configuration,
}; };
}; };
export const transformInstallAppRequest = (data: AppForm) => { export const transformInstallAppRequest = (data: App) => {
return { return {
subdomain: data.subdomain, subdomain: data.subdomain,
configuration: data.configuration, configuration: data.configuration,

View file

@ -5,10 +5,7 @@ export interface App {
status?: AppStatus; status?: AppStatus;
subdomain?: string; subdomain?: string;
automaticUpdates: boolean; automaticUpdates: boolean;
} configuration?: string;
export interface AppForm extends App {
configuration: string;
} }
export interface DisableAppForm { export interface DisableAppForm {