Skip to content

Commit

Permalink
feat: Schedule services (#2357)
Browse files Browse the repository at this point in the history
* feat: Schedule services

* fixup! feat: Schedule services

* fixup! Merge branch 'main' into acasanov-schedule-services
  • Loading branch information
aleixhub authored Feb 6, 2025
1 parent f56d119 commit 26f9874
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
19 changes: 19 additions & 0 deletions catalog/ui/src/app/Catalog/CatalogItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
serviceNamespace: formState.serviceNamespace,
usePoolIfAvailable: formState.usePoolIfAvailable,
useAutoDetach: formState.useAutoDetach,
startDate: formState.startDate,
stopDate: formState.stopDate,
endDate: formState.endDate,
email,
Expand Down Expand Up @@ -663,6 +664,24 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
</FormGroup>
) : null}

{!formState.workshop && !catalogItem.spec.externalUrl ? (
<FormGroup fieldId="serviceStartDate" isRequired label="Start Date">
<div className="catalog-item-form__group-control--single">
<DateTimePicker
defaultTimestamp={Date.now()}
onSelect={(d: Date) =>
dispatchFormState({
type: 'initDates',
catalogItem,
startDate: d,
})
}
minDate={Date.now()}
/>
</div>
</FormGroup>
) : null}

{!isAutoStopDisabled(catalogItem) && !formState.workshop && !catalogItem.spec.externalUrl ? (
<FormGroup key="auto-stop" fieldId="auto-stop" label="Auto-stop">
<div className="catalog-item-form__group-control--single">
Expand Down
16 changes: 10 additions & 6 deletions catalog/ui/src/app/Catalog/CatalogItemFormReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,17 @@ export async function checkConditionsInFormState(
}
}

function initDates(catalogItem: CatalogItem) {
function initDates(catalogItem: CatalogItem, currTime?: number) {
let _currTime = Date.now();
if (currTime) {
_currTime = currTime;
}
return {
startDate: null,
startDate: currTime ? new Date(currTime) : null,
stopDate: isAutoStopDisabled(catalogItem)
? null
: new Date(Date.now() + parseDuration(catalogItem.spec.runtime?.default || '4h')),
endDate: new Date(Date.now() + parseDuration(catalogItem.spec.lifespan?.default || '2d')),
: new Date(_currTime + parseDuration(catalogItem.spec.runtime?.default || '4h')),
endDate: new Date(_currTime + parseDuration(catalogItem.spec.lifespan?.default || '2d')),
};
}

Expand Down Expand Up @@ -362,7 +366,7 @@ function reduceFormStateInit(
message: '',
},
sfdc_enabled,
...initDates(catalogItem),
...initDates(catalogItem, null),
};
}

Expand Down Expand Up @@ -546,7 +550,7 @@ export function reduceFormState(state: FormState, action: FormStateAction): Form
action.sfdc_enabled
);
case 'initDates':
return { ...state, ...initDates(action.catalogItem) };
return { ...state, ...initDates(action.catalogItem, action.startDate ? action.startDate.getTime() : null) };
case 'parameterUpdate':
return reduceFormStateParameterUpdate(state, {
name: action.parameter.name,
Expand Down
23 changes: 4 additions & 19 deletions catalog/ui/src/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ declare const window: Window &
sessionPromiseInstance?: Promise<Session>;
};

type CreateServiceRequestOptScheduleStart = {
date: Date;
};
interface CreateServiceRequestOptScheduleStartLifespan extends CreateServiceRequestOptScheduleStart {
type: 'lifespan';
}
interface CreateServiceRequestOptScheduleStartResource extends CreateServiceRequestOptScheduleStart {
type: 'resource';
autoStop: Date;
}
type CreateServiceRequestOpt = {
catalogItem: CatalogItem;
catalogNamespaceName: string;
Expand All @@ -59,7 +49,7 @@ type CreateServiceRequestOpt = {
usePoolIfAvailable: boolean;
stopDate?: Date;
endDate: Date;
start?: CreateServiceRequestOptScheduleStartLifespan | CreateServiceRequestOptScheduleStartResource;
startDate?: Date;
useAutoDetach: boolean;
email: string;
skippedSfdc: boolean;
Expand Down Expand Up @@ -400,7 +390,7 @@ export async function createServiceRequest({
isAdmin,
parameterValues,
serviceNamespace,
start,
startDate,
stopDate,
endDate,
usePoolIfAvailable,
Expand Down Expand Up @@ -452,16 +442,11 @@ export async function createServiceRequest({
name: catalogItem.metadata.name,
parameterValues: {
purpose: parameterValues.purpose as string,
...(start ? { start_timestamp: dateToApiString(start.date) } : {}),
...(start && start.type === 'resource' && start.autoStop
? { stop_timestamp: dateToApiString(start.autoStop) }
: stopDate
? { stop_timestamp: dateToApiString(stopDate) }
: {}),
...(stopDate ? { stop_timestamp: dateToApiString(stopDate) } : {}),
},
},
lifespan: {
...(start && start.type === 'lifespan' ? { start: dateToApiString(start.date) } : {}),
...(startDate ? { start: dateToApiString(startDate) } : {}),
end: dateToApiString(endDate),
},
...(useAutoDetach
Expand Down

0 comments on commit 26f9874

Please sign in to comment.