Skip to content

Commit

Permalink
#273 : improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermau committed Feb 19, 2025
1 parent d80a991 commit 6fe0d97
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions web/src/ui/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,30 @@ export default function Home(props: Props) {

const stats = useCoreState("generalStats", "main");

type availableStat =
type AvailableStat =
| "softwareCount"
| "registeredUserCount"
| "agentReferentCount"
| "organizationCount";
const statsCases = config.home.statistics.catgegories as Array<availableStat>;
const statsCases = config.home.statistics.catgegories as Array<AvailableStat>;

type availableUseCase = "declareReferent" | "editSoftware" | "addSoftwareOrService";
type AvailableUseCase = "declareReferent" | "editSoftware" | "addSoftwareOrService";
type UseCaseConfig = {
enabled: boolean;
labelLinks: any;
buttonEnabled: boolean;
buttonLink: string;
};
type UsesCaseConfig = Record<availableUseCase, UseCaseConfig>;
type UsesCaseConfig = Record<AvailableUseCase, UseCaseConfig>;

const configUseCases: UsesCaseConfig = config.home.usecases;
const keys: Array<availableUseCase> = Object.keys(
const keys: Array<AvailableUseCase> = Object.keys(
configUseCases
) as Array<availableUseCase>;
) as Array<AvailableUseCase>;

const useCases: Array<availableUseCase> = keys.reduce(
(accumulator: Array<availableUseCase>, key: availableUseCase) => {
return configUseCases[key].enabled ? accumulator.concat([key]) : accumulator;
},
[]
);
const useCases: Array<AvailableUseCase> = keys.filter((key: AvailableUseCase) => {
return configUseCases[key].enabled;
});

const softwareSelectionList = [
{
Expand Down Expand Up @@ -156,7 +153,7 @@ export default function Home(props: Props) {
alignItems: "center"
}}
>
{statsCases.map((metricName: availableStat) => (
{statsCases.map((metricName: AvailableStat) => (
<Grid item xs={3}>
<div key={metricName}>
<AnimatedMetric
Expand Down Expand Up @@ -189,7 +186,7 @@ export default function Home(props: Props) {
alignContent: "stretch"
}}
>
{useCases.map((cardName: availableUseCase) => {
{useCases.map((cardName: AvailableUseCase) => {
const link = (() => {
const configLink = configUseCases[cardName].buttonLink;
const renderedConfigLink = {
Expand Down

0 comments on commit 6fe0d97

Please sign in to comment.