Skip to content

Commit

Permalink
refactor: fixes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
tohapi committed Jan 10, 2024
1 parent feccd76 commit e9211fb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AttestationDataMapper from "@verax-attestation-registry/verax-sdk/lib/typ
import { ITEMS_PER_PAGE_DEFAULT } from "@/constants";
import { ResultParseSearch } from "@/interfaces/components";
import { isNotNullOrUndefined } from "@/utils";
import { uniqMapById } from "@/utils/searchUtils";
import { uniqMap } from "@/utils/searchUtils";

export const loadAttestationList = async (
attestation: AttestationDataMapper,
Expand Down Expand Up @@ -40,5 +40,5 @@ export const loadAttestationList = async (
...(listBySchemaString || []),
];

return uniqMapById(results);
return uniqMap(results, "id");
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ModuleDataMapper from "@verax-attestation-registry/verax-sdk/lib/types/sr
import { ITEMS_PER_PAGE_DEFAULT } from "@/constants";
import { ResultParseSearch } from "@/interfaces/components";
import { isNotNullOrUndefined } from "@/utils";
import { uniqMapById } from "@/utils/searchUtils";
import { uniqMap } from "@/utils/searchUtils";

export const loadModuleList = async (module: ModuleDataMapper, parsedString: Partial<ResultParseSearch>) => {
const [listByName, listByDescription] = parsedString.nameOrDescription
Expand All @@ -23,5 +23,5 @@ export const loadModuleList = async (module: ModuleDataMapper, parsedString: Par

const results = [...(listByIds || []), ...(listByName || []), ...(listByDescription || [])];

return uniqMapById(results);
return uniqMap(results, "id");
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SchemaDataMapper from "@verax-attestation-registry/verax-sdk/lib/types/sr
import { ITEMS_PER_PAGE_DEFAULT } from "@/constants";
import { ResultParseSearch } from "@/interfaces/components";
import { isNotNullOrUndefined } from "@/utils";
import { uniqMapById } from "@/utils/searchUtils";
import { uniqMap } from "@/utils/searchUtils";

export const loadSchemaList = async (schema: SchemaDataMapper, parsedString: Partial<ResultParseSearch>) => {
const [listByName, listByDescription] = parsedString.nameOrDescription
Expand Down Expand Up @@ -39,5 +39,5 @@ export const loadSchemaList = async (schema: SchemaDataMapper, parsedString: Par
...(listByContext || []),
];

return uniqMapById(results);
return uniqMap(results, "id");
};
4 changes: 2 additions & 2 deletions explorer/src/utils/searchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export const parseSearch = (search: string | null): Partial<ResultParseSearch> =
};
};

export const uniqMapById = <T extends { id: string }>(array: T[]): T[] => [
...new Map(array.map((result) => [result.id, result])).values(),
export const uniqMap = <T>(array: T[], by: keyof T): T[] => [
...new Map(array.map((result) => [result[by], result])).values(),
];

0 comments on commit e9211fb

Please sign in to comment.