Skip to content

Commit 835cef5

Browse files
committed
File showing up as duplicate fix
1 parent 3bcefc1 commit 835cef5

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

src/ui/src/components/common/map-document-attributes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ const mapDocumentsAttributes = (documents) => {
7676
const hitlTriggered = hitlStatus && hitlStatus !== 'N/A';
7777
const hitlCompleted = isHitlCompleted(hitlStatus);
7878

79+
// Create a unique ID combining PK and SK for proper row tracking
80+
const uniqueId = listPK && listSK ? `${listPK}#${listSK}` : objectKey;
81+
7982
const mapping = {
83+
uniqueId,
8084
objectKey,
8185
objectStatus,
8286
initialEventTime: formatDate(initialEventTime),

src/ui/src/components/document-list/DocumentList.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
DocumentsCommonHeader,
2121
COLUMN_DEFINITIONS_MAIN,
2222
KEY_COLUMN_ID,
23+
UNIQUE_TRACK_ID,
2324
SELECTION_LABELS,
2425
DEFAULT_PREFERENCES,
2526
DEFAULT_SORT_COLUMN,
@@ -64,7 +65,7 @@ const DocumentList = () => {
6465
sorting: { defaultState: { sortingColumn: DEFAULT_SORT_COLUMN, isDescending: true } },
6566
selection: {
6667
keepSelection: false,
67-
trackBy: KEY_COLUMN_ID,
68+
trackBy: UNIQUE_TRACK_ID,
6869
},
6970
});
7071

@@ -150,7 +151,7 @@ const DocumentList = () => {
150151
wrapLines={preferences.wrapLines}
151152
pagination={<Pagination {...paginationProps} ariaLabels={paginationLabels} />}
152153
preferences={<DocumentsPreferences preferences={preferences} setPreferences={setPreferences} />}
153-
trackBy={items.objectKey}
154+
trackBy={UNIQUE_TRACK_ID}
154155
visibleColumns={[KEY_COLUMN_ID, ...preferences.visibleContent]}
155156
resizableColumns
156157
/>

src/ui/src/components/document-list/documents-table-config.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DOCUMENTS_PATH } from '../../routes/constants';
88
import { renderHitlStatus } from '../common/hitl-status-renderer';
99

1010
export const KEY_COLUMN_ID = 'objectKey';
11+
export const UNIQUE_TRACK_ID = 'uniqueId';
1112

1213
export const COLUMN_DEFINITIONS_MAIN = [
1314
{

src/ui/src/hooks/use-graphql-api.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,37 @@ const useGraphQlApi = ({ initialPeriodsToLoad = DOCUMENT_LIST_SHARDS_PER_DAY * 2
3030
logger.debug('setDocumentsDeduped called with:', documentValues);
3131
setDocuments((currentDocuments) => {
3232
const documentValuesdocumentIds = documentValues.map((c) => c.ObjectKey);
33-
const updatedDocuments = [
34-
...currentDocuments.filter((c) => !documentValuesdocumentIds.includes(c.ObjectKey)),
35-
...documentValues.map((document) => ({
36-
...document,
37-
ListPK: document.ListPK || currentDocuments.find((c) => c.ObjectKey === document.ObjectKey)?.ListPK,
38-
ListSK: document.ListSK || currentDocuments.find((c) => c.ObjectKey === document.ObjectKey)?.ListSK,
39-
})),
40-
];
41-
logger.debug('Documents state updated, new count:', updatedDocuments.length);
42-
return updatedDocuments;
33+
34+
// Remove old entries with matching ObjectKeys
35+
const filteredCurrentDocuments = currentDocuments.filter((c) => !documentValuesdocumentIds.includes(c.ObjectKey));
36+
37+
// Add new entries with PK/SK preserved
38+
const newDocuments = documentValues.map((document) => ({
39+
...document,
40+
ListPK: document.ListPK || currentDocuments.find((c) => c.ObjectKey === document.ObjectKey)?.ListPK,
41+
ListSK: document.ListSK || currentDocuments.find((c) => c.ObjectKey === document.ObjectKey)?.ListSK,
42+
}));
43+
44+
// Combine and deduplicate by ObjectKey, keeping only the latest entry per ObjectKey
45+
const allDocuments = [...filteredCurrentDocuments, ...newDocuments];
46+
const deduplicatedByObjectKey = Object.values(
47+
allDocuments.reduce((acc, doc) => {
48+
const existing = acc[doc.ObjectKey];
49+
// Keep the document with the most recent CompletionTime or InitialEventTime
50+
if (!existing) {
51+
acc[doc.ObjectKey] = doc;
52+
} else {
53+
const existingTime = existing.CompletionTime || existing.InitialEventTime || '0';
54+
const newTime = doc.CompletionTime || doc.InitialEventTime || '0';
55+
if (newTime > existingTime) {
56+
acc[doc.ObjectKey] = doc;
57+
}
58+
}
59+
return acc;
60+
}, {}),
61+
);
62+
63+
return deduplicatedByObjectKey;
4364
});
4465
}, []);
4566

0 commit comments

Comments
 (0)