Skip to content

Commit

Permalink
fix: search filters use the non paged endpoints, options sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
vincit-matu committed Dec 17, 2024
1 parent 29f9b3d commit 782431a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 89 deletions.
127 changes: 80 additions & 47 deletions apps/ui/gql/gql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2416,8 +2416,12 @@ export type QueryUnitsAllArgs = {
nameSv?: InputMaybe<Scalars["String"]["input"]>;
nameSv_Icontains?: InputMaybe<Scalars["String"]["input"]>;
nameSv_Istartswith?: InputMaybe<Scalars["String"]["input"]>;
onlyDirectBookable?: InputMaybe<Scalars["Boolean"]["input"]>;
onlySeasonalBookable?: InputMaybe<Scalars["Boolean"]["input"]>;
onlyWithPermission?: InputMaybe<Scalars["Boolean"]["input"]>;
orderBy?: InputMaybe<Array<InputMaybe<UnitOrderingChoices>>>;
ownReservations?: InputMaybe<Scalars["Boolean"]["input"]>;
publishedReservationUnits?: InputMaybe<Scalars["Boolean"]["input"]>;
unit?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
};

Expand Down Expand Up @@ -5317,7 +5321,27 @@ export type ReservationInfoCardFragment = {
}>;
};

export type OptionsQueryVariables = Exact<{ [key: string]: never }>;
export type OptionsQueryVariables = Exact<{
reservationUnitTypesOrderBy?: InputMaybe<
| Array<InputMaybe<ReservationUnitTypeOrderingChoices>>
| InputMaybe<ReservationUnitTypeOrderingChoices>
>;
purposesOrderBy?: InputMaybe<
| Array<InputMaybe<PurposeOrderingChoices>>
| InputMaybe<PurposeOrderingChoices>
>;
unitsOrderBy?: InputMaybe<
Array<InputMaybe<UnitOrderingChoices>> | InputMaybe<UnitOrderingChoices>
>;
equipmentsOrderBy?: InputMaybe<
| Array<InputMaybe<EquipmentOrderingChoices>>
| InputMaybe<EquipmentOrderingChoices>
>;
reservationPurposesOrderBy?: InputMaybe<
| Array<InputMaybe<ReservationPurposeOrderingChoices>>
| InputMaybe<ReservationPurposeOrderingChoices>
>;
}>;

export type OptionsQuery = {
reservationUnitTypes?: {
Expand Down Expand Up @@ -5374,17 +5398,20 @@ export type OptionsQuery = {
} | null;
} | null>;
} | null;
equipments?: {
edges: Array<{
node?: {
id: string;
pk?: number | null;
nameFi?: string | null;
nameEn?: string | null;
nameSv?: string | null;
} | null;
} | null>;
} | null;
equipmentsAll?: Array<{
id: string;
pk?: number | null;
nameFi?: string | null;
nameEn?: string | null;
nameSv?: string | null;
}> | null;
unitsAll?: Array<{
id: string;
pk?: number | null;
nameFi?: string | null;
nameSv?: string | null;
nameEn?: string | null;
}> | null;
};

