Skip to content

Commit 4182b04

Browse files
authored
fix: update session environment UI to allow resetting args and command (#3888)
Update the UI to allow resetting `args` and `command` for sessions.
1 parent 499b644 commit 4182b04

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

client/src/features/admin/UpdateSessionEnvironmentButton.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,10 @@ function UpdateSessionEnvironmentModal({
116116
uid: data.uid ?? undefined,
117117
working_directory: data.working_directory?.trim() || undefined,
118118
strip_path_prefix: data.strip_path_prefix,
119-
// TODO: The API spec needs to be fixed to describe value resets here
120-
// TODO: See https://github.com/SwissDataScienceCenter/renku-data-services/issues/985
121119
...(commandParsed.data
122120
? { command: commandParsed.data }
123-
: ({ command: null } as any)), // eslint-disable-line @typescript-eslint/no-explicit-any
124-
...(argsParsed.data
125-
? { args: argsParsed.data }
126-
: ({ args: null } as any)), // eslint-disable-line @typescript-eslint/no-explicit-any
121+
: { command: null }),
122+
...(argsParsed.data ? { args: argsParsed.data } : { args: null }),
127123
},
128124
});
129125
},

client/src/features/sessionsV2/api/sessionLaunchersV2.generated-api.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ export type EnvironmentPost = {
290290
};
291291
export type EnvironmentWorkingDirectoryPatch = string;
292292
export type EnvironmentMountDirectoryPatch = string;
293+
export type EnvironmentPatchCommand = string[] | null;
294+
export type EnvironmentPatchArgs = string[] | null;
295+
export type IsArchivedPatch = boolean;
296+
export type StripPathPrefixPatch = boolean;
293297
export type EnvironmentPatch = {
294298
name?: SessionName;
295299
description?: Description;
@@ -300,10 +304,10 @@ export type EnvironmentPatch = {
300304
working_directory?: EnvironmentWorkingDirectoryPatch;
301305
mount_directory?: EnvironmentMountDirectoryPatch;
302306
port?: EnvironmentPort;
303-
command?: EnvironmentCommand;
304-
args?: EnvironmentArgs;
305-
is_archived?: IsArchived;
306-
strip_path_prefix?: StripPathPrefix;
307+
command?: EnvironmentPatchCommand;
308+
args?: EnvironmentPatchArgs;
309+
is_archived?: IsArchivedPatch;
310+
strip_path_prefix?: StripPathPrefixPatch;
307311
};
308312
export type EnvironmentKind = "GLOBAL" | "CUSTOM";
309313
export type EnvironmentWithImageGet = Environment & {

client/src/features/sessionsV2/api/sessionLaunchersV2.openapi.json

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@
655655
"$ref": "#/components/schemas/EnvironmentKind"
656656
}
657657
],
658-
"default": "custom"
658+
"default": "CUSTOM"
659659
}
660660
},
661661
"required": ["environment_image_source", "environment_kind"]
@@ -685,7 +685,7 @@
685685
"$ref": "#/components/schemas/EnvironmentKind"
686686
}
687687
],
688-
"default": "custom"
688+
"default": "CUSTOM"
689689
}
690690
},
691691
"required": [
@@ -855,16 +855,16 @@
855855
"$ref": "#/components/schemas/EnvironmentPort"
856856
},
857857
"command": {
858-
"$ref": "#/components/schemas/EnvironmentCommand"
858+
"$ref": "#/components/schemas/EnvironmentPatchCommand"
859859
},
860860
"args": {
861-
"$ref": "#/components/schemas/EnvironmentArgs"
861+
"$ref": "#/components/schemas/EnvironmentPatchArgs"
862862
},
863863
"is_archived": {
864-
"$ref": "#/components/schemas/IsArchived"
864+
"$ref": "#/components/schemas/IsArchivedPatch"
865865
},
866866
"strip_path_prefix": {
867-
"$ref": "#/components/schemas/StripPathPrefix"
867+
"$ref": "#/components/schemas/StripPathPrefixPatch"
868868
}
869869
}
870870
},
@@ -1242,6 +1242,15 @@
12421242
"description": "The command that will be run i.e. will overwrite the image Dockerfile ENTRYPOINT, equivalent to command in Kubernetes",
12431243
"minItems": 1
12441244
},
1245+
"EnvironmentPatchCommand": {
1246+
"type": "array",
1247+
"description": "The command that will be run i.e. will overwrite the image Dockerfile ENTRYPOINT, equivalent to command in Kubernetes",
1248+
"items": {
1249+
"type": "string"
1250+
},
1251+
"nullable": true,
1252+
"minItems": 1
1253+
},
12451254
"EnvironmentArgs": {
12461255
"type": "array",
12471256
"items": {
@@ -1250,11 +1259,24 @@
12501259
"description": "The arguments that will follow the command, i.e. will overwrite the image Dockerfile CMD, equivalent to args in Kubernetes",
12511260
"minItems": 1
12521261
},
1262+
"EnvironmentPatchArgs": {
1263+
"type": "array",
1264+
"description": "The arguments that will follow the command, i.e. will overwrite the image Dockerfile CMD, equivalent to args in Kubernetes",
1265+
"items": {
1266+
"type": "string"
1267+
},
1268+
"nullable": true,
1269+
"minItems": 1
1270+
},
12531271
"IsArchived": {
12541272
"type": "boolean",
12551273
"description": "Whether this environment is archived and not for use in new projects or not",
12561274
"default": false
12571275
},
1276+
"IsArchivedPatch": {
1277+
"type": "boolean",
1278+
"description": "Whether this environment is archived and not for use in new projects or not"
1279+
},
12581280
"Build": {
12591281
"description": "A container image build",
12601282
"type": "object",
@@ -1332,6 +1354,10 @@
13321354
"default": false,
13331355
"description": "If set to true the default url and the base path where sessions are\nserved will be removed from all URL paths before the requests reach\nthe server running in the session. So the server in the session will\nreceive HTTP requests whose base path will be \"/\". However this will\nnot work unless the server running inside the session can be made\naware that paths are rewritten. For example, if the application/server\nrunning in the session serves a HTML page that then loads javascript\nand CSS, the path where these assets should be loaded from in the browser\nwill not be \"/\" but it has to include the prefix that was stripped. And\nthe server from the session that generated the HTML page needs to know\nwhat is the full base path (including the part that was stripped) so that\nit can make the URLs to such assets be reachable from the browser."
13341356
},
1357+
"StripPathPrefixPatch": {
1358+
"type": "boolean",
1359+
"description": "If set to true the default url and the base path where sessions are\nserved will be removed from all URL paths before the requests reach\nthe server running in the session. So the server in the session will\nreceive HTTP requests whose base path will be \"/\". However this will\nnot work unless the server running inside the session can be made\naware that paths are rewritten. For example, if the application/server\nrunning in the session serves a HTML page that then loads javascript\nand CSS, the path where these assets should be loaded from in the browser\nwill not be \"/\" but it has to include the prefix that was stripped. And\nthe server from the session that generated the HTML page needs to know\nwhat is the full base path (including the part that was stripped) so that\nit can make the URLs to such assets be reachable from the browser."
1360+
},
13351361
"BuildPatch": {
13361362
"description": "The requested update of a container image build",
13371363
"type": "object",

client/src/features/sessionsV2/session.utils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,23 @@ export function getFormattedEnvironmentValuesForEdit(
180180
environmentSelect === "global" ||
181181
environmentSelect === "custom + image"
182182
) {
183-
return getFormattedEnvironmentValues(data);
183+
const result = getFormattedEnvironmentValues(data);
184+
if (!result.success) {
185+
return result;
186+
}
187+
const { data: environment } = result;
188+
const commandParsed = safeParseJSONStringArray(data.command);
189+
const argsParsed = safeParseJSONStringArray(data.args);
190+
return {
191+
...result,
192+
data: {
193+
...environment,
194+
...(commandParsed.data
195+
? { command: commandParsed.data }
196+
: { command: null }),
197+
...(argsParsed.data ? { args: argsParsed.data } : { args: null }),
198+
},
199+
};
184200
}
185201

186202
const {

0 commit comments

Comments
 (0)