diff --git a/.eslintrc.yml b/.eslintrc.yml index 1a68b1dc8..a4630dcb8 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -39,8 +39,7 @@ rules: comma-dangle: - warn - always-multiline - spaced-comment: - - warn + spaced-comment: 0 array-bracket-spacing: - warn - always diff --git a/resources/scripts/api/admin/nests/searchEggs.ts b/resources/scripts/api/admin/nests/searchEggs.ts new file mode 100644 index 000000000..50482bfa8 --- /dev/null +++ b/resources/scripts/api/admin/nests/searchEggs.ts @@ -0,0 +1,24 @@ +import http from '@/api/http'; +import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; + +interface Filters { + name?: string; +} + +export default (nestId: number, filters?: Filters): Promise => { + const params = {}; + if (filters !== undefined) { + Object.keys(filters).forEach(key => { + // @ts-ignore + params['filter[' + key + ']'] = filters[key]; + }); + } + + return new Promise((resolve, reject) => { + http.get(`/api/application/nests/${nestId}/eggs`, { params: { ...params } }) + .then(response => resolve( + (response.data.data || []).map(rawDataToEgg) + )) + .catch(reject); + }); +}; diff --git a/resources/scripts/api/admin/nests/searchNests.ts b/resources/scripts/api/admin/nests/searchNests.ts new file mode 100644 index 000000000..65cc41f36 --- /dev/null +++ b/resources/scripts/api/admin/nests/searchNests.ts @@ -0,0 +1,24 @@ +import http from '@/api/http'; +import { Nest, rawDataToNest } from '@/api/admin/nests/getNests'; + +interface Filters { + name?: string; +} + +export default (filters?: Filters): Promise => { + const params = {}; + if (filters !== undefined) { + Object.keys(filters).forEach(key => { + // @ts-ignore + params['filter[' + key + ']'] = filters[key]; + }); + } + + return new Promise((resolve, reject) => { + http.get('/api/application/nests', { params: { ...params } }) + .then(response => resolve( + (response.data.data || []).map(rawDataToNest) + )) + .catch(reject); + }); +}; diff --git a/resources/scripts/components/admin/servers/EggSelect.tsx b/resources/scripts/components/admin/servers/EggSelect.tsx new file mode 100644 index 000000000..ad1e27d74 --- /dev/null +++ b/resources/scripts/components/admin/servers/EggSelect.tsx @@ -0,0 +1,32 @@ +import Label from '@/components/elements/Label'; +import Select from '@/components/elements/Select'; +import React, { useEffect, useState } from 'react'; +import { Egg } from '@/api/admin/eggs/getEgg'; +import searchEggs from '@/api/admin/nests/searchEggs'; + +export default ({ nestId, eggId }: { nestId: number | null; eggId?: number }) => { + const [ eggs, setEggs ] = useState([]); + + useEffect(() => { + if (nestId === null) { + return; + } + + searchEggs(nestId, {}) + .then(eggs => setEggs(eggs)) + .catch(error => console.error(error)); + }, [ nestId ]); + + return ( + <> + + + + ); +}; diff --git a/resources/scripts/components/admin/servers/NestSelect.tsx b/resources/scripts/components/admin/servers/NestSelect.tsx new file mode 100644 index 000000000..0ab761b4c --- /dev/null +++ b/resources/scripts/components/admin/servers/NestSelect.tsx @@ -0,0 +1,30 @@ +import Label from '@/components/elements/Label'; +import Select from '@/components/elements/Select'; +import React, { useEffect, useState } from 'react'; +import { Nest } from '@/api/admin/nests/getNests'; +import searchNests from '@/api/admin/nests/searchNests'; + +export default ({ nestId, setNestId }: { nestId: number | null; setNestId: (value: number | null) => void }) => { + const [ nests, setNests ] = useState(null); + + useEffect(() => { + console.log(nestId || undefined); + + searchNests({}) + .then(nests => setNests(nests)) + .catch(error => console.error(error)); + }, []); + + return ( + <> + + + + ); +}; diff --git a/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx b/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx index 2dcf6c96b..d1ea56fc0 100644 --- a/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx @@ -135,7 +135,7 @@ export function ServerResourceContainer () { diff --git a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx index be2139d03..255c51be2 100644 --- a/resources/scripts/components/admin/servers/ServerStartupContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerStartupContainer.tsx @@ -1,153 +1,112 @@ -import React from 'react'; -import Button from '@/components/elements/Button'; +import EggSelect from '@/components/admin/servers/EggSelect'; +import NestSelect from '@/components/admin/servers/NestSelect'; import FormikSwitch from '@/components/elements/FormikSwitch'; +import React, { useState } from 'react'; +import Button from '@/components/elements/Button'; import Input from '@/components/elements/Input'; import AdminBox from '@/components/admin/AdminBox'; import tw from 'twin.macro'; import { object } from 'yup'; -import updateServer from '@/api/admin/servers/updateServer'; import Field from '@/components/elements/Field'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; -import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; +import { Form, Formik, useFormikContext } from 'formik'; import { Context } from '@/components/admin/servers/ServerRouter'; import { ApplicationStore } from '@/state'; import { Actions, useStoreActions } from 'easy-peasy'; import Label from '@/components/elements/Label'; -// import { ServerEggVariable } from '@/api/server/types'; -/* interface Props { - variable: ServerEggVariable; -} */ +// interface Values { +// startupCommand: string; +// image: string; +// +// eggId: number; +// skipScripts: boolean; +// } -interface Values { - startupCommand: string; - nestId: number; - eggId: number; -} - -/* const VariableBox = ({ variable }: Props) => { +function ServerStartupLineContainer () { const { isSubmitting } = useFormikContext(); - const server = Context.useStoreState(state => state.server); - - if (server === undefined) { - return ( - <> - ); - } - - return ( - - - -
-
- -
-
-
- ); -}; */ - -const ServerServiceContainer = () => { - const { isSubmitting } = useFormikContext(); - - const server = Context.useStoreState(state => state.server); - - if (server === undefined) { - return ( - <> - ); - } - - return ( - - - -
-
-
-
-

- This is a destructive operation in many cases. This server will be stopped immediately in order for this action to proceed. -

-
-
-

- Changing any of the below values will result in the server processing a re-install command. The server will be stopped and will then proceed. If you would like the service scripts to not run, ensure the box is checked at the bottom. -

-
-
-
- Nest/Egg Selector HERE -
-
-
- -
-
-
-
-
- ); -}; - -const ServerStartupContainer = () => { - const { isSubmitting } = useFormikContext(); - - const server = Context.useStoreState(state => state.server); - - if (server === undefined) { - return ( - <> - ); - } - return (
-
-
- -
+
+ +
-
-
- - -
+
+ + +
+ + + ); +} + +function ServerServiceContainer ({ nestId: nestId2, eggId }: { nestId: number | null; eggId: number | null }) { + const { isSubmitting } = useFormikContext(); + + const [ nestId, setNestId ] = useState(nestId2); + + return ( + + + +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ ); +} + +function ServerImageContainer () { + const { isSubmitting } = useFormikContext(); + + return ( + + + +
+
+
+
); -}; +} -export default () => { - const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); +export default function ServerStartupContainer () { + const { clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); const server = Context.useStoreState(state => state.server); - const setServer = Context.useStoreActions(actions => actions.setServer); if (server === undefined) { return ( @@ -155,16 +114,8 @@ export default () => { ); } - const submit = (values: Values, { setSubmitting }: FormikHelpers) => { + const submit = () => { clearFlashes('server'); - - // updateServer(server.id, values) - // .then(() => setServer({ ...server, ...values })) - // .catch(error => { - // console.error(error); - // clearAndAddHttpError({ key: 'server', error }); - // }) - // .then(() => setSubmitting(false)); }; return ( @@ -172,34 +123,56 @@ export default () => { onSubmit={submit} initialValues={{ startupCommand: server.container.startupCommand, - nestId: server.nestId, - eggId: server.eggId, + image: server.container.image, + eggId: 0, + skipScripts: false, }} - validationSchema={object().shape({ - })} + validationSchema={object().shape({})} > - { - ({ isSubmitting, isValid }) => ( -
-
- + {({ isSubmitting, isValid }) => ( +
+
+ +
+ +
+
+
-
- -
-
- Server Startup variables go here -
-
-
- -
+
+
- ) - } + + {/*
*/} + {/* {variables.map((variable, i) => (*/} + {/* {variable.name}

}*/} + {/* >*/} + {/* */} + {/* */} + {/* */} + {/*

*/} + {/* {variable.description}*/} + {/*

*/} + {/* */} + {/* ))}*/} + {/*
*/} + +
+
+ +
+
+
+ )} ); -}; +}