export type ApplicationSectionReservationFragment = {
Expand Down Expand Up @@ -5991,17 +6018,13 @@ export type SearchFormParamsUnitQueryVariables = Exact<{
}>;

export type SearchFormParamsUnitQuery = {
units?: {
edges: Array<{
node?: {
id: string;
pk?: number | null;
nameFi?: string | null;
nameEn?: string | null;
nameSv?: string | null;
} | null;
} | null>;
} | null;
unitsAll?: Array<{
id: string;
pk?: number | null;
nameFi?: string | null;
nameEn?: string | null;
nameSv?: string | null;
}> | null;
};

export type ReservationUnitPurposesQueryVariables = Exact<{
Expand Down Expand Up @@ -8650,8 +8673,14 @@ export const BannerNotificationCommonFragmentDoc = gql`
}
`;
export const OptionsDocument = gql`
query Options {
reservationUnitTypes {
query Options(
$reservationUnitTypesOrderBy: [ReservationUnitTypeOrderingChoices]
$purposesOrderBy: [PurposeOrderingChoices]
$unitsOrderBy: [UnitOrderingChoices]
$equipmentsOrderBy: [EquipmentOrderingChoices]
$reservationPurposesOrderBy: [ReservationPurposeOrderingChoices]
) {
reservationUnitTypes(orderBy: $reservationUnitTypesOrderBy) {
edges {
node {
id
Expand All @@ -8662,7 +8691,7 @@ export const OptionsDocument = gql`
}
}
}
purposes {
purposes(orderBy: $purposesOrderBy) {
edges {
node {
id
Expand All @@ -8673,7 +8702,7 @@ export const OptionsDocument = gql`
}
}
}
reservationPurposes {
reservationPurposes(orderBy: $reservationPurposesOrderBy) {
edges {
node {
id
Expand Down Expand Up @@ -8705,16 +8734,19 @@ export const OptionsDocument = gql`
}
}
}
equipments {
edges {
node {
id
pk
nameFi
nameEn
nameSv
}
}
equipmentsAll(orderBy: $equipmentsOrderBy) {
id
pk
nameFi
nameEn
nameSv
}
unitsAll(orderBy: $unitsOrderBy) {
id
pk
nameFi
nameSv
nameEn
}
}
`;
Expand All @@ -8731,6 +8763,11 @@ export const OptionsDocument = gql`
* @example
* const { data, loading, error } = useOptionsQuery({
* variables: {
* reservationUnitTypesOrderBy: // value for 'reservationUnitTypesOrderBy'
* purposesOrderBy: // value for 'purposesOrderBy'
* unitsOrderBy: // value for 'unitsOrderBy'
* equipmentsOrderBy: // value for 'equipmentsOrderBy'
* reservationPurposesOrderBy: // value for 'reservationPurposesOrderBy'
* },
* });
*/
Expand Down Expand Up @@ -9443,22 +9480,18 @@ export const SearchFormParamsUnitDocument = gql`
$onlySeasonalBookable: Boolean
$orderBy: [UnitOrderingChoices]
) {
units(
unitsAll(
publishedReservationUnits: $publishedReservationUnits
ownReservations: $ownReservations
onlyDirectBookable: $onlyDirectBookable
onlySeasonalBookable: $onlySeasonalBookable
orderBy: $orderBy
) {
edges {
node {
id
pk
nameFi
nameEn
nameSv
}
}
id
pk
nameFi
nameEn
nameSv
}
}
`;
Expand Down
66 changes: 43 additions & 23 deletions apps/ui/hooks/useOptions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { gql } from "@apollo/client";
import { useTranslation } from "next-i18next";
import { type Maybe, useOptionsQuery, type OptionsQuery } from "@gql/gql-types";
import {
type Maybe,
type OptionsQuery,
ReservationPurposeOrderingChoices,
ReservationUnitTypeOrderingChoices,
useOptionsQuery,
} from "@gql/gql-types";
import { participantCountOptions } from "@/modules/const";
import { filterNonNullable, getLocalizationLang } from "common/src/helpers";
import { getParameterLabel } from "@/modules/util";

// There is a duplicate in admin-ui but it doesn't have translations
// export so we can use this on SSR
export const OPTIONS_QUERY = gql`
query Options {
reservationUnitTypes {
query Options(
$reservationUnitTypesOrderBy: [ReservationUnitTypeOrderingChoices]
$purposesOrderBy: [PurposeOrderingChoices]
$unitsOrderBy: [UnitOrderingChoices]
$equipmentsOrderBy: [EquipmentOrderingChoices]
$reservationPurposesOrderBy: [ReservationPurposeOrderingChoices]
) {
reservationUnitTypes(orderBy: $reservationUnitTypesOrderBy) {
edges {
node {
id
Expand All @@ -20,7 +32,7 @@ export const OPTIONS_QUERY = gql`
}
}
}
purposes {
purposes(orderBy: $purposesOrderBy) {
edges {
node {
id
Expand All @@ -31,7 +43,7 @@ export const OPTIONS_QUERY = gql`
}
}
}
reservationPurposes {
reservationPurposes(orderBy: $reservationPurposesOrderBy) {
edges {
node {
id
Expand Down Expand Up @@ -63,16 +75,19 @@ export const OPTIONS_QUERY = gql`
}
}
}
equipments {
edges {
node {
id
pk
nameFi
nameEn
nameSv
}
}
equipmentsAll(orderBy: $equipmentsOrderBy) {
id
pk
nameFi
nameEn
nameSv
}
unitsAll(orderBy: $unitsOrderBy) {
id
pk
nameFi
nameSv
nameEn
}
}
`;
Expand Down Expand Up @@ -124,7 +139,12 @@ function sortAgeGroups(ageGroups: AgeGroup[]): AgeGroup[] {
export function useOptions() {
const { i18n } = useTranslation();

const { data, loading: isLoading } = useOptionsQuery();
const { data, loading: isLoading } = useOptionsQuery({
variables: {
reservationUnitTypesOrderBy: ReservationUnitTypeOrderingChoices.RankAsc,
reservationPurposesOrderBy: ReservationPurposeOrderingChoices.RankAsc,
},
});
const ageGroups = filterNonNullable(
data?.ageGroups?.edges?.map((edge) => edge?.node)
);
Expand All @@ -138,13 +158,6 @@ export function useOptions() {
data?.reservationPurposes?.edges?.map((edge) => edge?.node)
);

const params = {
ageGroups,
cities,
reservationUnitTypes,
purposes,
};

const lang = getLocalizationLang(i18n.language);
const ageGroupOptions = filterNonNullable(sortAgeGroups(ageGroups)).map(
(v) => ({
Expand Down Expand Up @@ -180,5 +193,12 @@ export function useOptions() {
participantCountOptions,
};

const params = {
ageGroups,
cities,
reservationUnitTypes,
purposes,
};

return { isLoading, options, params };
}
16 changes: 6 additions & 10 deletions apps/ui/modules/queries/params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ export const SEARCH_FORM_PARAMS_UNIT = gql`
$onlySeasonalBookable: Boolean
$orderBy: [UnitOrderingChoices]
) {
units(
unitsAll(
publishedReservationUnits: $publishedReservationUnits
ownReservations: $ownReservations
onlyDirectBookable: $onlyDirectBookable
onlySeasonalBookable: $onlySeasonalBookable
orderBy: $orderBy
) {
edges {
node {
id
pk
nameFi
nameEn
nameSv
}
}
id
pk
nameFi
nameEn
nameSv
}
}
`;
Expand Down
Loading

0 comments on commit 782431a

Please sign in to comment.