diff --git a/enums/enum-functions.ts b/enums/enum-functions.ts index f2a11e1..e65d6bd 100644 --- a/enums/enum-functions.ts +++ b/enums/enum-functions.ts @@ -1,4 +1,4 @@ -import { InformationSourceType, LabelSource, SearchGroup, Slice, StaticOrderByKeys } from "./enums"; +import { InformationSourceType, IntegrationType, LabelSource, SearchGroup, Slice, StaticOrderByKeys } from "./enums"; export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) { if (forDisplay) { @@ -58,4 +58,10 @@ export function getOrderByDisplayName(orderByKey: string) { case StaticOrderByKeys.WEAK_SUPERVISION_CONFIDENCE: return "Weak Supervision Confidence"; default: return orderByKey; //attributes } +} + +export const INTEGRATIONS_DISPLAY = { + [IntegrationType.GITHUB_FILE]: "GitHub File", + [IntegrationType.GITHUB_ISSUE]: "GitHub Issue", + [IntegrationType.SHAREPOINT]: "SharePoint", } \ No newline at end of file diff --git a/enums/enums.ts b/enums/enums.ts index 76f58c1..937d473 100644 --- a/enums/enums.ts +++ b/enums/enums.ts @@ -52,4 +52,10 @@ export enum ModelsDownloadedStatus { DOWNLOADING = 'downloading', INITIALIZING = 'initializing', FAILED = 'failed', +} + +export enum IntegrationType { + GITHUB_ISSUE = 'GITHUB_ISSUE', + GITHUB_FILE = 'GITHUB_FILE', + SHAREPOINT = 'SHAREPOINT', } \ No newline at end of file diff --git a/post-process-functions.ts b/post-process-functions.ts new file mode 100644 index 0000000..96fafd8 --- /dev/null +++ b/post-process-functions.ts @@ -0,0 +1,48 @@ +import { jsonCopy } from "./general"; + +export function postProcessRecord(record: any, attributes: any[]) { + const prepareRecord = jsonCopy(record); + if (!prepareRecord.hasOwnProperty('data')) { + if (prepareRecord.hasOwnProperty('fullRecordData')) { + prepareRecord.data = prepareRecord.fullRecordData; + } + else if (prepareRecord.hasOwnProperty('recordData')) { + prepareRecord.data = prepareRecord.recordData; + } else { + throw new Error("Cant find record data in record object"); + } + } + attributes.forEach((attribute, index) => { + if (typeof prepareRecord.data[attribute.name] === 'boolean') { + prepareRecord.data[attribute.name] = prepareRecord.data[attribute.name].toString(); + } + }); + return prepareRecord; +} + +export function postProcessAttributes(attributes: any[]) { + const prepareAttributes = jsonCopy(attributes); + if (attributes && attributes.length > 0) { + if (!attributes[0].hasOwnProperty('key')) { + prepareAttributes.forEach((attribute, index) => { + if (attribute.id !== null) { + attribute.key = attribute.id; + } else { + throw new Error("Cant find attribute id in attribute object"); + } + }); + } + } + return prepareAttributes; +} + +export function postProcessUpdateAndSortRecords(prev: any[], newRecords: any[]) { + const merged = [...prev, ...newRecords]; + const uniqueRecords = Array.from( + new Map(merged.map((item) => [item.data?.running_id, item])).values() + ); + uniqueRecords.sort( + (a, b) => (a.data?.running_id || 0) - (b.data?.running_id || 0) + ); + return uniqueRecords; +} \ No newline at end of file