Skip to content

Commit

Permalink
chore: improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Sep 19, 2024
1 parent 7ca238b commit c374ccc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IReportBase {
title: string;
}

interface IReportTable extends IReportBase {
export interface IReportTable extends IReportBase {
data: Record<string, any>[];
type: "table";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { IParsedWorkbookData } from "../../types";
import { IReport } from "../report.types";
import { IReportTable } from "../report.types";

interface IReportData {
type: string;
subtype: string;
total: number;
}

interface IFlowByTypeReport extends IReportTable {
data: IReportData[];
}

/** Generate a list of all flows by type and subtype */
export class FlowByTypeReport {
Expand All @@ -13,22 +23,20 @@ export class FlowByTypeReport {
countBySubtype[type]++;
});
});
const summary = Object.keys(countBySubtype)
const summary: IReportData[] = Object.keys(countBySubtype)
.sort()
.map((key) => {
const [type, subtype] = key.split(".");
return { type, subtype: subtype || null, total: countBySubtype[key] };
});

const reports: Record<"flows_by_type", IReport> = {
flows_by_type: {
type: "table",
title: "Flows By Type",
level: "info",
data: summary,
},
const flows_by_type: IFlowByTypeReport = {
type: "table",
title: "Flows By Type",
level: "info",
data: summary,
};

return reports;
return { flows_by_type };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { FlowTypes } from "data-models";
import { sortJsonKeys } from "shared/src/utils";

import { IParsedWorkbookData } from "../../types";
import { IReport } from "../report.types";
import { IReportTable } from "../report.types";

interface IReportData {
type: string;
count: number;
}

interface ITemplateSummaryReport extends IReportTable {
data: IReportData[];
}

interface ITemplateSummary {
components: Record<string, { count: number }>;
Expand Down Expand Up @@ -35,26 +44,24 @@ export class TemplateSummaryReport {
}
}

const reports: Record<"template_components" | "template_actions", IReport> = {
template_components: {
type: "table",
title: "Components",
level: "info",
data: this.getReportData(this.summary.components),
},
template_actions: {
type: "table",
title: "Actions",
level: "info",
data: this.getReportData(this.summary.actions),
},
const template_components: ITemplateSummaryReport = {
type: "table",
title: "Components",
level: "info",
data: this.getReportData(this.summary.components),
};
const template_actions: ITemplateSummaryReport = {
type: "table",
title: "Actions",
level: "info",
data: this.getReportData(this.summary.actions),
};

return reports;
return { template_components, template_actions };
}

/** Convert type records to array for report */
private getReportData(data: Record<string, { count: number }>) {
private getReportData(data: Record<string, { count: number }>): IReportData[] {
const sorted = sortJsonKeys(data);
return Object.entries(sorted).map(([type, { count }]) => ({ type, count }));
}
Expand Down

0 comments on commit c374ccc

Please sign in to comment.