chore: run prettier
This commit is contained in:
parent
9cdbbc3a00
commit
155d7bb876
76 changed files with 788 additions and 550 deletions
|
@ -1,11 +1,26 @@
|
|||
import http from '@/api/http';
|
||||
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
|
||||
|
||||
export default (name: string, host: string, port: number, username: string, password: string, include: string[] = []): Promise<Database> => {
|
||||
export default (
|
||||
name: string,
|
||||
host: string,
|
||||
port: number,
|
||||
username: string,
|
||||
password: string,
|
||||
include: string[] = [],
|
||||
): Promise<Database> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/databases', {
|
||||
name, host, port, username, password,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.post(
|
||||
'/api/application/databases',
|
||||
{
|
||||
name,
|
||||
host,
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToDatabase(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface Database {
|
|||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
getAddress (): string;
|
||||
getAddress(): string;
|
||||
}
|
||||
|
||||
export const rawDataToDatabase = ({ attributes }: FractalResponseData): Database => ({
|
||||
|
@ -53,12 +53,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Database>>([ 'databases', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/databases', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Database>>(['databases', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/databases', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToDatabase),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -17,9 +17,7 @@ export default (filters?: Filters): Promise<Database[]> => {
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/databases', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(rawDataToDatabase)
|
||||
))
|
||||
.then(response => resolve((response.data.data || []).map(rawDataToDatabase)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
import http from '@/api/http';
|
||||
import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases';
|
||||
|
||||
export default (id: number, name: string, host: string, port: number, username: string, password: string | undefined, include: string[] = []): Promise<Database> => {
|
||||
export default (
|
||||
id: number,
|
||||
name: string,
|
||||
host: string,
|
||||
port: number,
|
||||
username: string,
|
||||
password: string | undefined,
|
||||
include: string[] = [],
|
||||
): Promise<Database> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(`/api/application/databases/${id}`, {
|
||||
name, host, port, username, password,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.patch(
|
||||
`/api/application/databases/${id}`,
|
||||
{
|
||||
name,
|
||||
host,
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToDatabase(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles: string, configStartup: string };
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles: string; configStartup: string };
|
||||
|
||||
export default (egg: Partial<Egg2>): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post(
|
||||
'/api/application/eggs',
|
||||
{
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
},
|
||||
)
|
||||
http.post('/api/application/eggs', {
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
})
|
||||
.then(({ data }) => resolve(rawDataToEgg(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -5,18 +5,15 @@ import { Transformers } from '@definitions/admin';
|
|||
export type CreateEggVariable = Omit<EggVariable, 'id' | 'eggId' | 'createdAt' | 'updatedAt' | 'relationships'>;
|
||||
|
||||
export default async (eggId: number, variable: CreateEggVariable): Promise<EggVariable> => {
|
||||
const { data } = await http.post(
|
||||
`/api/application/eggs/${eggId}/variables`,
|
||||
{
|
||||
name: variable.name,
|
||||
description: variable.description,
|
||||
env_variable: variable.environmentVariable,
|
||||
default_value: variable.defaultValue,
|
||||
user_viewable: variable.isUserViewable,
|
||||
user_editable: variable.isUserEditable,
|
||||
rules: variable.rules,
|
||||
},
|
||||
);
|
||||
const { data } = await http.post(`/api/application/eggs/${eggId}/variables`, {
|
||||
name: variable.name,
|
||||
description: variable.description,
|
||||
env_variable: variable.environmentVariable,
|
||||
default_value: variable.defaultValue,
|
||||
user_viewable: variable.isUserViewable,
|
||||
user_editable: variable.isUserEditable,
|
||||
rules: variable.rules,
|
||||
});
|
||||
|
||||
return Transformers.toEggVariable(data);
|
||||
};
|
||||
|
|
|
@ -1,30 +1,27 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles?: string, configStartup?: string };
|
||||
type Egg2 = Omit<Omit<Partial<Egg>, 'configFiles'>, 'configStartup'> & { configFiles?: string; configStartup?: string };
|
||||
|
||||
export default (id: number, egg: Partial<Egg2>): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(
|
||||
`/api/application/eggs/${id}`,
|
||||
{
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
},
|
||||
)
|
||||
http.patch(`/api/application/eggs/${id}`, {
|
||||
nest_id: egg.nestId,
|
||||
name: egg.name,
|
||||
description: egg.description,
|
||||
features: egg.features,
|
||||
docker_images: egg.dockerImages,
|
||||
config_files: egg.configFiles,
|
||||
config_startup: egg.configStartup,
|
||||
config_stop: egg.configStop,
|
||||
config_from: egg.configFrom,
|
||||
startup: egg.startup,
|
||||
script_container: egg.scriptContainer,
|
||||
copy_script_from: egg.copyScriptFrom,
|
||||
script_entry: egg.scriptEntry,
|
||||
script_is_privileged: egg.scriptIsPrivileged,
|
||||
script_install: egg.scriptInstall,
|
||||
})
|
||||
.then(({ data }) => resolve(rawDataToEgg(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -2,7 +2,10 @@ import http from '@/api/http';
|
|||
import { EggVariable } from '@/api/admin/egg';
|
||||
import { Transformers } from '@definitions/admin';
|
||||
|
||||
export default async (eggId: number, variables: Omit<EggVariable, 'eggId' | 'createdAt' | 'updatedAt'>[]): Promise<EggVariable[]> => {
|
||||
export default async (
|
||||
eggId: number,
|
||||
variables: Omit<EggVariable, 'eggId' | 'createdAt' | 'updatedAt'>[],
|
||||
): Promise<EggVariable[]> => {
|
||||
const { data } = await http.patch(
|
||||
`/api/application/eggs/${eggId}/variables`,
|
||||
variables.map(variable => ({
|
||||
|
|
|
@ -4,11 +4,11 @@ export interface VersionData {
|
|||
panel: {
|
||||
current: string;
|
||||
latest: string;
|
||||
}
|
||||
};
|
||||
|
||||
wings: {
|
||||
latest: string;
|
||||
}
|
||||
};
|
||||
|
||||
git: string | null;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ export type UUID = string;
|
|||
export type WithRelationships<M extends Model, R extends string> = Omit<M, 'relationships'> & {
|
||||
relationships: Omit<M['relationships'], keyof R> & {
|
||||
[K in R]: NonNullable<M['relationships'][K]>;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper type that allows you to infer the type of an object by giving
|
||||
|
@ -29,7 +29,7 @@ export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends
|
|||
* such that TypeScript understands the relationships on it. This is just to help
|
||||
* reduce the amount of duplicated type casting all over the codebase.
|
||||
*/
|
||||
export const withRelationships = <M extends Model, R extends string> (model: M, ..._keys: R[]) => {
|
||||
export const withRelationships = <M extends Model, R extends string>(model: M, ..._keys: R[]) => {
|
||||
return model as unknown as WithRelationships<M, R>;
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ export interface ListContext<T> {
|
|||
setSortDirection: (direction: ((p: boolean) => boolean) | boolean) => void;
|
||||
}
|
||||
|
||||
function create<T> () {
|
||||
function create<T>() {
|
||||
return createContext<ListContext<T>>({
|
||||
page: 1,
|
||||
setPage: () => 1,
|
||||
|
|
|
@ -3,9 +3,14 @@ import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'
|
|||
|
||||
export default (short: string, long: string | null, include: string[] = []): Promise<Location> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/locations', {
|
||||
short, long,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.post(
|
||||
'/api/application/locations',
|
||||
{
|
||||
short,
|
||||
long,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToLocation(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -43,12 +43,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Location>>([ 'locations', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/locations', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Location>>(['locations', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/locations', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToLocation),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -17,9 +17,7 @@ export default (filters?: Filters): Promise<Location[]> => {
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/locations', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(rawDataToLocation)
|
||||
))
|
||||
.then(response => resolve((response.data.data || []).map(rawDataToLocation)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -3,9 +3,14 @@ import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'
|
|||
|
||||
export default (id: number, short: string, long: string | null, include: string[] = []): Promise<Location> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(`/api/application/locations/${id}`, {
|
||||
short, long,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.patch(
|
||||
`/api/application/locations/${id}`,
|
||||
{
|
||||
short,
|
||||
long,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToLocation(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,28 @@
|
|||
import http from '@/api/http';
|
||||
import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts';
|
||||
|
||||
export default (name: string, description: string, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise<Mount> => {
|
||||
export default (
|
||||
name: string,
|
||||
description: string,
|
||||
source: string,
|
||||
target: string,
|
||||
readOnly: boolean,
|
||||
userMountable: boolean,
|
||||
include: string[] = [],
|
||||
): Promise<Mount> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/mounts', {
|
||||
name, description, source, target, read_only: readOnly, user_mountable: userMountable,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.post(
|
||||
'/api/application/mounts',
|
||||
{
|
||||
name,
|
||||
description,
|
||||
source,
|
||||
target,
|
||||
read_only: readOnly,
|
||||
user_mountable: userMountable,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToMount(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -40,7 +40,9 @@ export const rawDataToMount = ({ attributes }: FractalResponseData): Mount => ({
|
|||
relations: {
|
||||
eggs: ((attributes.relationships?.eggs as FractalResponseList | undefined)?.data || []).map(rawDataToEgg),
|
||||
nodes: ((attributes.relationships?.nodes as FractalResponseList | undefined)?.data || []).map(rawDataToNode),
|
||||
servers: ((attributes.relationships?.servers as FractalResponseList | undefined)?.data || []).map(rawDataToServer),
|
||||
servers: ((attributes.relationships?.servers as FractalResponseList | undefined)?.data || []).map(
|
||||
rawDataToServer,
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -69,12 +71,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Mount>>([ 'mounts', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/mounts', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Mount>>(['mounts', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/mounts', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToMount),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
import http from '@/api/http';
|
||||
import { Mount, rawDataToMount } from '@/api/admin/mounts/getMounts';
|
||||
|
||||
export default (id: number, name: string, description: string | null, source: string, target: string, readOnly: boolean, userMountable: boolean, include: string[] = []): Promise<Mount> => {
|
||||
export default (
|
||||
id: number,
|
||||
name: string,
|
||||
description: string | null,
|
||||
source: string,
|
||||
target: string,
|
||||
readOnly: boolean,
|
||||
userMountable: boolean,
|
||||
include: string[] = [],
|
||||
): Promise<Mount> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(`/api/application/mounts/${id}`, {
|
||||
name, description, source, target, read_only: readOnly, user_mountable: userMountable,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.patch(
|
||||
`/api/application/mounts/${id}`,
|
||||
{
|
||||
name,
|
||||
description,
|
||||
source,
|
||||
target,
|
||||
read_only: readOnly,
|
||||
user_mountable: userMountable,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToMount(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -3,9 +3,14 @@ import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
|
|||
|
||||
export default (name: string, description: string | null, include: string[] = []): Promise<Nest> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/nests', {
|
||||
name, description,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.post(
|
||||
'/api/application/nests',
|
||||
{
|
||||
name,
|
||||
description,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToNest(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -27,12 +27,14 @@ export default (nestId: number, include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Egg>>([ nestId, 'eggs', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get(`/api/application/nests/${nestId}/eggs`, { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Egg>>([nestId, 'eggs', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get(`/api/application/nests/${nestId}/eggs`, {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToEgg),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ export interface Nest {
|
|||
|
||||
relations: {
|
||||
eggs: Egg[] | undefined;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({
|
||||
|
@ -55,12 +55,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Nest>>([ 'nests', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/nests', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Nest>>(['nests', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/nests', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToNest),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -3,9 +3,14 @@ import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
|
|||
|
||||
export default (id: number, name: string, description: string | null, include: string[] = []): Promise<Nest> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(`/api/application/nests/${id}`, {
|
||||
name, description,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.patch(
|
||||
`/api/application/nests/${id}`,
|
||||
{
|
||||
name,
|
||||
description,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToNest(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ export interface Node extends Model {
|
|||
export const getNode = async (id: string | number): Promise<WithRelationships<Node, 'location'>> => {
|
||||
const { data } = await http.get(`/api/application/nodes/${id}`, {
|
||||
params: {
|
||||
include: [ 'location' ],
|
||||
include: ['location'],
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -75,7 +75,10 @@ export const searchNodes = async (params: QueryBuilderParams<'name'>): Promise<N
|
|||
return data.data.map(Transformers.toNode);
|
||||
};
|
||||
|
||||
export const getAllocations = async (id: string | number, params?: QueryBuilderParams<'ip' | 'server_id'>): Promise<Allocation[]> => {
|
||||
export const getAllocations = async (
|
||||
id: string | number,
|
||||
params?: QueryBuilderParams<'ip' | 'server_id'>,
|
||||
): Promise<Allocation[]> => {
|
||||
const { data } = await http.get(`/api/application/nodes/${id}/allocations`, {
|
||||
params: withQueryBuilderParams(params),
|
||||
});
|
||||
|
|
|
@ -28,12 +28,14 @@ export default (id: number, include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Allocation>>([ 'allocations', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get(`/api/application/nodes/${id}/allocations`, { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Allocation>>(['allocations', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get(`/api/application/nodes/${id}/allocations`, {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToAllocation),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -25,7 +25,7 @@ export interface Values {
|
|||
export default (values: Values, include: string[] = []): Promise<Node> => {
|
||||
const data = {};
|
||||
|
||||
Object.keys(values).forEach((key) => {
|
||||
Object.keys(values).forEach(key => {
|
||||
const key2 = key
|
||||
.replace('HTTP', 'Http')
|
||||
.replace('SFTP', 'Sftp')
|
||||
|
|
|
@ -11,9 +11,9 @@ export interface Allocation {
|
|||
|
||||
relations: {
|
||||
server?: Server;
|
||||
}
|
||||
};
|
||||
|
||||
getDisplayText (): string;
|
||||
getDisplayText(): string;
|
||||
}
|
||||
|
||||
export const rawDataToAllocation = ({ attributes }: FractalResponseData): Allocation => ({
|
||||
|
@ -25,11 +25,14 @@ export const rawDataToAllocation = ({ attributes }: FractalResponseData): Alloca
|
|||
assigned: attributes.assigned,
|
||||
|
||||
relations: {
|
||||
server: attributes.relationships?.server?.object === 'server' ? rawDataToServer(attributes.relationships.server as FractalResponseData) : undefined,
|
||||
server:
|
||||
attributes.relationships?.server?.object === 'server'
|
||||
? rawDataToServer(attributes.relationships.server as FractalResponseData)
|
||||
: undefined,
|
||||
},
|
||||
|
||||
// TODO: If IP is an IPv6, wrap IP in [].
|
||||
getDisplayText (): string {
|
||||
getDisplayText(): string {
|
||||
if (attributes.alias !== null) {
|
||||
return `${attributes.ip}:${attributes.port} (${attributes.alias})`;
|
||||
}
|
||||
|
@ -38,7 +41,7 @@ export const rawDataToAllocation = ({ attributes }: FractalResponseData): Alloca
|
|||
});
|
||||
|
||||
export interface Filters {
|
||||
ip?: string
|
||||
ip?: string;
|
||||
/* eslint-disable camelcase */
|
||||
server_id?: string;
|
||||
/* eslint-enable camelcase */
|
||||
|
|
|
@ -33,7 +33,7 @@ export interface Node {
|
|||
relations: {
|
||||
databaseHost: Database | undefined;
|
||||
location: Location | undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({
|
||||
|
@ -63,8 +63,15 @@ export const rawDataToNode = ({ attributes }: FractalResponseData): Node => ({
|
|||
|
||||
relations: {
|
||||
// eslint-disable-next-line camelcase
|
||||
databaseHost: attributes.relationships?.database_host !== undefined && attributes.relationships?.database_host.object !== 'null_resource' ? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData) : undefined,
|
||||
location: attributes.relationships?.location !== undefined ? rawDataToLocation(attributes.relationships.location as FractalResponseData) : undefined,
|
||||
databaseHost:
|
||||
attributes.relationships?.database_host !== undefined &&
|
||||
attributes.relationships?.database_host.object !== 'null_resource'
|
||||
? rawDataToDatabase(attributes.relationships.database_host as FractalResponseData)
|
||||
: undefined,
|
||||
location:
|
||||
attributes.relationships?.location !== undefined
|
||||
? rawDataToLocation(attributes.relationships.location as FractalResponseData)
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -96,12 +103,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Node>>([ 'nodes', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/nodes', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Node>>(['nodes', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/nodes', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToNode),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes';
|
|||
export default (id: number, node: Partial<Node>, include: string[] = []): Promise<Node> => {
|
||||
const data = {};
|
||||
|
||||
Object.keys(node).forEach((key) => {
|
||||
Object.keys(node).forEach(key => {
|
||||
const key2 = key
|
||||
.replace('HTTP', 'Http')
|
||||
.replace('SFTP', 'Sftp')
|
||||
|
|
|
@ -13,9 +13,14 @@ export const Context = createContext<Filters>();
|
|||
|
||||
const createRole = (name: string, description: string | null, include: string[] = []): Promise<UserRole> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/roles', {
|
||||
name, description,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.post(
|
||||
'/api/application/roles',
|
||||
{
|
||||
name,
|
||||
description,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(Transformers.toUserRole(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
@ -48,18 +53,26 @@ const searchRoles = (filters?: { name?: string }): Promise<UserRole[]> => {
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get('/api/application/roles', { params })
|
||||
.then(response => resolve(
|
||||
(response.data.data || []).map(Transformers.toUserRole)
|
||||
))
|
||||
.then(response => resolve((response.data.data || []).map(Transformers.toUserRole)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const updateRole = (id: number, name: string, description: string | null, include: string[] = []): Promise<UserRole> => {
|
||||
const updateRole = (
|
||||
id: number,
|
||||
name: string,
|
||||
description: string | null,
|
||||
include: string[] = [],
|
||||
): Promise<UserRole> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.patch(`/api/application/roles/${id}`, {
|
||||
name, description,
|
||||
}, { params: { include: include.join(',') } })
|
||||
http.patch(
|
||||
`/api/application/roles/${id}`,
|
||||
{
|
||||
name,
|
||||
description,
|
||||
},
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(Transformers.toUserRole(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
@ -83,21 +96,16 @@ const getRoles = (include: string[] = []) => {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
return useSWR<PaginatedResult<UserRole>>([ 'roles', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/roles', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<UserRole>>(['roles', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/roles', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(Transformers.toUserRole),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
createRole,
|
||||
deleteRole,
|
||||
getRole,
|
||||
searchRoles,
|
||||
updateRole,
|
||||
getRoles,
|
||||
};
|
||||
export { createRole, deleteRole, getRole, searchRoles, updateRole, getRoles };
|
||||
|
|
|
@ -16,7 +16,7 @@ export interface CreateServerRequest {
|
|||
cpu: number;
|
||||
threads: string;
|
||||
oomDisabled: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
featureLimits: {
|
||||
allocations: number;
|
||||
|
@ -39,41 +39,45 @@ export interface CreateServerRequest {
|
|||
|
||||
export default (r: CreateServerRequest, include: string[] = []): Promise<Server> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/servers', {
|
||||
externalId: r.externalId,
|
||||
name: r.name,
|
||||
description: r.description,
|
||||
owner_id: r.ownerId,
|
||||
node_id: r.nodeId,
|
||||
http.post(
|
||||
'/api/application/servers',
|
||||
{
|
||||
externalId: r.externalId,
|
||||
name: r.name,
|
||||
description: r.description,
|
||||
owner_id: r.ownerId,
|
||||
node_id: r.nodeId,
|
||||
|
||||
limits: {
|
||||
cpu: r.limits.cpu,
|
||||
disk: r.limits.disk,
|
||||
io: r.limits.io,
|
||||
memory: r.limits.memory,
|
||||
swap: r.limits.swap,
|
||||
threads: r.limits.threads,
|
||||
oom_killer: r.limits.oomDisabled,
|
||||
limits: {
|
||||
cpu: r.limits.cpu,
|
||||
disk: r.limits.disk,
|
||||
io: r.limits.io,
|
||||
memory: r.limits.memory,
|
||||
swap: r.limits.swap,
|
||||
threads: r.limits.threads,
|
||||
oom_killer: r.limits.oomDisabled,
|
||||
},
|
||||
|
||||
feature_limits: {
|
||||
allocations: r.featureLimits.allocations,
|
||||
backups: r.featureLimits.backups,
|
||||
databases: r.featureLimits.databases,
|
||||
},
|
||||
|
||||
allocation: {
|
||||
default: r.allocation.default,
|
||||
additional: r.allocation.additional,
|
||||
},
|
||||
|
||||
startup: r.startup,
|
||||
environment: r.environment,
|
||||
egg_id: r.eggId,
|
||||
image: r.image,
|
||||
skip_scripts: r.skipScripts,
|
||||
start_on_completion: r.startOnCompletion,
|
||||
},
|
||||
|
||||
feature_limits: {
|
||||
allocations: r.featureLimits.allocations,
|
||||
backups: r.featureLimits.backups,
|
||||
databases: r.featureLimits.databases,
|
||||
},
|
||||
|
||||
allocation: {
|
||||
default: r.allocation.default,
|
||||
additional: r.allocation.additional,
|
||||
},
|
||||
|
||||
startup: r.startup,
|
||||
environment: r.environment,
|
||||
egg_id: r.eggId,
|
||||
image: r.image,
|
||||
skip_scripts: r.skipScripts,
|
||||
start_on_completion: r.startOnCompletion,
|
||||
}, { params: { include: include.join(',') } })
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToServer(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -41,7 +41,7 @@ export const rawDataToServerVariable = ({ attributes }: FractalResponseData): Se
|
|||
|
||||
export interface Server {
|
||||
id: number;
|
||||
externalId: string | null
|
||||
externalId: string | null;
|
||||
uuid: string;
|
||||
identifier: string;
|
||||
name: string;
|
||||
|
@ -56,13 +56,13 @@ export interface Server {
|
|||
cpu: number;
|
||||
threads: string | null;
|
||||
oomDisabled: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
featureLimits: {
|
||||
databases: number;
|
||||
allocations: number;
|
||||
backups: number;
|
||||
}
|
||||
};
|
||||
|
||||
ownerId: number;
|
||||
nodeId: number;
|
||||
|
@ -74,7 +74,7 @@ export interface Server {
|
|||
startup: string;
|
||||
image: string;
|
||||
environment: Map<string, string>;
|
||||
}
|
||||
};
|
||||
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
@ -85,57 +85,71 @@ export interface Server {
|
|||
node?: Node;
|
||||
user?: User;
|
||||
variables: ServerVariable[];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const rawDataToServer = ({ attributes }: FractalResponseData): Server => ({
|
||||
id: attributes.id,
|
||||
externalId: attributes.external_id,
|
||||
uuid: attributes.uuid,
|
||||
identifier: attributes.identifier,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
status: attributes.status,
|
||||
export const rawDataToServer = ({ attributes }: FractalResponseData): Server =>
|
||||
({
|
||||
id: attributes.id,
|
||||
externalId: attributes.external_id,
|
||||
uuid: attributes.uuid,
|
||||
identifier: attributes.identifier,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
status: attributes.status,
|
||||
|
||||
limits: {
|
||||
memory: attributes.limits.memory,
|
||||
swap: attributes.limits.swap,
|
||||
disk: attributes.limits.disk,
|
||||
io: attributes.limits.io,
|
||||
cpu: attributes.limits.cpu,
|
||||
threads: attributes.limits.threads,
|
||||
oomDisabled: attributes.limits.oom_disabled,
|
||||
},
|
||||
limits: {
|
||||
memory: attributes.limits.memory,
|
||||
swap: attributes.limits.swap,
|
||||
disk: attributes.limits.disk,
|
||||
io: attributes.limits.io,
|
||||
cpu: attributes.limits.cpu,
|
||||
threads: attributes.limits.threads,
|
||||
oomDisabled: attributes.limits.oom_disabled,
|
||||
},
|
||||
|
||||
featureLimits: {
|
||||
databases: attributes.feature_limits.databases,
|
||||
allocations: attributes.feature_limits.allocations,
|
||||
backups: attributes.feature_limits.backups,
|
||||
},
|
||||
featureLimits: {
|
||||
databases: attributes.feature_limits.databases,
|
||||
allocations: attributes.feature_limits.allocations,
|
||||
backups: attributes.feature_limits.backups,
|
||||
},
|
||||
|
||||
ownerId: attributes.owner_id,
|
||||
nodeId: attributes.node_id,
|
||||
allocationId: attributes.allocation_id,
|
||||
nestId: attributes.nest_id,
|
||||
eggId: attributes.egg_id,
|
||||
ownerId: attributes.owner_id,
|
||||
nodeId: attributes.node_id,
|
||||
allocationId: attributes.allocation_id,
|
||||
nestId: attributes.nest_id,
|
||||
eggId: attributes.egg_id,
|
||||
|
||||
container: {
|
||||
startup: attributes.container.startup,
|
||||
image: attributes.container.image,
|
||||
environment: attributes.container.environment,
|
||||
},
|
||||
container: {
|
||||
startup: attributes.container.startup,
|
||||
image: attributes.container.image,
|
||||
environment: attributes.container.environment,
|
||||
},
|
||||
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
|
||||
relations: {
|
||||
allocations: ((attributes.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(rawDataToAllocation),
|
||||
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' ? Transformers.toUser(attributes.relationships.user as FractalResponseData) : undefined,
|
||||
variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerVariable),
|
||||
},
|
||||
}) as Server;
|
||||
relations: {
|
||||
allocations: ((attributes.relationships?.allocations as FractalResponseList | undefined)?.data || []).map(
|
||||
rawDataToAllocation,
|
||||
),
|
||||
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'
|
||||
? Transformers.toUser(attributes.relationships.user as FractalResponseData)
|
||||
: undefined,
|
||||
variables: ((attributes.relationships?.variables as FractalResponseList | undefined)?.data || []).map(
|
||||
rawDataToServerVariable,
|
||||
),
|
||||
},
|
||||
} as Server);
|
||||
|
||||
export interface Filters {
|
||||
id?: string;
|
||||
|
@ -166,12 +180,14 @@ export default (include: string[] = []) => {
|
|||
params.sort = (sortDirection ? '-' : '') + sort;
|
||||
}
|
||||
|
||||
return useSWR<PaginatedResult<Server>>([ 'servers', page, filters, sort, sortDirection ], async () => {
|
||||
const { data } = await http.get('/api/application/servers', { params: { include: include.join(','), page, ...params } });
|
||||
return useSWR<PaginatedResult<Server>>(['servers', page, filters, sort, sortDirection], async () => {
|
||||
const { data } = await http.get('/api/application/servers', {
|
||||
params: { include: include.join(','), page, ...params },
|
||||
});
|
||||
|
||||
return ({
|
||||
return {
|
||||
items: (data.data || []).map(rawDataToServer),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -14,13 +14,13 @@ export interface Values {
|
|||
cpu: number;
|
||||
threads: string;
|
||||
oomDisabled: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
featureLimits: {
|
||||
allocations: number;
|
||||
backups: number;
|
||||
databases: number;
|
||||
}
|
||||
};
|
||||
|
||||
allocationId: number;
|
||||
addAllocations: number[];
|
||||
|
@ -56,7 +56,7 @@ export default (id: number, server: Partial<Values>, include: string[] = []): Pr
|
|||
add_allocations: server.addAllocations,
|
||||
remove_allocations: server.removeAllocations,
|
||||
},
|
||||
{ params: { include: include.join(',') } }
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToServer(data)))
|
||||
.catch(reject);
|
||||
|
|
|
@ -20,7 +20,7 @@ export default (id: number, values: Partial<Values>, include: string[] = []): Pr
|
|||
image: values.image,
|
||||
skip_scripts: values.skipScripts,
|
||||
},
|
||||
{ params: { include: include.join(',') } }
|
||||
{ params: { include: include.join(',') } },
|
||||
)
|
||||
.then(({ data }) => resolve(rawDataToServer(data)))
|
||||
.catch(reject);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue