Skip to content

Commit 09c7897

Browse files
committed
update launch link based on selection
1 parent ac0fcbb commit 09c7897

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

client/src/features/sessionsV2/SessionView/SessionLaunchLinkModal.tsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,17 @@ function EditEnvVariablesCustomizationFormContent({
229229
);
230230
}
231231

232+
type SessionLaunchLinkProps = Required<
233+
Pick<SessionLaunchLinkModalProps, "launcher" | "project">
234+
> &
235+
SessionLaunchLinkCustomizationProps;
236+
232237
function SessionLaunchLink({
238+
fields,
233239
launcher,
234240
project,
235-
}: Required<Pick<SessionLaunchLinkModalProps, "launcher" | "project">>) {
241+
watch,
242+
}: SessionLaunchLinkProps) {
236243
const startPath = generatePath(
237244
ABSOLUTE_ROUTES.v2.projects.show.sessions.start,
238245
{
@@ -243,8 +250,29 @@ function SessionLaunchLink({
243250
);
244251
const { params } = useContext(AppContext);
245252
const baseUrl = params?.BASE_URL ?? window.location.href;
246-
const url = new URL(startPath, baseUrl);
247-
const markdown = `[![launch - renku](${baseUrl}/renku-badge.svg)](${url.toString()})`;
253+
const customized = fields.map(
254+
(_f, i) => `envVariables.${i}.isCustomized`
255+
) as `envVariables.${number}.isCustomized`[];
256+
const values = fields.map(
257+
(_f, i) => `envVariables.${i}.value`
258+
) as `envVariables.${number}.value`[];
259+
const isCustomizedValues = watch(customized);
260+
const fieldValues = watch(values);
261+
262+
const urlWithParams = useMemo(() => {
263+
const url = new URL(startPath, baseUrl);
264+
const searchParams = new URLSearchParams();
265+
fields.forEach((field, i) => {
266+
if (isCustomizedValues[i]) {
267+
searchParams.append(field.name, fieldValues[i]);
268+
}
269+
});
270+
const urlWithParams = new URL(url.toString());
271+
urlWithParams.search = searchParams.toString();
272+
return urlWithParams;
273+
}, [baseUrl, fields, fieldValues, isCustomizedValues, startPath]);
274+
275+
const markdown = `[![launch - renku](${baseUrl}/renku-badge.svg)](${urlWithParams.toString()})`;
248276
return (
249277
<Row className="mb-2">
250278
<Col md={6}>
@@ -260,7 +288,7 @@ function SessionLaunchLink({
260288
"d-inline-block",
261289
"cursor-pointer"
262290
)}
263-
clipboardText={url.toString()}
291+
clipboardText={urlWithParams.toString()}
264292
>
265293
<span className="ms-2">Copy Launch Link</span>
266294
</Clipboard>
@@ -298,11 +326,11 @@ function SessionLaunchLinkCustomization({
298326
fields,
299327
watch,
300328
}: SessionLaunchLinkCustomizationProps) {
301-
const names = fields.map(
329+
const customized = fields.map(
302330
(_f, i) => `envVariables.${i}.isCustomized`
303331
) as `envVariables.${number}.isCustomized`[];
304-
const values = watch(names);
305-
const shownFields = fields.filter((_f, i) => values[i]);
332+
const isCustomizedValues = watch(customized);
333+
const shownFields = fields.filter((_f, i) => isCustomizedValues[i]);
306334
if (shownFields.length < 1) return null;
307335
return (
308336
<>
@@ -386,7 +414,12 @@ export default function SessionLaunchLinkModal({
386414
</div>
387415
</ModalHeader>
388416
<ModalBody>
389-
<SessionLaunchLink launcher={launcher} project={project} />
417+
<SessionLaunchLink
418+
fields={fields}
419+
launcher={launcher}
420+
project={project}
421+
watch={watch}
422+
/>
390423
<SessionLaunchLinkCustomization fields={fields} watch={watch} />
391424
<CustomizeLaunchLinkForm
392425
control={control}

0 commit comments

Comments
 (0)