mirror of
https://github.com/run-llama/sec-insights.git
synced 2026-07-01 20:24:03 -04:00
frontend hotfix for duplicated sec docs (#70)
* frontend hotfix for duplicated sec docs * add sorting + make use of lodash's sortedUniqBy * revert NEXT_PUBLIC_BACKEND_URL
This commit is contained in:
@@ -2,12 +2,16 @@ import { MAX_NUMBER_OF_SELECTED_DOCUMENTS } from "~/hooks/useDocumentSelector";
|
||||
import { BackendDocument, BackendDocumentType } from "~/types/backend/document";
|
||||
import { SecDocument, DocumentType } from "~/types/document";
|
||||
import { documentColors } from "~/utils/colors";
|
||||
import _ from "lodash";
|
||||
|
||||
export const fromBackendDocumentToFrontend = (
|
||||
backendDocuments: BackendDocument[]
|
||||
) => {
|
||||
const frontendDocs: SecDocument[] = [];
|
||||
backendDocuments.map((backendDoc, index) => {
|
||||
// sort by created_at so that de-dupe filter later keeps oldest duplicate docs
|
||||
backendDocuments = _.sortBy(backendDocuments, 'created_at');
|
||||
let frontendDocs: SecDocument[] = backendDocuments
|
||||
.filter((backendDoc) => 'sec_document' in backendDoc.metadata_map)
|
||||
.map((backendDoc, index) => {
|
||||
const backendDocType = backendDoc.metadata_map.sec_document.doc_type;
|
||||
const frontendDocType =
|
||||
backendDocType === BackendDocumentType.TenK
|
||||
@@ -16,7 +20,7 @@ export const fromBackendDocumentToFrontend = (
|
||||
|
||||
// we have 10 colors for 10 documents
|
||||
const colorIndex = index < 10 ? index : 0;
|
||||
const payload = {
|
||||
return {
|
||||
id: backendDoc.id,
|
||||
url: backendDoc.url,
|
||||
ticker: backendDoc.metadata_map.sec_document.company_ticker,
|
||||
@@ -26,7 +30,10 @@ export const fromBackendDocumentToFrontend = (
|
||||
color: documentColors[colorIndex],
|
||||
quarter: backendDoc.metadata_map.sec_document.quarter || "",
|
||||
} as SecDocument;
|
||||
frontendDocs.push(payload);
|
||||
});
|
||||
// de-dupe hotfix
|
||||
const getDocDeDupeKey = (doc: SecDocument) => `${doc.ticker}-${doc.year}-${doc.quarter || ''}`;
|
||||
frontendDocs = _.chain(frontendDocs).sortBy(getDocDeDupeKey).sortedUniqBy(getDocDeDupeKey).value();
|
||||
|
||||
return frontendDocs;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user