Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Feature/op 81/query param filters" #368

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"private": true,
"description": "skeleton-pip",
"author": "Conduction",
"keywords": [
"gatsby"
],
"keywords": ["gatsby"],
"scripts": {
"develop": "gatsby develop",
"start": "gatsby develop",
Expand Down
4 changes: 2 additions & 2 deletions pwa/src/apiService/resources/applications.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Send } from "../apiService";
import { AxiosInstance } from "axios";
import { IFiltersContext } from "../../context/filters";
import { IFilters } from "../../context/filters";

export default class Applications {
private _instance: AxiosInstance;
Expand All @@ -15,7 +15,7 @@ export default class Applications {
return data;
};

public getAll = async (filters: IFiltersContext): Promise<any> => {
public getAll = async (filters: IFilters): Promise<any> => {
const { data } = await Send(
this._instance,
"GET",
Expand Down
6 changes: 3 additions & 3 deletions pwa/src/apiService/resources/components.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Send } from "../apiService";
import { AxiosInstance } from "axios";
import { IFiltersContext } from "../../context/filters";
import { IFilters } from "../../context/filters";
import { filtersToQueryParams } from "../../services/filtersToQueryParams";

export default class Component {
Expand All @@ -16,7 +16,7 @@ export default class Component {
return data;
};

public getAll = async (filters: IFiltersContext): Promise<any> => {
public getAll = async (filters: IFilters): Promise<any> => {
const { data } = await Send(
this._instance,
"GET",
Expand All @@ -26,7 +26,7 @@ export default class Component {
return data;
};

public getCount = async (filters: IFiltersContext): Promise<any> => {
public getCount = async (filters: IFilters): Promise<any> => {
const { data } = await Send(this._instance, "GET", `/components?limit=1${filtersToQueryParams(filters)}`);

return data.total;
Expand Down
6 changes: 3 additions & 3 deletions pwa/src/apiService/resources/organization.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Send } from "../apiService";
import { AxiosInstance } from "axios";
import { IFiltersContext } from "../../context/filters";
import { IFilters } from "../../context/filters";
import { filtersToQueryParams } from "../../services/filtersToQueryParams";

export default class Organization {
Expand All @@ -16,7 +16,7 @@ export default class Organization {
return data;
};

public getAll = async (filters: IFiltersContext): Promise<any> => {
public getAll = async (filters: IFilters): Promise<any> => {
let url = `/organizations?page=${filters.organizationCurrentPage}&order[owns]=desc&limit=10&extend[]=all`;

if (filters.organizationSearch) {
Expand All @@ -34,7 +34,7 @@ export default class Organization {
return data;
};

public getCount = async (filters: IFiltersContext): Promise<any> => {
public getCount = async (filters: IFilters): Promise<any> => {
const { data } = await Send(this._instance, "GET", `/organizations?limit=1${filtersToQueryParams(filters)}`);

return data.total;
Expand Down
8 changes: 4 additions & 4 deletions pwa/src/apiService/resources/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Send } from "../apiService";
import { AxiosInstance } from "axios";
import { IFiltersContext } from "../../context/filters";
import { IFilters } from "../../context/filters";
import { filtersToQueryParams } from "../../services/filtersToQueryParams";

export default class Search {
Expand All @@ -10,16 +10,16 @@ export default class Search {
this._instance = _instance;
}

public getSearch = async (filters: IFiltersContext): Promise<any> => {
public getSearch = async (filters: IFilters): Promise<any> => {
let endpoint = `/search?page=${
filters.currentPage
}&order[_self.dateCreated]=desc&limit=10&extend[]=all${filtersToQueryParams(filters)}`;

if (process.env.GATSBY_GITHUB_ORGANIZATION_URL) {
endpoint += `&embedded.url.embedded.organisation.github=${process.env.GATSBY_GITHUB_ORGANIZATION_URL}`;
endpoint += `&legal.repoOwner.github=${process.env.GATSBY_GITHUB_ORGANIZATION_URL}`;
}

if (filters.isForked === true) {
if (filters.isForked) {
endpoint += `&isBasedOn=IS NULL`;
}

Expand Down
4 changes: 2 additions & 2 deletions pwa/src/components/breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from "lodash";
import { Container } from "@conduction/components";
import { isHomepage } from "../../services/isHomepage";
import { BreadcrumbNav, BreadcrumbNavLink, BreadcrumbNavSeparator, Icon } from "@utrecht/component-library-react";
import { useGatsbyContext } from "../../context/gatsby";
import { GatsbyContext } from "../../context/gatsby";
import { navigate } from "gatsby";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
Expand All @@ -18,7 +18,7 @@ export const Breadcrumbs: React.FC = () => {
breadcrumb: { crumbs },
},
location: { pathname },
} = useGatsbyContext();
} = React.useContext(GatsbyContext);

const githubLabel = () => {
const stringLabelfull = location.pathname.split("/github/")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import * as styles from "./ResultsDisplaySwitch.module.css";
import { Button, ButtonGroup } from "@utrecht/component-library-react/dist/css-module";
import { useTranslation } from "react-i18next";
import { useFiltersContext } from "../../context/filters";
import { FiltersContext } from "../../context/filters";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleNodes, faGripVertical, faLayerGroup, faTable } from "@fortawesome/free-solid-svg-icons";
import clsx from "clsx";
Expand All @@ -26,7 +26,7 @@ interface ResultsDisplaySwitchProps {

const ResultsDisplaySwitch: React.FC<ResultsDisplaySwitchProps> = ({ layoutClassName, resultsDisplayType }) => {
const { t } = useTranslation();
const { filters, setFilters } = useFiltersContext();
const [filters, setFilters] = React.useContext(FiltersContext);

const acceptedFilters: AcceptedFilters = {
resultDisplayLayout: ["table", "cards", "layer"],
Expand Down
27 changes: 6 additions & 21 deletions pwa/src/context/filters.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import * as React from "react";
import { GlobalContext } from "./global";
import { getParsedParamsFromSearch } from "../services/getParsedParamsFromSearch";
import { navigate } from "gatsby";
import { filtersToUrlQueryParams } from "../services/filtersToQueryParams";

export type TComponentResultsLayout = "table" | "cards" | "layer";
export type TComponentDependenciesLayout = "layer" | "relations";
export type TLandingDisplayLayout = "layer" | "cards";
export type TCatagoryDisplayLayout = "table" | "cards" | "layer";
export type TOrganizationsResultDisplayLayout = "table" | "cards";

export interface IFiltersContext {
export interface IFilters {
resultDisplayLayout: TComponentResultsLayout;
dependenciesDisplayLayout: TComponentDependenciesLayout;
landingDisplayLayout: TLandingDisplayLayout;
Expand All @@ -32,7 +28,7 @@ export interface IFiltersContext {
"embedded.nl.embedded.gemma.bedrijfsfuncties"?: string[];
"embedded.nl.embedded.gemma.bedrijfsservices"?: string[];
"embedded.nl.embedded.gemma.referentieComponenten"?: string[];
"embedded.nl.embedded.gemma.applicatiefunctie"?: string;
"embedded.nl.embedded.gemma.applicatiefunctie": string;
"embedded.nl.embedded.upl"?: string[];
"embedded.maintenance.type"?: string;
"embedded.legal.license"?: string;
Expand All @@ -43,7 +39,7 @@ export interface IFiltersContext {
showMoreSupport?: boolean;
}

export const defaultFiltersContext: IFiltersContext = {
export const baseFilters = {
resultDisplayLayout: "table",
dependenciesDisplayLayout: "layer",
landingDisplayLayout: "cards",
Expand All @@ -56,19 +52,8 @@ export const defaultFiltersContext: IFiltersContext = {
organizationSearch: "",
isForked: true,
developmentStatus: "hideObsolete",
};
} as IFilters;

export const useFiltersContext = () => {
const [globalContext, setGlobalContext] = React.useContext(GlobalContext);
export const FiltersContext = React.createContext<[IFilters, (_: IFilters) => void]>([baseFilters, () => null]);

const filters: IFiltersContext = globalContext.filters;

const setFilters = (newFilters: IFiltersContext) => {
setGlobalContext((oldGlobalContext) => ({
...oldGlobalContext,
filters: newFilters,
}));
};

return { setFilters, filters };
};
export const FiltersProvider = FiltersContext.Provider;
13 changes: 3 additions & 10 deletions pwa/src/context/gatsby.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from "react";
import { GlobalContext } from "./global";

export type TScreenSize = "mobile" | "tablet" | "desktop";

Expand All @@ -9,16 +8,10 @@ export interface IGatsbyContext {
screenSize: TScreenSize;
}

export const defaultGatsbyContext: IGatsbyContext = {
export const GatsbyContext = React.createContext<IGatsbyContext>({
pageContext: null,
location: null,
screenSize: "mobile",
};
});

export const useGatsbyContext = () => {
const [globalContext] = React.useContext(GlobalContext);

const gatsbyContext: IGatsbyContext = globalContext.gatsby;

return gatsbyContext;
};
export const GatsbyProvider = GatsbyContext.Provider;
21 changes: 0 additions & 21 deletions pwa/src/context/global.ts

This file was deleted.

4 changes: 2 additions & 2 deletions pwa/src/hooks/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as React from "react";
import { QueryClient, useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";
import { IFiltersContext } from "../context/filters";
import { IFilters } from "../context/filters";

export const useApplications = (queryClient: QueryClient) => {
const API: APIService | null = React.useContext(APIContext);

const getAll = (filters: IFiltersContext) =>
const getAll = (filters: IFilters) =>
useQuery<any, Error>(["applications", filters], () => API?.Applications.getAll(filters), {
onError: (error) => {
throw new Error(error.message);
Expand Down
6 changes: 3 additions & 3 deletions pwa/src/hooks/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { QueryClient, useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";
import { IFiltersContext } from "../context/filters";
import { IFilters } from "../context/filters";

export const useComponent = (queryClient: QueryClient) => {
const API: APIService | null = React.useContext(APIContext);
Expand All @@ -17,14 +17,14 @@ export const useComponent = (queryClient: QueryClient) => {
enabled: !!componentId,
});

const getAll = (filters: IFiltersContext) =>
const getAll = (filters: IFilters) =>
useQuery<any, Error>(["components", filters], () => API?.Component.getAll(filters), {
onError: (error) => {
throw new Error(error.message);
},
});

const getCount = (filters: IFiltersContext) =>
const getCount = (filters: IFilters) =>
useQuery<any, Error>(["components_count", filters], () => API?.Component.getCount(filters), {
onError: (error) => {
throw new Error(error.message);
Expand Down
6 changes: 3 additions & 3 deletions pwa/src/hooks/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import { QueryClient, useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";
import { IFiltersContext } from "../context/filters";
import { IFilters } from "../context/filters";

export const useOrganization = (queryClient: QueryClient) => {
const API: APIService | null = React.useContext(APIContext);
Expand All @@ -17,7 +17,7 @@ export const useOrganization = (queryClient: QueryClient) => {
enabled: !!organizationId,
});

const getAll = (filters: IFiltersContext) =>
const getAll = (filters: IFilters) =>
useQuery<any, Error>(["organizations", filters], () => API?.Organization.getAll(filters), {
onError: (error) => {
throw new Error(error.message);
Expand All @@ -31,7 +31,7 @@ export const useOrganization = (queryClient: QueryClient) => {
},
});

const getCount = (filters: IFiltersContext) =>
const getCount = (filters: IFilters) =>
useQuery<any, Error>(["organizations_count", filters], () => API?.Organization.getCount(filters), {
onError: (error) => {
throw new Error(error.message);
Expand Down
4 changes: 2 additions & 2 deletions pwa/src/hooks/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as React from "react";
import { QueryClient, useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";
import { IFiltersContext } from "../context/filters";
import { IFilters } from "../context/filters";

export const useSearch = (_: QueryClient) => {
const API: APIService | null = React.useContext(APIContext);

const getSearch = (filters: IFiltersContext) =>
const getSearch = (filters: IFilters) =>
useQuery<any, Error>(["search", filters], () => API?.Search.getSearch(filters), {
onError: (error) => {
throw new Error(error.message);
Expand Down
Loading
Loading