Skip to content

Commit

Permalink
Added more context to log
Browse files Browse the repository at this point in the history
  • Loading branch information
remko48 committed Feb 19, 2024
1 parent f35e41f commit 71bb659
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 70 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
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 };
};
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
Loading

0 comments on commit 71bb659

Please sign in to comment.