diff --git a/app/Transformers/Api/Application/ServerVariableTransformer.php b/app/Transformers/Api/Application/ServerVariableTransformer.php index af06b1e97..8a9b910db 100644 --- a/app/Transformers/Api/Application/ServerVariableTransformer.php +++ b/app/Transformers/Api/Application/ServerVariableTransformer.php @@ -24,9 +24,9 @@ class ServerVariableTransformer extends Transformer return ServerVariable::RESOURCE_NAME; } - public function transform(EggVariable $variable): array + public function transform(EggVariable $model): array { - return $variable->toArray(); + return $model->toArray(); } /** diff --git a/resources/scripts/api/admin/nests/searchEggs.ts b/resources/scripts/api/admin/nests/searchEggs.ts index 50482bfa8..8bb0f3185 100644 --- a/resources/scripts/api/admin/nests/searchEggs.ts +++ b/resources/scripts/api/admin/nests/searchEggs.ts @@ -5,7 +5,7 @@ interface Filters { name?: string; } -export default (nestId: number, filters?: Filters): Promise => { +export default (nestId: number, filters?: Filters, include: string[] = []): Promise => { const params = {}; if (filters !== undefined) { Object.keys(filters).forEach(key => { @@ -15,7 +15,7 @@ export default (nestId: number, filters?: Filters): Promise => { } return new Promise((resolve, reject) => { - http.get(`/api/application/nests/${nestId}/eggs`, { params: { ...params } }) + http.get(`/api/application/nests/${nestId}/eggs`, { params: { include: include.join(','), ...params } }) .then(response => resolve( (response.data.data || []).map(rawDataToEgg) )) diff --git a/resources/scripts/api/admin/servers/getServers.ts b/resources/scripts/api/admin/servers/getServers.ts index 5dd7deba1..0c6d49bf4 100644 --- a/resources/scripts/api/admin/servers/getServers.ts +++ b/resources/scripts/api/admin/servers/getServers.ts @@ -7,6 +7,38 @@ import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; import { User, rawDataToUser } from '@/api/admin/users/getUsers'; +export interface ServerVariable { + id: number; + eggId: number; + name: string; + description: string; + envVariable: string; + defaultValue: string; + userViewable: boolean; + userEditable: boolean; + rules: string; + required: boolean; + serverValue: string; + createdAt: Date; + updatedAt: Date; +} + +const rawDataToServerVariable = ({ attributes }: FractalResponseData): ServerVariable => ({ + id: attributes.id, + eggId: attributes.egg_id, + name: attributes.name, + description: attributes.description, + envVariable: attributes.env_variable, + defaultValue: attributes.default_value, + userViewable: attributes.user_viewable, + userEditable: attributes.user_editable, + rules: attributes.rules, + required: attributes.required, + serverValue: attributes.server_value, + createdAt: new Date(attributes.created_at), + updatedAt: new Date(attributes.updated_at), +}); + export interface Server { id: number; externalId: string | null @@ -53,6 +85,7 @@ export interface Server { egg?: Egg; node?: Node; user?: User; + variables: ServerVariable[]; } } @@ -102,6 +135,7 @@ export const rawDataToServer = ({ attributes }: FractalResponseData): Server => egg: attributes.relationships?.egg?.object === 'egg' ? rawDataToEgg(attributes.relationships.egg as FractalResponseData) : undefined, node: attributes.relationships?.node?.object === 'node' ? rawDataToNode(attributes.relationships.node as FractalResponseData) : undefined, user: attributes.relationships?.user?.object === 'user' ? rawDataToUser(attributes.relationships.user as FractalResponseData) : undefined, + variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerVariable), }, }) as Server; diff --git a/resources/scripts/api/admin/servers/updateServer.ts b/resources/scripts/api/admin/servers/updateServer.ts index d4ac2b750..47e09a963 100644 --- a/resources/scripts/api/admin/servers/updateServer.ts +++ b/resources/scripts/api/admin/servers/updateServer.ts @@ -31,7 +31,6 @@ export default (id: number, server: Partial, include: string[] = []): Pr // @ts-ignore data[key2] = server[key]; }); - console.log(data); return new Promise((resolve, reject) => { http.patch(`/api/application/servers/${id}`, data, { params: { include: include.join(',') } }) diff --git a/resources/scripts/components/admin/AdminBox.tsx b/resources/scripts/components/admin/AdminBox.tsx index 12d53c3c4..3c77e8180 100644 --- a/resources/scripts/components/admin/AdminBox.tsx +++ b/resources/scripts/components/admin/AdminBox.tsx @@ -19,7 +19,7 @@ const AdminBox = ({ icon, title, className, padding, children }: Props) => { return (
-
+
{typeof title === 'string' ?

{icon && }{title} @@ -28,7 +28,7 @@ const AdminBox = ({ icon, title, className, padding, children }: Props) => { title }

-
+
{children}
diff --git a/resources/scripts/components/admin/servers/EggSelect.tsx b/resources/scripts/components/admin/servers/EggSelect.tsx index ad1e27d74..e042d3709 100644 --- a/resources/scripts/components/admin/servers/EggSelect.tsx +++ b/resources/scripts/components/admin/servers/EggSelect.tsx @@ -4,7 +4,7 @@ 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 }) => { +export default ({ nestId, egg, setEgg }: { nestId: number | null; egg: Egg | null, setEgg: (value: Egg | null) => void }) => { const [ eggs, setEggs ] = useState([]); useEffect(() => { @@ -12,15 +12,27 @@ export default ({ nestId, eggId }: { nestId: number | null; eggId?: number }) => return; } - searchEggs(nestId, {}) - .then(eggs => setEggs(eggs)) + searchEggs(nestId, {}, [ 'variables' ]) + .then(eggs => { + setEggs(eggs); + if (eggs.length < 1) { + setEgg(null); + return; + } + setEgg(eggs[0]); + }) .catch(error => console.error(error)); }, [ nestId ]); return ( <> - setEgg(eggs.find(egg => egg.id.toString() === e.currentTarget.value) || null)} + > {eggs.map(v => (