From 7de0a6f367b3236e261c2fb1c3da17199bf0774c Mon Sep 17 00:00:00 2001 From: James Date: Thu, 5 Dec 2024 15:07:20 -0500 Subject: [PATCH] [ALS-7889] Remove duplication of Sample Ids (#315) --- .../components/datatable/accessories/Rows.svelte | 2 +- .../explorer/export/ExportStepper.svelte | 14 +++++++++----- src/lib/stores/Export.ts | 11 ++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lib/components/datatable/accessories/Rows.svelte b/src/lib/components/datatable/accessories/Rows.svelte index e13de9be..d53525cd 100644 --- a/src/lib/components/datatable/accessories/Rows.svelte +++ b/src/lib/components/datatable/accessories/Rows.svelte @@ -3,7 +3,7 @@ import { DataHandler as RemoteHander } from '@vincjo/datatables/remote'; export let handler: DataHandler | RemoteHander; export let options: number[] = [5, 10, 20, 50]; - const rowsPerPage = handler.getRowsPerPage(); + $: rowsPerPage = handler.getRowsPerPage(); const setRowsPerPage = () => { handler.setPage(1); if (handler instanceof RemoteHander) { diff --git a/src/lib/components/explorer/export/ExportStepper.svelte b/src/lib/components/explorer/export/ExportStepper.svelte index 6b9911bf..611cf468 100644 --- a/src/lib/components/explorer/export/ExportStepper.svelte +++ b/src/lib/components/explorer/export/ExportStepper.svelte @@ -274,15 +274,19 @@ (e) => ({ ref: e, - variableId: e.id, - variableName: e.display, + variableId: e?.searchResult?.conceptPath, + variableName: e?.display, description: e?.searchResult?.description, - type: e?.searchResult.type, + type: e?.searchResult?.type, selected: true, }) as ExportRowInterface, ); - - rows = [...rows, ...newRows]; + //Remove duplicates + rows = Array.from( + [...rows, ...newRows] + .reduce((map, row) => map.set(row.variableId, row), new Map()) + .values(), + ); lastExports = newRows; } catch (error) { console.error('Error in toggleSampleIds', error); diff --git a/src/lib/stores/Export.ts b/src/lib/stores/Export.ts index 61eb2c8a..85aac877 100644 --- a/src/lib/stores/Export.ts +++ b/src/lib/stores/Export.ts @@ -6,7 +6,7 @@ const exports: Writable = writable([]); function addExport(exportedField: ExportInterface) { const currentExports = get(exports); - if (currentExports.some((e: ExportInterface) => e.id === exportedField.id)) { + if (currentExports.some((e: ExportInterface) => e.conceptPath === exportedField.conceptPath)) { return; } exports.set([...currentExports, exportedField]); @@ -16,7 +16,8 @@ function addExport(exportedField: ExportInterface) { function addExports(exportedFields: ExportInterface[]) { const currentExports = get(exports); const newExports = exportedFields.filter( - (e: ExportInterface) => !currentExports.some((ce: ExportInterface) => ce.id === e.id), + (e: ExportInterface) => + !currentExports.some((ce: ExportInterface) => ce.conceptPath === e.conceptPath), ); exports.set([...currentExports, ...newExports]); } @@ -32,7 +33,11 @@ function removeExport(uuid: string) { function removeExports(exportsToRemove: ExportInterface[]) { const currentExports = get(exports); - exports.set(currentExports.filter((e: ExportInterface) => !exportsToRemove.includes(e))); + exports.set( + currentExports.filter( + (e: ExportInterface) => !exportsToRemove.some((re) => re.conceptPath === e.conceptPath), + ), + ); } export function clearExports() {