Re-enable debugbar, add table to ServersContainer.tsx
This commit is contained in:
parent
ed73f6a020
commit
8f1a5bf0ab
15 changed files with 446 additions and 82 deletions
|
@ -1,5 +1,4 @@
|
|||
import http from '@/api/http';
|
||||
import { rawDataToEgg } from '@/api/transformers';
|
||||
import http, { FractalResponseData } from '@/api/http';
|
||||
|
||||
export interface Egg {
|
||||
id: number;
|
||||
|
@ -25,6 +24,30 @@ export interface Egg {
|
|||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
nest_id: attributes.nest_id,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
features: attributes.features,
|
||||
dockerImages: attributes.docker_images,
|
||||
configFiles: attributes.config_files,
|
||||
configStartup: attributes.config_startup,
|
||||
configLogs: attributes.config_logs,
|
||||
configStop: attributes.config_stop,
|
||||
configFrom: attributes.config_from,
|
||||
startup: attributes.startup,
|
||||
scriptContainer: attributes.script_container,
|
||||
copyScriptFrom: attributes.copy_script_from,
|
||||
scriptEntry: attributes.script_entry,
|
||||
scriptIsPrivileged: attributes.script_is_privileged,
|
||||
scriptInstall: attributes.script_install,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
export default (id: number): Promise<Egg[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/nests/${id}`)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { rawDataToNest } from '@/api/transformers';
|
||||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
|
@ -13,6 +12,16 @@ export interface Nest {
|
|||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
interface ctx {
|
||||
page: number;
|
||||
setPage: (value: number | ((s: number) => number)) => void;
|
||||
|
|
69
resources/scripts/api/admin/nodes/getNodes.ts
Normal file
69
resources/scripts/api/admin/nodes/getNodes.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
export interface Node {
|
||||
id: number;
|
||||
uuid: string;
|
||||
public: boolean;
|
||||
name: string;
|
||||
description: string | null;
|
||||
locationId: number;
|
||||
fqdn: string;
|
||||
scheme: string;
|
||||
behindProxy: boolean;
|
||||
maintenanceMode: boolean;
|
||||
memory: number;
|
||||
memoryOverallocate: number;
|
||||
disk: number;
|
||||
diskOverallocate: number;
|
||||
uploadSize: number;
|
||||
daemonListen: number;
|
||||
daemonSftp: number;
|
||||
daemonBase: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
public: attributes.public,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
locationId: attributes.location_id,
|
||||
fqdn: attributes.fqdn,
|
||||
scheme: attributes.scheme,
|
||||
behindProxy: attributes.behind_proxy,
|
||||
maintenanceMode: attributes.maintenance_mode,
|
||||
memory: attributes.memory,
|
||||
memoryOverallocate: attributes.memory_overallocate,
|
||||
disk: attributes.disk,
|
||||
diskOverallocate: attributes.disk_overallocate,
|
||||
uploadSize: attributes.upload_size,
|
||||
daemonListen: attributes.daemon_listen,
|
||||
daemonSftp: attributes.daemon_sftp,
|
||||
daemonBase: attributes.daemon_base,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
interface ctx {
|
||||
page: number;
|
||||
setPage: (value: number | ((s: number) => number)) => void;
|
||||
}
|
||||
|
||||
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
||||
|
||||
export default () => {
|
||||
const { page } = useContext(Context);
|
||||
|
||||
return useSWR<PaginatedResult<Node>>([ 'nodes', page ], async () => {
|
||||
const { data } = await http.get('/api/application/nodes', { params: { page } });
|
||||
|
||||
return ({
|
||||
items: (data.data || []).map(rawDataToNode),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
import http from '@/api/http';
|
||||
import { rawDataToAdminRole } from '@/api/transformers';
|
||||
import http, { FractalResponseData } from '@/api/http';
|
||||
|
||||
export interface Role {
|
||||
id: number;
|
||||
|
@ -7,10 +6,16 @@ export interface Role {
|
|||
description: string | null;
|
||||
}
|
||||
|
||||
export const rawDataToRole = ({ attributes }: FractalResponseData): Role => ({
|
||||
id: attributes.id,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
});
|
||||
|
||||
export default (): Promise<Role[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/roles')
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToAdminRole)))
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToRole)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
|
63
resources/scripts/api/admin/servers/getServers.ts
Normal file
63
resources/scripts/api/admin/servers/getServers.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
|
||||
import { User, rawDataToUser } from '@/api/admin/users/getUsers';
|
||||
|
||||
export interface Server {
|
||||
id: number;
|
||||
externalId: string;
|
||||
uuid: string;
|
||||
identifier: string;
|
||||
name: string;
|
||||
description: string;
|
||||
isSuspended: boolean;
|
||||
isInstalling: boolean;
|
||||
isTransferring: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
relations: {
|
||||
node: Node | undefined;
|
||||
user: User | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
const rawDataToServerObject = ({ attributes }: FractalResponseData): Server => ({
|
||||
id: attributes.id,
|
||||
externalId: attributes.external_id,
|
||||
uuid: attributes.uuid,
|
||||
identifier: attributes.identifier,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
isSuspended: attributes.is_suspended,
|
||||
isInstalling: attributes.is_installing,
|
||||
isTransferring: attributes.is_transferring,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
|
||||
relations: {
|
||||
node: attributes.relationships?.node !== undefined ? rawDataToNode(attributes.relationships.node as FractalResponseData) : undefined,
|
||||
user: attributes.relationships?.user !== undefined ? rawDataToUser(attributes.relationships.user as FractalResponseData) : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
interface ctx {
|
||||
page: number;
|
||||
setPage: (value: number | ((s: number) => number)) => void;
|
||||
}
|
||||
|
||||
export const Context = createContext<ctx>({ page: 1, setPage: () => 1 });
|
||||
|
||||
export default () => {
|
||||
const { page } = useContext(Context);
|
||||
|
||||
return useSWR<PaginatedResult<Server>>([ 'servers', page ], async () => {
|
||||
const { data } = await http.get('/api/application/servers', { params: { include: 'node,user', page } });
|
||||
|
||||
return ({
|
||||
items: (data.data || []).map(rawDataToServerObject),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
});
|
||||
};
|
|
@ -1,5 +1,4 @@
|
|||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { rawDataToUser } from '@/api/transformers';
|
||||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
|
@ -19,6 +18,22 @@ export interface User {
|
|||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToUser = ({ attributes }: FractalResponseData): User => ({
|
||||
id: attributes.id,
|
||||
externalId: attributes.external_id,
|
||||
uuid: attributes.uuid,
|
||||
username: attributes.username,
|
||||
email: attributes.email,
|
||||
firstName: attributes.first_name,
|
||||
lastName: attributes.last_name,
|
||||
language: attributes.language,
|
||||
rootAdmin: attributes.root_admin,
|
||||
tfa: attributes['2fa'],
|
||||
roleName: attributes.role_name,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
interface ctx {
|
||||
page: number;
|
||||
setPage: (value: number | ((s: number) => number)) => void;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import { Egg } from '@/api/admin/nests/eggs/getEggs';
|
||||
import { Nest } from '@/api/admin/nests/getNests';
|
||||
import { Role } from '@/api/admin/roles/getRoles';
|
||||
import { User } from '@/api/admin/users/getUsers';
|
||||
import { Allocation } from '@/api/server/getServer';
|
||||
import { FractalResponseData } from '@/api/http';
|
||||
import { Allocation } from '@/api/server/getServer';
|
||||
import { FileObject } from '@/api/server/files/loadDirectory';
|
||||
import { ServerBackup, ServerEggVariable } from '@/api/server/types';
|
||||
|
||||
|
@ -78,59 +74,3 @@ export const rawDataToServerEggVariable = ({ attributes }: FractalResponseData):
|
|||
isEditable: attributes.is_editable,
|
||||
rules: attributes.rules.split('|'),
|
||||
});
|
||||
|
||||
export const rawDataToAdminRole = ({ attributes }: FractalResponseData): Role => ({
|
||||
id: attributes.id,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
});
|
||||
|
||||
export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
nest_id: attributes.nest_id,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
features: attributes.features,
|
||||
dockerImages: attributes.docker_images,
|
||||
configFiles: attributes.config_files,
|
||||
configStartup: attributes.config_startup,
|
||||
configLogs: attributes.config_logs,
|
||||
configStop: attributes.config_stop,
|
||||
configFrom: attributes.config_from,
|
||||
startup: attributes.startup,
|
||||
scriptContainer: attributes.script_container,
|
||||
copyScriptFrom: attributes.copy_script_from,
|
||||
scriptEntry: attributes.script_entry,
|
||||
scriptIsPrivileged: attributes.script_is_privileged,
|
||||
scriptInstall: attributes.script_install,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
export const rawDataToUser = ({ attributes }: FractalResponseData): User => ({
|
||||
id: attributes.id,
|
||||
externalId: attributes.external_id,
|
||||
uuid: attributes.uuid,
|
||||
username: attributes.username,
|
||||
email: attributes.email,
|
||||
firstName: attributes.first_name,
|
||||
lastName: attributes.last_name,
|
||||
language: attributes.language,
|
||||
rootAdmin: attributes.root_admin,
|
||||
tfa: attributes['2fa'],
|
||||
roleName: attributes.role_name,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue