Skip to content

Commit

Permalink
Merge branch 'feature/enable-dashboard-elements-to-be-loaded-from-ser…
Browse files Browse the repository at this point in the history
…ver' of https://github.com/tokenguardio/dashboard-creator-server into feature/enable-dashboard-elements-to-be-loaded-from-server
  • Loading branch information
AdamDawidKrol committed Mar 5, 2024
2 parents d627cd2 + c2d9792 commit 908398d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/components/dashboard/dashboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,40 @@ const getAllDashboards = async (req: Request, res: Response) => {
const readDashboard = async (req: Request, res: Response) => {
try {
const dashboard = await read(req.params.id);
for (const filter of dashboard.filters) {
if ('queryId' in filter) {
const dynamicFilter = filter as
| IDashboardFilterDynamic
| IDashboardFilterDependent;
const filterValues = [];
if ('params' in dynamicFilter && dynamicFilter.params.length > 0) {
for (const param of dynamicFilter.params) {
filterValues.push({ name: param, value: [' '] });
}
}
const queryPayload = prepareFilterQueryPayload(
dashboard,
filter as IDashboardFilterDynamic | IDashboardFilterDependent,
filterValues,
);
logger.info(
`getFilterData queryPayload: ${JSON.stringify(queryPayload)}`,
);
const url = `${API_BASE_URL}/execute-query`;
const response = await axios.post(url, queryPayload);
const data = await response.data;
logger.info(`getFilterData response: ${JSON.stringify(data)}`);
// Update options field if necessary
if (data && data.data && Array.isArray(data.data)) {
// Update options field if necessary
filter.options = data.data.map((item: any) => ({
label: item.value,
value: item.value,
}));
}
}
}

res
.status(httpStatus.OK)
.send({ message: 'Dashboard Read', output: dashboard });
Expand Down
1 change: 1 addition & 0 deletions src/components/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const read = async (id: string): Promise<IDashboard> => {
if (!dashboard) {
throw new Error(`Dashboard with id ${id} not found`);
}

return dashboard as IDashboard;
} catch (error) {
logger.error('Error in fetching dashboard:', error);
Expand Down

0 comments on commit 908398d

Please sign in to comment.