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

Added publication table #477

Merged
merged 1 commit into from
Jul 6, 2024
Merged
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
11 changes: 8 additions & 3 deletions pwa/src/apiService/apiService.ts
Original file line number Diff line number Diff line change
@@ -102,10 +102,15 @@ export default class APIService {
}

public get PublicationClient(): AxiosInstance {
const authorization = this.JWT ? { Authorization: "Bearer " + this.JWT } : {};

return axios.create({
baseURL: removeFileNameFromUrl(
"https://raw.githubusercontent.com/ConductionNL/OpenCatalogApp/feature/AQ212-8/publicatie-modal/docs/dcat_example.json",
),
baseURL: "https://nextcloud.test.commonground.nu/index.php/apps/opencatalog/api",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
...authorization,
});
}

23 changes: 21 additions & 2 deletions pwa/src/apiService/resources/publication.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Send } from "../apiService";
import { AxiosInstance } from "axios";
import { IFiltersContext } from "../../context/filters";
import { filtersToQueryParams } from "../../services/filtersToQueryParams";

export default class Publication {
private _instance: AxiosInstance;
@@ -8,8 +10,25 @@ export default class Publication {
this._instance = _instance;
}

public getContent = async (fileName: string): Promise<any> => {
const { data } = await Send(this._instance, "GET", fileName);
public getOne = async (id: string): Promise<any> => {
const { data } = await Send(this._instance, "GET", `/search/${id}?extend[]=all`);

return data;
};

public getSearch = async (filters: IFiltersContext, currentPage: number, limit: number): Promise<any> => {
let endpoint = `/search`;

if (
window.sessionStorage.getItem("GITHUB_ORGANIZATION_URL") !== "" &&
window.sessionStorage.getItem("GITHUB_ORGANIZATION_URL") !== "false"
) {
endpoint += `&embedded.url.embedded.organisation.github=${window.sessionStorage.getItem(
"GITHUB_ORGANIZATION_URL",
)}`;
}

const { data } = await Send(this._instance, "GET", endpoint);

return data;
};
7 changes: 1 addition & 6 deletions pwa/src/apiService/resources/search.ts
Original file line number Diff line number Diff line change
@@ -10,14 +10,9 @@ export default class Search {
this._instance = _instance;
}

public getSearch = async (
filters: IFiltersContext,
currentPage: number,
limit: number,
): Promise<any> => {
public getSearch = async (filters: IFiltersContext, currentPage: number, limit: number): Promise<any> => {
let endpoint = `/search?page=${currentPage}&limit=${limit}&extend[]=all${filtersToQueryParams(filters)}`;


if (
window.sessionStorage.getItem("GITHUB_ORGANIZATION_URL") !== "" &&
window.sessionStorage.getItem("GITHUB_ORGANIZATION_URL") !== "false"
2 changes: 2 additions & 0 deletions pwa/src/context/pagination.ts
Original file line number Diff line number Diff line change
@@ -5,12 +5,14 @@ export interface IPaginationContext {
componentsCurrentPage: number;
organizationCurrentPage: number;
applicationCurrentPage: number;
publicationCurrentPage: number;
}

export const defaultPaginationContext: IPaginationContext = {
componentsCurrentPage: 1,
organizationCurrentPage: 1,
applicationCurrentPage: 1,
publicationCurrentPage: 1,
};

export const usePaginationContext = () => {
4 changes: 4 additions & 0 deletions pwa/src/context/queryLimit.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ export interface IQueryLimitContext {
organizationsQueryLimit: number;
previousApplicationsQueryLimit: number;
applicationsQueryLimit: number;
previousPublicationsQueryLimit: number;
publicationsQueryLimit: number;
}

export const defaultQueryLimitContext: IQueryLimitContext = {
@@ -19,6 +21,8 @@ export const defaultQueryLimitContext: IQueryLimitContext = {
organizationsQueryLimit: QUERY_LIMIT_DEFAULT,
previousApplicationsQueryLimit: QUERY_LIMIT_DEFAULT,
applicationsQueryLimit: QUERY_LIMIT_DEFAULT,
previousPublicationsQueryLimit: QUERY_LIMIT_DEFAULT,
publicationsQueryLimit: QUERY_LIMIT_DEFAULT,
};

export const useQueryLimitContext = () => {
3 changes: 3 additions & 0 deletions pwa/src/context/resultDisplayLayout.ts
Original file line number Diff line number Diff line change
@@ -6,13 +6,15 @@ export type TComponentDependenciesLayout = "layer" | "relations";
export type TLandingDisplayLayout = "layer" | "cards";
export type TCatagoryDisplayLayout = "table" | "cards" | "layer";
export type TOrganizationsResultDisplayLayout = "table" | "cards";
export type TPublicationsResultDisplayLayout = "table";

export interface IResultDisplayLayoutContext {
componentsDisplayLayout: TComponentResultsLayout;
dependenciesDisplayLayout: TComponentDependenciesLayout;
landingDisplayLayout: TLandingDisplayLayout;
catagoryDisplayLayout: TCatagoryDisplayLayout;
organizationsResultDisplayLayout: TOrganizationsResultDisplayLayout;
publicationsResultDisplayLayout: TPublicationsResultDisplayLayout;
}

export const defaultResultDisplayLayoutContext: IResultDisplayLayoutContext = {
@@ -21,6 +23,7 @@ export const defaultResultDisplayLayoutContext: IResultDisplayLayoutContext = {
landingDisplayLayout: "cards",
catagoryDisplayLayout: "table",
organizationsResultDisplayLayout: "cards",
publicationsResultDisplayLayout: "table",
};

export const useResultDisplayLayoutContext = () => {
33 changes: 21 additions & 12 deletions pwa/src/hooks/publication.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import * as React from "react";
import { useQuery } from "react-query";
import { QueryClient, useQuery } from "react-query";
import APIService from "../apiService/apiService";
import APIContext from "../apiService/apiContext";
import { getFileNameFromUrl } from "../services/FileNameFromUrl";
import { DEFAULT_HEADER_CONTENT_URL } from "../templates/templateParts/header/HeaderTemplate";
import { IFiltersContext } from "../context/filters";

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

const fileName = getFileNameFromUrl(
"https://raw.githubusercontent.com/ConductionNL/OpenCatalogApp/feature/AQ212-8/publicatie-modal/docs/dcat_example.json",
);

const getContent = () =>
useQuery<any, Error>(["contents", fileName], () => API?.Publication.getContent(fileName), {
const getOne = (publicationId: string) =>
useQuery<any, Error>(["publications", publicationId], () => API?.Publication.getOne(publicationId), {
initialData: () =>
queryClient.getQueryData<any[]>("publications")?.find((_publication) => _publication.id === publicationId),
onError: (error) => {
console.warn(error.message);
throw new Error(error.message);
},
enabled: !!publicationId,
});

return { getContent };
const getSearch = (filters: IFiltersContext, currentPage: number, limit: number) =>
useQuery<any, Error>(
["publications", filters, currentPage, limit],
() => API?.Publication.getSearch(filters, currentPage, limit),
{
onError: (error) => {
throw new Error(error.message);
},
},
);

return { getOne, getSearch };
};
4 changes: 2 additions & 2 deletions pwa/src/pages/publications/PublicationsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react";
import { PageProps } from "gatsby";
import { ComponentsTemplate } from "../../templates/components/ComponentsTemplate";
import { PublicationsTemplate } from "../../templates/publications/PublicationsTemplate";

const PublicationsPage: React.FC<PageProps> = () => {
return <ComponentsTemplate />;
return <PublicationsTemplate />;
};

export default PublicationsPage;
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@ import { PageProps } from "gatsby";
import { PublicationsDetailTemplate } from "../../../templates/publicationDetail/PublicationsDetailTemplate";

const PublicationsDetailPage: React.FC<PageProps> = (props: PageProps) => {
return <PublicationsDetailTemplate publicationId={props.params.componentId} />;
return <PublicationsDetailTemplate publicationId={props.params.publicationId} />;
};
export default PublicationsDetailPage;
7 changes: 6 additions & 1 deletion pwa/src/templates/components/ComponentsTemplate.tsx
Original file line number Diff line number Diff line change
@@ -155,7 +155,12 @@ export const ComponentsTemplate: React.FC = () => {
totalPages={getComponents.data.pages}
currentPage={getComponents.data.page}
setCurrentPage={(page: any) => setPagination({ ...pagination, componentsCurrentPage: page })}
ariaLabels={{ nextPage: t("Next page"), previousPage: t("Previous page"), page: t("Page") }}
ariaLabels={{
pagination: t("Pagination"),
nextPage: t("Next page"),
previousPage: t("Previous page"),
page: t("Page"),
}}
/>
<PaginationLimitSelectComponent queryLimitName={"componentsSearchQueryLimit"} />
</div>
Loading