Skip to content

Commit

Permalink
chore(client): adjust to snake-case names in notebooks responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Jan 24, 2024
1 parent ede9062 commit d7cfff0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 63 deletions.
15 changes: 0 additions & 15 deletions client/src/api-client/notebook-servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ function addNotebookServersMethods(client) {
.then((resp) => {
let { data } = resp;

// ? rename defaultUrl to default_url to prevent conflicts later with project options
if (data && "defaultUrl" in data) {
data.default_url = data.defaultUrl;
delete data.defaultUrl;
}

Object.keys(data).forEach((key) => {
data[key].selected = data[key].default;
});
Expand All @@ -113,15 +107,6 @@ function addNotebookServersMethods(client) {
const url = `${client.baseUrl}/notebooks/servers`;
let notebook;

// ? rename default_url to legacy defaultUrl
if (
options &&
options.serverOptions &&
"default_url" in options.serverOptions
) {
options.serverOptions.defaultUrl = options.serverOptions.default_url;
delete options.serverOptions.default_url;
}
if (
options &&
options.serverOptions &&
Expand Down
24 changes: 18 additions & 6 deletions client/src/features/session/sessions.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,24 @@ const sessionsApi = createApi({
url: "server_options",
}),
transformResponse: ({
defaultUrl,
...legacyOptions
}: ServerOptionsResponse) => ({
defaultUrl: defaultUrl as ServerOption<string>,
legacyOptions,
}),
default_url,
...legacyOptionsResponse
}: ServerOptionsResponse) => {
const legacyOptions: { [k: string]: ServerOption } = {};
Object.keys(legacyOptionsResponse).forEach((k) => {
legacyOptions[k] = {
...legacyOptionsResponse[k],
displayName: legacyOptionsResponse[k].display_name,
} as ServerOption;
});
return {
defaultUrl: {
...default_url,
displayName: default_url.display_name,
} as ServerOption<string>,
legacyOptions ,
};
},
}),
stopSession: builder.mutation<boolean, StopSessionArgs>({
query: (args) => ({
Expand Down
13 changes: 12 additions & 1 deletion client/src/features/session/sessions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ export interface ServerOption<T extends number | string = number | string> {
type: "enum" | "int" | "float" | "boolean";
}

export interface ServerOptionResponse<
T extends number | string = number | string
> {
allow_any_value?: boolean;
default: T;
display_name: string;
options: T[];
order: number;
type: "enum" | "int" | "float" | "boolean";
}

export interface ServerOptions {
defaultUrl: ServerOption<string>;
legacyOptions: Record<string, ServerOption>;
}

export type ServerOptionsResponse = Record<string, ServerOption>;
export type ServerOptionsResponse = Record<string, ServerOptionResponse>;

export type Sessions = Record<string, Session>;

Expand Down
6 changes: 3 additions & 3 deletions client/src/features/versions/versions.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export const versionsApi = createApi({
name: response.name,
version: singleVersion?.version ?? "unavailable",
anonymousSessionsEnabled:
singleVersion?.data?.anonymousSessionsEnabled ?? false,
sshEnabled: singleVersion?.data?.sshEnabled ?? false,
singleVersion?.data?.anonymous_sessions_enabled ?? false,
sshEnabled: singleVersion?.data?.ssh_enabled ?? false,
cloudStorageEnabled:
singleVersion?.data?.cloudstorageEnabled ?? false,
singleVersion?.data?.cloudstorage_enabled ?? false,
};
},
transformErrorResponse: () => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/features/versions/versions.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export interface KgVersion {

interface NotebookComponent extends BaseVersion {
data: {
anonymousSessionsEnabled: boolean;
cloudstorageEnabled: boolean;
sshEnabled: boolean;
anonymous_sessions_enabled: boolean;
cloudstorage_enabled: boolean;
ssh_enabled: boolean;
};
}

Expand Down
26 changes: 21 additions & 5 deletions server/src/websocket/handlers/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,23 @@ import { WsMessage } from "../WsMessages";
import { simpleHash, sortObjectProperties } from "../../utils";

interface SessionsResult {
servers: Record<string, Session>;
servers: Record<string, SessionResponse >;
}
interface SessionResponse {
status: {
details: {
status: string;
step: string;
}[];
message?: string;
ready_num_containers: number;
state: {
pod_name: string;
[key: string]: unknown;
};
total_num_containers: number;
[key: string]: unknown;
};
}

interface Session {
Expand Down Expand Up @@ -74,16 +90,16 @@ function heartbeatRequestSessionStatus(
const {
details,
message,
readyNumContainers,
ready_num_containers,
state,
totalNumContainers,
total_num_containers,
} = session.status;
const cleanedStatus = {
details: details ?? [],
...(message ? { message } : {}),
readyNumContainers: readyNumContainers ?? -1,
readyNumContainers: ready_num_containers ?? -1,
state: state ?? { pod_name: "" },
totalNumContainers: totalNumContainers ?? -1,
totalNumContainers: total_num_containers ?? -1,
};
return [key, { status: cleanedStatus }] as const;
}
Expand Down
20 changes: 8 additions & 12 deletions tests/cypress/fixtures/session/server-options.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
{
"cpu_request": {
"default": 0.1,
"displayName": "Number of CPUs",
"display_name": "Number of CPUs",
"options": [0.1, 0.5],
"order": 2,
"type": "enum"
},
"defaultUrl": {
"default_url": {
"default": "/lab",
"displayName": "Default Environment",
"display_name": "Default Environment",
"options": ["/lab", "/rstudio"],
"order": 1,
"type": "enum"
},
"disk_request": {
"default": "1G",
"displayName": "Amount of Storage",
"display_name": "Amount of Storage",
"options": ["1G", "4G", "16G"],
"order": 3,
"type": "enum"
},
"gpu_request": {
"default": 0,
"displayName": "Number of GPUs",
"display_name": "Number of GPUs",
"options": [0],
"order": 5,
"type": "enum"
},
"lfs_auto_fetch": {
"default": false,
"displayName": "Automatically fetch LFS data",
"display_name": "Automatically fetch LFS data",
"order": 6,
"type": "boolean"
},
"mem_request": {
"default": "1G",
"displayName": "Amount of Memory",
"display_name": "Amount of Memory",
"options": ["1G", "2G"],
"order": 4,
"type": "enum"
},
"cloudstorage": {
"s3": {
"enabled": true
}
}
"cloudstorage": true
}
9 changes: 3 additions & 6 deletions tests/cypress/fixtures/session/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
"versions": [
{
"data": {
"anonymousSessionsEnabled": true,
"cloudstorageEnabled": {
"azure_blob": false,
"s3": true
},
"sshEnabled": true
"anonymous_sessions_enabled": true,
"cloudstorage_enabled": true,
"ssh_enabled": true
},
"version": "1.15.2"
}
Expand Down
9 changes: 3 additions & 6 deletions tests/cypress/fixtures/version-notebooks-s3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
"versions": [
{
"data": {
"anonymousSessionsEnabled": true,
"cloudstorageEnabled": {
"azure_blob": false,
"s3": true
},
"sshEnabled": false
"anonymous_sessions_enabled": true,
"cloudstorage_enabled": true,
"ssh_enabled": false
},
"version": "1.15.2"
}
Expand Down
9 changes: 3 additions & 6 deletions tests/cypress/fixtures/version-notebooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
"versions": [
{
"data": {
"anonymousSessionsEnabled": true,
"cloudstorageEnabled": {
"azure_blob": false,
"s3": false
},
"sshEnabled": false
"anonymous_sessions_enabled": true,
"cloudstorage_enabled": true,
"ssh_enabled": false
},
"version": "1.15.2"
}
Expand Down

0 comments on commit d7cfff0

Please sign in to comment.