Skip to content

Commit

Permalink
Merge pull request #357 from ConductionNL/development
Browse files Browse the repository at this point in the history
Development to main, week 9
  • Loading branch information
remko48 authored Mar 4, 2024
2 parents bedbe4e + daa98a6 commit ae30046
Show file tree
Hide file tree
Showing 20 changed files with 608 additions and 216 deletions.
13 changes: 6 additions & 7 deletions pwa/src/apiService/apiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Upload from "./resources/upload";
interface PromiseMessage {
loading?: string;
success?: string;
error?: string;
}

export type TSendFunction = (
Expand Down Expand Up @@ -255,37 +256,35 @@ export default class APIService {
switch (action) {
case "GET":
const response = instance.get(endpoint);

response.catch((err) => toast.error(err.message));

response.catch((err) => toast.error(promiseMessage?.error ?? err.message));
return response;

case "POST":
return toast.promise(instance.post(endpoint, _payload), {
loading: promiseMessage?.loading ?? "Creating item...",
success: promiseMessage?.success ?? "Succesfully created item",
error: (err) => err.message,
error: (err) => promiseMessage?.error ?? err.message,
});

case "PUT":
return toast.promise(instance.put(endpoint, _payload), {
loading: promiseMessage?.loading ?? "Updating item...",
success: promiseMessage?.success ?? "Succesfully updated item",
error: (err) => err.message,
error: (err) => promiseMessage?.error ?? err.message,
});

case "DELETE":
return toast.promise(instance.delete(endpoint), {
loading: promiseMessage?.loading ?? "Deleting item...",
success: promiseMessage?.success ?? "Succesfully deleted item",
error: (err) => err.message,
error: (err) => promiseMessage?.error ?? err.message,
});

case "DOWNLOAD":
return toast.promise(instance.get(endpoint), {
loading: promiseMessage?.loading ?? "Downloading item...",
success: promiseMessage?.success ?? "Succesfully downloaded item",
error: (err) => err.message,
error: (err) => promiseMessage?.error ?? err.message,
});
}
};
Expand Down
4 changes: 3 additions & 1 deletion pwa/src/apiService/resources/dashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default class DashboardCards {
}

public getAll = async (): Promise<any> => {
const { data } = await this._send(this._instance, "GET", "/admin/dashboardCards");
const { data } = await this._send(this._instance, "GET", "/admin/dashboardCards", undefined, {
error: "Could not fetch Dashboardcards.",
});

return data;
};
Expand Down
6 changes: 6 additions & 0 deletions pwa/src/apiService/resources/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export default class Source {
return data;
};

public getAllSelectOptions = async (): Promise<any> => {
const { data } = await this._send(this._instance, "GET", "/admin/gateways?limit=200");

return data?.map((source: any) => ({ label: source.name, value: source.id }));
};

public getOne = async (id: string): Promise<any> => {
const { data } = await this._send(this._instance, "GET", `/admin/gateways/${id}`);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
:root {
--conduction-horizontal-overflow-wrapper-background-color: unset;
--conduction-horizontal-overflow-wrapper-buttons-top: 12px;

--conduction-horizontal-overflow-wrapper-margin-inline-start: 8px;
--conduction-horizontal-overflow-wrapper-margin-inline-end: 8px;
--conduction-horizontal-overflow-wrapper-margin-block-start: 8px;
--conduction-horizontal-overflow-wrapper-margin-block-end: 8px;
}

.container {
position: relative;
background-color: var(
--conduction-horizontal-overflow-wrapper-background-color
);
}

.wrapper {
overflow-x: scroll;
}

.scrollButton {
position: sticky;
top: var(--conduction-horizontal-overflow-wrapper-buttons-top);

margin-inline-start: var(
--conduction-horizontal-overflow-wrapper-margin-inline-start
);
margin-inline-end: var(
--conduction-horizontal-overflow-wrapper-margin-inline-end
);
margin-block-start: var(
--conduction-horizontal-overflow-wrapper-margin-block-start
);
margin-block-end: var(
--conduction-horizontal-overflow-wrapper-margin-block-end
);
z-index: 10000;
}

.scrollButton.right {
left: 100%;
}

/* Hide scrollbar */
.wrapper::-webkit-scrollbar {
display: none;
}
.wrapper {
-ms-overflow-style: none;
scrollbar-width: none;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* IMPORTANT: This is a temporary component that will be removed if the @conduction/components package can be updated.
*/

import * as React from "react";
import * as styles from "./HorizontalOverflowWrapper.module.css";
import clsx from "clsx";
import { Button } from "@utrecht/component-library-react/dist/css-module";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons";

interface HorizontalOverflowWrapperProps {
children: React.ReactNode;
ariaLabels: {
scrollRightButton: string;
scrollLeftButton: string;
};
}

export const HorizontalOverflowWrapper: React.FC<HorizontalOverflowWrapperProps> = ({ children, ariaLabels }) => {
const [canScrollRight, setCanScrollRight] = React.useState<boolean>(false);
const [canScrollLeft, setCanScrollLeft] = React.useState<boolean>(false);

const wrapperRef = React.useRef<HTMLDivElement | null>(null);

const scrollRight = (): void => {
wrapperRef.current?.scrollTo({
left: wrapperRef.current.scrollLeft + wrapperRef.current.clientWidth * 0.9,
behavior: "smooth",
});
};

const scrollLeft = (): void => {
wrapperRef.current?.scrollTo({
left: wrapperRef.current.scrollLeft - wrapperRef.current.clientWidth * 0.9,
behavior: "smooth",
});
};

React.useEffect(() => {
checkScrollDirections(); // initiate available scroll directions

window.addEventListener("resize", checkScrollDirections);

return () => window.removeEventListener("resize", checkScrollDirections);
}, []);

const checkScrollDirections = (): void => {
if (!wrapperRef.current) return;

setCanScrollRight(wrapperRef.current.scrollLeft + wrapperRef.current.clientWidth < wrapperRef.current.scrollWidth);
setCanScrollLeft(wrapperRef.current.scrollLeft > 0);
};

return (
<div className={styles.container}>
{canScrollLeft && (
<Button
className={clsx(styles.scrollButton)}
onClick={scrollLeft}
appearance="secondary-action-button"
aria-label={ariaLabels.scrollLeftButton}
>
<FontAwesomeIcon icon={faChevronLeft} />
</Button>
)}

{canScrollRight && (
<Button
className={clsx(styles.scrollButton, styles.right)}
onClick={scrollRight}
appearance="secondary-action-button"
aria-label={ariaLabels.scrollRightButton}
>
<FontAwesomeIcon icon={faChevronRight} />
</Button>
)}

<div ref={wrapperRef} className={styles.wrapper} onScroll={checkScrollDirections}>
{children}
</div>
</div>
);
};
1 change: 1 addition & 0 deletions pwa/src/context/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ILogFiltersContext {
process?: string;
endpoint?: string;
schema?: string;
source?: string;
cronjob?: string;
action?: string;
user?: string;
Expand Down
1 change: 1 addition & 0 deletions pwa/src/context/tableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const logColumns = {
created: true,
endpoint: true,
schema: true,
source: true,
cronjob: true,
action: true,
user: true,
Expand Down
1 change: 1 addition & 0 deletions pwa/src/hooks/dashboardCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const useDashboardCards = (queryClient: QueryClient) => {
onError: (error) => {
console.warn(error.message);
},
retry: 0,
});

const getOne = (dashboardCardsId: string) =>
Expand Down
9 changes: 8 additions & 1 deletion pwa/src/hooks/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export const useSource = (queryClient: QueryClient) => {
},
});

const getAllSelectOptions = () =>
useQuery<any[], Error>("source_select_options", API.Sources.getAllSelectOptions, {
onError: (error) => {
console.warn(error.message);
},
});

const getOne = (sourceId: string) =>
useQuery<any, Error>(["sources", sourceId], () => API?.Sources.getOne(sourceId), {
initialData: () => queryClient.getQueryData<any[]>("sources")?.find((_sources) => _sources.id === sourceId),
Expand Down Expand Up @@ -78,5 +85,5 @@ export const useSource = (queryClient: QueryClient) => {
},
});

return { getAll, getOne, remove, createOrEdit, getProxy };
return { getAll, getOne, remove, createOrEdit, getProxy, getAllSelectOptions };
};
4 changes: 4 additions & 0 deletions pwa/src/services/removeTrailingSlash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const removeTrailingSlash = (str: string) => {
const newStr = str.endsWith("/") ? str.slice(0, -1) : str;
return newStr;
};
2 changes: 1 addition & 1 deletion pwa/src/templates/actionsTemplate/ActionsTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const ActionsTemplate: React.FC = () => {

<TableCell>{action.lastRun ? dateTime(t(i18n.language), action.lastRun) : "-"}</TableCell>

<TableCell>{`${action.lastRunTime}ms` ?? "-"}</TableCell>
<TableCell>{`${action.lastRunTime}s` ?? "-"}</TableCell>

<TableCell>{translateDate(i18n.language, action.dateCreated) ?? "-"}</TableCell>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const GatewayDetailTemplate: React.FC = () => {
getPlugins.data.update ? getPlugins.data?.version : `Latest (${getPlugins.data?.version})`
} `}</p>
)}
<p>{`last update time: ${new Date(getPlugins.data?.time).toLocaleString()}`}</p>
<p>{`last update time: ${new Date(
getPlugins.data?.versions[getPlugins.data?.version]?.time,
).toLocaleString()}`}</p>
</div>

<div>
Expand Down
5 changes: 4 additions & 1 deletion pwa/src/templates/login/LoginTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAuthentication } from "../../hooks/useAuthentication";
import { useIsLoadingContext } from "../../context/isLoading";
import APIService from "../../apiService/apiService";
import APIContext from "../../apiService/apiContext";
import { removeTrailingSlash } from "../../services/removeTrailingSlash";

export const LoginTemplate: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -54,7 +55,9 @@ export const LoginTemplate: React.FC = () => {

React.useEffect(() => {
window.sessionStorage.getItem("GATSBY_BASE_URL") &&
setDexRedirectURL(`${window.sessionStorage.getItem("GATSBY_BASE_URL")}/login/oidc/dex`);
setDexRedirectURL(
`${removeTrailingSlash(window.sessionStorage.getItem("GATSBY_BASE_URL") ?? "")}/login/oidc/dex`,
);
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
}

.warningLevel {
--denhaag-alert-info-background-color: #var(
--denhaag-alert-info-background-color: var(
--gateway-ui-color-status-background-warning
);
--denhaag-alert-info-icon-color: var(--gateway-ui-color-status-warning);
Expand Down
Loading

0 comments on commit ae30046

Please sign in to comment.