Skip to content

Commit

Permalink
fix: Scheduled annotation (#2270)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixhub authored Nov 19, 2024
1 parent 61a7cc1 commit 1cfdd4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 4 additions & 5 deletions catalog/ui/src/app/Admin/WorkshopsScheduled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import ExclamationTriangleIcon from '@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon';
import { apiPaths, fetcherItemsInAllPages } from '@app/api';
import { Workshop } from '@app/types';
import { compareK8sObjectsArr, FETCH_BATCH_LIMIT } from '@app/util';
import { compareK8sObjectsArr, DEMO_DOMAIN, FETCH_BATCH_LIMIT } from '@app/util';
import Footer from '@app/components/Footer';
import ProjectSelector from '@app/components/ProjectSelector';
import { Calendar, momentLocalizer } from 'react-big-calendar';
Expand Down Expand Up @@ -54,9 +54,8 @@ const eventMapper = (workshop: Workshop): TEvent => {
};
};

const filterOutRunningWorkshops = (ev: TEvent) => {
if (ev.start > new Date()) return true;
return false;
const filterOutNonScheduled = (w: Workshop) => {
return (w.metadata.annotations[`${DEMO_DOMAIN}/scheduled`] === 'true')
};

const eventStyleGetter = (event: TEvent, start: Date, end: Date) => {
Expand Down Expand Up @@ -122,7 +121,7 @@ const WorkshopsScheduled: React.FC<{}> = () => {
<p style={{ padding: '16px 0' }}>Showing only upcoming scheduled workshops.</p>
<Calendar
localizer={localizer}
events={workshops.map(eventMapper).filter(Boolean).filter(filterOutRunningWorkshops)}
events={workshops.filter(filterOutNonScheduled).map(eventMapper).filter(Boolean)}
startAccessor="start"
endAccessor="end"
style={{ height: 700 }}
Expand Down
5 changes: 1 addition & 4 deletions catalog/ui/src/app/Catalog/CatalogItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ const CatalogItemFormData: React.FC<{ catalogItemName: string; catalogNamespaceN
serviceNamespace: formState.serviceNamespace,
stopDate: formState.stopDate,
endDate: formState.endDate,
startDate:
formState.startDate.getTime() > Date.now() + parseDuration('6h')
? new Date(formState.startDate.getTime() - parseDuration('6h'))
: new Date(),
startDate: new Date(formState.startDate.getTime() - parseDuration('6h')),
email,
parameterValues,
skippedSfdc: formState.salesforceId.skip,
Expand Down
2 changes: 1 addition & 1 deletion catalog/ui/src/app/Catalog/CatalogItemFormReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ function reduceFormStateDates(initialState: FormState, _startDate: Date, _stopDa
...initialState,
stopDate,
endDate,
startDate: _startDate,
startDate,
};
}
return {
Expand Down
3 changes: 2 additions & 1 deletion catalog/ui/src/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ export async function createWorkshop({
: catalogItem.spec.messageTemplates?.info
? { [`${DEMO_DOMAIN}/info-message-template`]: JSON.stringify(catalogItem.spec.messageTemplates?.info) }
: {}),
[`${DEMO_DOMAIN}/scheduled`]: startDate ? 'true' : 'false',
[`${DEMO_DOMAIN}/scheduled`]:
startDate && startDate.getTime() + parseDuration('6h') > Date.now() ? 'true' : 'false',
[`${DEMO_DOMAIN}/requester`]: serviceNamespace.requester || email,
[`${DEMO_DOMAIN}/orderedBy`]: session.user,
},
Expand Down

0 comments on commit 1cfdd4c

Please sign in to comment.