Skip to content

Commit

Permalink
fix: backend graphql API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Oct 24, 2024
1 parent fe16587 commit 19c272f
Show file tree
Hide file tree
Showing 60 changed files with 996 additions and 824 deletions.
845 changes: 521 additions & 324 deletions apps/admin-ui/gql/gql-types.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/admin-ui/src/common/fragments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const SPACE_FRAGMENT = gql`
fragment SpaceFields on SpaceNode {
...SpaceCommonFields
code
resourceSet {
resources {
...ResourceFields
}
children {
Expand Down Expand Up @@ -177,7 +177,7 @@ export const RESERVATIONUNIT_RESERVATIONS_FRAGMENT = gql`
name
numPersons
calendarUrl
reservationUnit {
reservationUnits {
id
pk
nameFi
Expand Down
4 changes: 2 additions & 2 deletions apps/admin-ui/src/common/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const UNIT_QUERY = gql`
nameFi
tprekId
shortDescriptionFi
reservationunitSet {
reservationUnits {
...ReservationUnitCommonFields
resources {
id
Expand Down Expand Up @@ -60,7 +60,7 @@ export const UNIT_WITH_SPACES_AND_RESOURCES = gql`
nameFi
spaces {
...SpaceCommonFields
resourceSet {
resources {
id
pk
nameFi
Expand Down
8 changes: 4 additions & 4 deletions apps/admin-ui/src/component/EditTimeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const CHANGE_RESERVATION_TIME_QUERY_FRAGMENT = gql`
beginDate
endDate
}
reservationUnit {
reservationUnits {
id
pk
bufferTimeBefore
Expand Down Expand Up @@ -316,7 +316,7 @@ export function NewReservationModal({

const { recurringReservation, type } = reservationToCopy ?? {};
const { pk: recurringReservationPk } = recurringReservation ?? {};
const reservationUnit = reservationToCopy?.reservationUnit?.[0];
const reservationUnit = reservationToCopy?.reservationUnits?.[0];

// NOTE 0 => buffer disabled for this reservation, undefined => no buffers selected
const bufferTimeBefore = reservationUnit?.bufferTimeBefore ?? 0;
Expand Down Expand Up @@ -455,7 +455,7 @@ export function EditTimeModal({
const startDateTime = new Date(reservation.begin);
const endDateTime = new Date(reservation.end);

const reservationUnit = reservation.reservationUnit?.find(() => true);
const reservationUnit = reservation.reservationUnits?.find(() => true);

// NOTE 0 => buffer disabled for this reservation, undefined => no buffers selected
const bufferTimeBefore =
Expand Down Expand Up @@ -525,7 +525,7 @@ export function EditTimeModal({
<ErrorBoundary fallback={<div>{t("errors.descriptive.unknown")}</div>}>
<DialogContent
form={form}
reservationUnitPk={reservation.reservationUnit?.[0]?.pk ?? 0}
reservationUnitPk={reservation.reservationUnits?.[0]?.pk ?? 0}
bufferTimeAfter={bufferTimeAfter}
bufferTimeBefore={bufferTimeBefore}
mutate={changeTime}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/component/RecurringReservationsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function RecurringReservationsView({
});

const { hasPermission } = useCheckPermission({
units: [reservationToCopy?.reservationUnit?.[0].unit?.pk ?? 0],
units: [reservationToCopy?.reservationUnits?.[0].unit?.pk ?? 0],
permission: UserPermissionChoice.CanManageReservations,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/component/ReservationTypeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Element } from "@/styles/util";
// TODO use a fragment
type ReservationType = NonNullable<ReservationQuery["reservation"]>;
type ReservationUnitType = Omit<
NonNullable<ReservationType["reservationUnit"]>[0],
NonNullable<ReservationType["reservationUnits"]>[0],
"pricings"
>;

Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/component/ReservationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function AddNewReservationButton({
refetch,
}: AddNewReservationButtonProps) {
const { hasPermission } = useCheckPermission({
units: [reservationToCopy?.reservationUnit?.[0].unit?.pk ?? 0],
units: [reservationToCopy?.reservationUnits?.[0].unit?.pk ?? 0],
permission: UserPermissionChoice.CanManageReservations,
});
const { t } = useTranslation();
Expand Down
4 changes: 2 additions & 2 deletions apps/admin-ui/src/component/VisibleIfPermission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useSession } from "@/hooks/auth";

type ReservationPermissionType = Pick<
ReservationUnitReservationsFragment,
"reservationUnit" | "user"
"reservationUnits" | "user"
>;

function VisibleIfPermission({
Expand All @@ -25,7 +25,7 @@ function VisibleIfPermission({
const { user } = useSession();
const isOwner = reservation.user?.pk === user?.pk;
const { hasPermission } = useCheckPermission({
units: [reservation?.reservationUnit?.[0]?.unit?.pk ?? 0],
units: [reservation?.reservationUnits?.[0]?.unit?.pk ?? 0],
permission,
});

Expand Down
4 changes: 1 addition & 3 deletions apps/admin-ui/src/hooks/useCheckCollisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export function useCheckCollisions({
) {
return reservation.affectedReservationUnits?.some((pk) => pk === resUnitPk);
}
const reservationSet = filterNonNullable(
data?.reservationUnit?.reservationSet
);
const reservationSet = filterNonNullable(data?.reservationUnit?.reservations);
// NOTE we could use a recular concat here (we only have single reservationUnit here)
const affectingReservations = filterNonNullable(data?.affectingReservations);
const reservations = filterNonNullable(
Expand Down
13 changes: 6 additions & 7 deletions apps/admin-ui/src/spa/ReservationUnit/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,13 @@ function BasicSection({
const { errors } = formState;
const { spaces } = unit ?? {};

const spaceOptions =
spaces?.map((s) => ({
label: String(s?.nameFi),
value: Number(s?.pk),
})) ?? [];
const spaceOptions = filterNonNullable(spaces).map((s) => ({
label: s?.nameFi ?? "-",
value: s?.pk ?? 0,
}));
const resourceOptions = filterNonNullable(
spaces?.flatMap((s) => s?.resourceSet)
).map((r) => ({ label: String(r?.nameFi), value: Number(r?.pk) }));
spaces?.flatMap((s) => s?.resources)
).map((r) => ({ label: r?.nameFi ?? "-", value: r?.pk ?? 0 }));

const spacePks = watch("spaces");
const selectedSpaces = filterNonNullable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ReservationPopupContent({
<DenseVerticalFlex>
<Heading>
{formatTime(reservation.begin)} - {formatTime(reservation.end)} /{" "}
{reservation.reservationUnit?.[0]?.nameFi}
{reservation.reservationUnits?.[0]?.nameFi ?? "-"}
</Heading>
<VisibleIfPermission
reservation={reservation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ReservationUnitType = NonNullable<
ReservationUnitCalendarQuery["reservationUnit"]
>;
type ReservationType = NonNullable<
NonNullable<ReservationUnitType["reservationSet"]>[0]
NonNullable<ReservationUnitType["reservations"]>[0]
>;

function getEventTitle({
Expand All @@ -56,7 +56,7 @@ function getEventTitle({
reservation: ReservationType;
t: TFunction;
}) {
const reservationUnit = reservation.reservationUnit?.[0];
const reservationUnit = reservation.reservationUnits?.[0];
const isOtherReservationUnit = reservationUnitPk !== reservationUnit?.pk;

const reserveeName = getReserveeName(reservation, t);
Expand Down Expand Up @@ -128,9 +128,7 @@ export function ReservationUnitCalendar({
return reservation.affectedReservationUnits?.some((pk) => pk === resUnitPk);
}

const reservationSet = filterNonNullable(
data?.reservationUnit?.reservationSet
);
const reservationSet = filterNonNullable(data?.reservationUnit?.reservations);
const affectingReservations = filterNonNullable(data?.affectingReservations);
const reservations = filterNonNullable(
reservationSet?.concat(
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/spa/my-units/[id]/UnitCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function getEventTitle({
return t("MyUnits.Calendar.legend.closed");
}

return event && event?.pk !== event?.reservationUnit?.[0]?.pk
return event && event?.pk !== event?.reservationUnits?.[0]?.pk
? getReserveeName(event, t)
: title;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/spa/my-units/[id]/eventStyleGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const eventStyleGetter =
style: React.CSSProperties;
className?: string;
} => {
const isCurrentReservationUnit = !!event?.reservationUnit?.find(
const isCurrentReservationUnit = !!event?.reservationUnits?.find(
(ru) => ru?.pk === currentReservationUnitPk
);

Expand Down
4 changes: 2 additions & 2 deletions apps/admin-ui/src/spa/my-units/[id]/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useUnitResources(
});

const { affectingReservations } = data ?? {};
const reservationunitSet = filterNonNullable(data?.unit?.reservationunitSet);
const reservationunitSet = filterNonNullable(data?.unit?.reservationUnits);

type ReservationType = NonNullable<typeof affectingReservations>[0];
type ReservationUnitType = NonNullable<typeof reservationunitSet>[0];
Expand Down Expand Up @@ -66,7 +66,7 @@ export function useUnitResources(
const affecting = affectingReservations?.filter((y) =>
doesReservationAffectReservationUnit(y, x.pk ?? 0)
);
const _events = x.reservationSet?.concat(affecting ?? []);
const _events = x.reservations?.concat(affecting ?? []);
const events = filterNonNullable(_events);

return {
Expand Down
10 changes: 3 additions & 7 deletions apps/admin-ui/src/spa/my-units/[id]/hooks/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const UNIT_VIEW_QUERY = gql`
location {
...LocationFields
}
reservationunitSet {
reservationUnits {
id
pk
nameFi
Expand All @@ -72,7 +72,7 @@ export const RESERVATION_UNITS_BY_UNIT = gql`
) {
unit(id: $id) {
id
reservationunitSet {
reservationUnits {
id
pk
nameFi
Expand All @@ -88,11 +88,7 @@ export const RESERVATION_UNITS_BY_UNIT = gql`
bufferTimeAfter
isDraft
authentication
reservationSet(
beginDate: $beginDate
endDate: $endDate
state: $state
) {
reservations(beginDate: $beginDate, endDate: $endDate, state: $state) {
...ReservationUnitReservations
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/admin-ui/src/spa/my-units/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export function MyUnitView() {
const recurringReservationUrl = getRecurringReservationUrl(pk);

const reservationUnitOptions = filterNonNullable(
data?.unit?.reservationunitSet
data?.unit?.reservationUnits
).map((reservationUnit) => ({
label: reservationUnit?.nameFi ?? "",
label: reservationUnit?.nameFi ?? "-",
value: reservationUnit?.pk ?? 0,
}));

Expand Down
4 changes: 2 additions & 2 deletions apps/admin-ui/src/spa/my-units/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const RECURRING_RESERVATION_UNIT_QUERY = gql`
id
nameFi
pk
reservationunitSet {
reservationUnits {
id
pk
nameFi
Expand All @@ -33,7 +33,7 @@ export const RESERVATION_UNIT_CALENDAR_QUERY = gql`
reservationUnit(id: $id) {
id
pk
reservationSet(state: $state, beginDate: $beginDate, endDate: $endDate) {
reservations(state: $state, beginDate: $beginDate, endDate: $endDate) {
...ReservationUnitReservations
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
YEAR,
mocks,
mondayMorningReservations,
units,
createUnits,
} from "./__test__/mocks";

function customRender() {
return render(
<MemoryRouter>
<MockedProvider mocks={mocks} addTypename={false}>
<RecurringReservationForm reservationUnits={units} />
<RecurringReservationForm reservationUnits={createUnits()} />
</MockedProvider>
</MemoryRouter>
);
Expand Down Expand Up @@ -60,6 +60,7 @@ test("Render recurring reservation form with all but unit field disabled", async
selector: "ul",
});

const units = createUnits();
expect(units[0].nameFi).toBeDefined();
expect(units[1].nameFi).toBeDefined();
expect(listbox).toBeInTheDocument();
Expand Down Expand Up @@ -106,6 +107,7 @@ async function selectUnit() {
const listbox = screen.getByLabelText(/reservationUnit/, {
selector: "ul",
});
const units = createUnits();
expect(units[0].nameFi).toBeDefined();
const unitName = units[0].nameFi!;

Expand Down Expand Up @@ -216,7 +218,6 @@ async function fillForm({
const listbox = screen.getByLabelText(/reservationUnit/, {
selector: "ul",
});
expect(units[0].nameFi).toBeDefined();

// Select works for HDS listbox but
// to check the selected value we have to read the button text not check options
Expand Down
Loading

0 comments on commit 19c272f

Please sign in to comment.