Skip to content

Commit

Permalink
HJ-128 - Updating frontend to use the new API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-torres-marroquin committed Dec 11, 2024
1 parent 426e5fb commit cdd533f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,22 @@ export const CustomReportCreationModal = ({
);

const handleCreateReport = async (reportName: string) => {
// const columnMap: Record<string, { label: string; enabled: boolean }> = {};
// const columnVisibility: Record<string, boolean> =
// tableStateToSave?.columnVisibility || {};
// Object.keys(columnMapToSave).forEach((key) => {
// columnMap[key] = {
// label: columnMapToSave[key],
// enabled: columnVisibility[key],
// };
// });

// console.log("columnMap", columnMap);
const columnMap: Record<string, { label: string; enabled: boolean }> = {};
const columnVisibility: Record<string, boolean> =
tableStateToSave?.columnVisibility || {};
Object.keys(columnMapToSave).forEach((key) => {
columnMap[key] = {
label: columnMapToSave[key],
enabled: columnVisibility[key],
};
});

try {
const newReportTemplate = {
name: reportName.trim(),
type: ReportType.DATAMAP,
config: {
// column_map: columnMap,
column_map: columnMapToSave,
column_map: columnMap,
table_state: tableStateToSave,
},
};
Expand Down
4 changes: 2 additions & 2 deletions clients/admin-ui/src/features/common/table/v2/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const columnExpandedVersion = (

interface GetColumnHeaderTextProps {
columnId: string | undefined;
columnNameMap?: Record<string, string>;
columnNameMap?: Record<string, Record<string, any>>;
}
/**
* Get the header text for a column.
Expand Down Expand Up @@ -56,5 +56,5 @@ export const getColumnHeaderText = ({
"",
);
const nameFromId = _.upperFirst(keyWithoutPrefix.replaceAll("_", " "));
return columnNameMap?.[columnId] || nameFromId;
return columnNameMap?.[columnId]?.label || nameFromId;
};
7 changes: 3 additions & 4 deletions clients/admin-ui/src/features/datamap/datamap.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const datamapApi = baseApi.injectEndpoints({
dataSubjects?: string;
format?: ExportFormat;
report_id?: string;
report?: string;
report?: object;
}
>({
query: ({
Expand Down Expand Up @@ -139,11 +139,10 @@ const datamapApi = baseApi.injectEndpoints({
if (report_id) {
queryString += `&report_id=${report_id}`;
}
if (report) {
queryString += `&report=${report}`;
}
return {
url: `plus/datamap/minimal/${format}?${queryString}`,
method: "POST",
body: { report },
responseHandler: async (response) => {
const filename = await getFileNameFromContentDisposition(
response.headers.get("content-disposition"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,30 @@ export const DatamapReportTable = () => {
} = useDisclosure();

const onExport = (downloadType: ExportFormat) => {
const columnMap: Record<string, { label: string; enabled: boolean }> = {};
Object.keys(columnNameMapOverrides).forEach((key) => {
columnMap[key] = {
label: columnNameMapOverrides[key],
enabled: columnVisibility[key],
};
});

exportMinimalDatamapReport({
...reportQuery,
format: downloadType,
report_id: savedCustomReportId,
// report: JSON.stringify({
// name: "temporary report",
// type: "datamap",
// config: {
// column_map: columnNameMapOverrides,
// table_state: {
// groupBy,
// filters: selectedFilters,
// columnOrder,
// columnVisibility,
// },
// },
// }),
report: {
name: "temporary report",
type: "datamap",
config: {
column_map: columnMap,
table_state: {
groupBy,
filters: selectedFilters,
columnOrder,
},
},
},
}).then(() => {
if (isExportReportSuccess) {
onExportReportClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,22 @@ export const getDefaultColumn: (
isRenamingColumns,
) => ({
cell: (props) => <DefaultCell value={props.getValue() as string} />,
header: (props) => {
console.log("props", props);
console.log("columnNameMap", columnNameMap);
return null;
// <EditableHeaderCell
// value={getColumnHeaderText({
// columnId: props.column.id,
// columnNameMap,
// })}
// defaultValue={
// DEFAULT_COLUMN_NAMES[props.column.id as COLUMN_IDS] ||
// getColumnHeaderText({
// columnId: props.column.id,
// })
// }
// isEditing={isRenamingColumns}
// {...props}
// />
},
header: (props) => (
<EditableHeaderCell
value={getColumnHeaderText({
columnId: props.column.id,
columnNameMap,
})}
defaultValue={
DEFAULT_COLUMN_NAMES[props.column.id as COLUMN_IDS] ||
getColumnHeaderText({
columnId: props.column.id,
})
}
isEditing={isRenamingColumns}
{...props}
/>
),
});

const getCustomFieldColumns = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum DATAMAP_LOCAL_STORAGE_KEYS {

export enum COLUMN_IDS {
SYSTEM_NAME = "system_name",
DATA_USE = "data_use",
DATA_USE = "data_uses",
DATA_CATEGORY = "data_categories",
DATA_SUBJECT = "data_subjects",
LEGAL_NAME = "legal_name",
Expand Down

0 comments on commit cdd533f

Please sign in to comment.