diff --git a/src/App.tsx b/src/App.tsx index f23474fe..130d842c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -38,7 +38,6 @@ import SqlInstaller from "./apps/Sql/Installer/SqlInstaller"; import SqlDatabase from "./apps/Sql/SqlDatabase/SqlDatabase"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; -import ServiceEditor from "./apps/DevToolsServiceEditor/ServiceEditor/ServiceEditor"; import Login from "./apps/Auth/pages/Login/Login"; import SettingsDb from "./apps/AdminSettings/SettingsData/SettingsDb"; import SettingsChecks from "./apps/AdminSettings/SettingsChecks/SettingsChecks"; @@ -121,10 +120,6 @@ function AllRoutes() { path="/containers/add" element={} /> - } - /> }> - { - const value = environmentTypes.find( - (e) => e.value === field.value - )?.label; - return ( - - {environmentTypes.map((e) => ( - - {e.label} - - ))} - - ); - }} - name={`environment.${i}.type`} - control={control} - /> - - - - - - ); -} - -function UrlInputs({ control, register, errors, i, env }) { - console.log(env); - return ( - - - { - const e = env?.find((e) => e.name === field.value); - return ( - - {env?.map((env) => { - if (env.type !== "port") return null; - return ( - - {env.name} - - ); - })} - - ); - }} - name={`urls.${i}.port`} - control={control} - /> - { - const value = urlKinds.find( - (e) => e.value === field.value - )?.label; - return ( - - {urlKinds.map((e) => ( - - {e.label} - - ))} - - ); - }} - name={`urls.${i}.kind`} - control={control} - /> - - - ); -} - -function VolumeInputs({ register, errors, i }) { - return ( -
- - -
- ); -} - -function PortInputs({ control, register, errors, i, env }) { - return ( -
- - { - const e = env?.find((e) => e.name === field.value); - return ( - - {env?.map((env) => { - if (env.type !== "port") return null; - return ( - - {env.name} - - ); - })} - - ); - }} - name={`methods.docker.ports.${i}.value`} - control={control} - /> -
- ); -} - -function ContainerEnvironmentInputs({ register, errors, i }) { - return ( -
- - -
- ); -} - -const environmentTypes = [ - { value: "string", label: "String" }, - { value: "port", label: "Port" }, - { value: "timezone", label: "Timezone" }, - { value: "url", label: "URL" }, -]; - -const urlKinds = [ - { value: "client", label: "Client" }, - { value: "server", label: "Server" }, -]; - -const schema = object({ - id: yup - .string() - .label("Service ID") - .required() - .matches( - /^[a-z0-9-]+$/, - "Can only have lowercase letters, numbers and dashes." - ), - name: yup.string().label("Service name").required(), - repository: yup.string().label("Repository").url(), - description: yup.string().label("Description").required().max(100), - color: yup - .string() - .label("Color") - .matches(/^#[0-9a-f]{6}$/i, { - message: "Must be a valid hex color.", - excludeEmptyString: true, - }), - - environment: yup.array().of( - yup.object().shape({ - type: yup - .string() - .label("Type") - .oneOf(environmentTypes.map((e) => e.value)) - .required(), - name: yup - .string() - .label("Name") - .matches( - /^[A-Z0-9_]+$/, - "Can only have uppercase letters, numbers and underscores." - ) - .required(), - display_name: yup.string().label("Display name").required(), - default: yup.string().label("Default value"), - description: yup.string().label("Description").max(100), - }) - ), - - urls: yup.array().of( - yup.object().shape({ - name: yup.string().label("Name").required(), - port: yup.string().label("Port").required(), - ping: yup.string().label("Ping"), - kind: yup - .string() - .label("Kind") - .oneOf(urlKinds.map((e) => e.value)) - .required(), - }) - ), - - methods: yup.object().shape({ - docker: yup.object().shape({ - image: yup.string().label("Docker image").required(), - command: yup.string().label("Command"), - volumes: yup.array().of( - yup.object().shape({ - key: yup.string().label("Name").required(), - value: yup.string().label("Path").required(), - }) - ), - ports: yup.array().of( - yup.object().shape({ - key: yup.number().label("Port input").required(), - value: yup.string().label("Port output").required(), - }) - ), - environment: yup.array().of( - yup.object().shape({ - key: yup.string().label("Name").required(), - value: yup.string().label("Name").required(), - }) - ), - }), - }), -}); - -type FormData = yup.InferType; - -export default function ServiceEditor() { - useTitle("Service Editor"); - - const resolver = yupResolver(schema); - const { - control, - register, - handleSubmit, - getValues: getService, - formState: { errors }, - } = useForm({ resolver }); - const onSubmit: SubmitHandler = (data) => console.log(data); - - const { - fields: environment, - append: appendEnvironment, - remove: removeEnvironment, - } = useFieldArray({ - control, - name: "environment", - }); - - const { - fields: urls, - append: appendUrl, - remove: removeUrl, - } = useFieldArray({ - control, - name: "urls", - }); - - const { - fields: volumes, - append: appendVolume, - remove: removeVolume, - } = useFieldArray({ - control, - name: "methods.docker.volumes", - }); - - const { - fields: ports, - append: appendPort, - remove: removePort, - } = useFieldArray({ - control, - name: "methods.docker.ports", - }); - - const { - fields: containerEnvironment, - append: appendContainerEnvironment, - remove: removeContainerEnvironment, - } = useFieldArray({ - control, - name: "methods.docker.environment", - }); - - const [yaml, setYaml] = useState(); - - const env = useWatch({ control, name: "environment", defaultValue: [] }); - - const download = () => { - const service = getService(); - console.log(service); - - const s: any = produce(service, (draft: any) => { - const volumes = draft.methods.docker.volumes; - const newVolumes = Object.assign( - {}, - ...volumes.map((x: any) => ({ [x.key]: x.value })) - ); - - const ports = draft.methods.docker.ports; - const newPorts = Object.assign( - {}, - ...ports.map((x: any) => ({ [x.key]: x.value })) - ); - - const environment = draft.methods.docker.environment; - const newEnvironment = Object.assign( - {}, - ...environment.map((x: any) => ({ [x.key]: x.value })) - ); - - return { - ...draft, - methods: { - docker: { - volumes: newVolumes, - ports: newPorts, - environment: newEnvironment, - }, - }, - }; - }); - - console.log(s); - - api.vxServiceEditor.editor.toYaml(s).then((data) => setYaml(data)); - }; - - return ( - - Info -
- - - - - -
- - - Environment - - - - {environment.length === 0 && ( - - )} - - {environment.map((field, i) => { - return ( - - - - - Environment variable #{i + 1} - - - - -
- -
-
-
- ); - })} -
- - - URLs - - - - {urls.length === 0 && } - - {urls.map((field, i) => { - return ( - - - - URL #{i + 1} - - - -
- -
-
-
- ); - })} -
- - Docker - - - - - - - Docker Volumes - - - - {volumes.length === 0 ? ( - - ) : ( - - {volumes.map((field, i) => { - return ( -
- - -
- ); - })} -
- )} - - - Docker Ports - - - - {ports.length === 0 ? ( - - ) : ( - - {ports.map((field, i) => { - return ( -
- - -
- ); - })} -
- )} - - - Docker Environments - - - - {containerEnvironment.length === 0 ? ( - - ) : ( - - {containerEnvironment.map((field, i) => { - return ( -
- - -
- ); - })} -
- )} - - Service.yml - {yaml} - - - - - - -
- ); -} diff --git a/src/backend/api/backend.ts b/src/backend/api/backend.ts index d52b696a..1d25e669 100644 --- a/src/backend/api/backend.ts +++ b/src/backend/api/backend.ts @@ -3,7 +3,6 @@ import { vxMonitoringRoutes } from "./vxMonitoring"; import { vxSqlRoutes } from "./vxSql"; import { vxReverseProxyRoutes } from "./vxReverseProxy"; import { VertexApp } from "../../models/app"; -import { vxServiceEditorRoutes } from "./vxServiceEditor"; import { createServer } from "../server"; // @ts-ignore @@ -14,7 +13,6 @@ export const api = { vxMonitoring: vxMonitoringRoutes, vxSql: vxSqlRoutes, vxReverseProxy: vxReverseProxyRoutes, - vxServiceEditor: vxServiceEditorRoutes, apps: { all: async () => { diff --git a/src/backend/api/vxServiceEditor.ts b/src/backend/api/vxServiceEditor.ts deleted file mode 100644 index 70901806..00000000 --- a/src/backend/api/vxServiceEditor.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Template } from "../../apps/Containers/backend/template"; - -import { createServer } from "../server"; - -// @ts-ignore -const server = createServer(window.api_urls.devtools_service_editor); - -const toYaml = async (service: Template) => { - const { data } = await server.post(`/editor/to-yaml`, service); - return data; -}; - -const editorRoutes = { - toYaml: toYaml, -}; - -export const vxServiceEditorRoutes = { - editor: editorRoutes, -};