Skip to content

Commit dcbd2e8

Browse files
Added integration type as enum (#15)
* Added integration type as enum * Display for integration types * Added sharepoint integration * Post processing functions in submodules (#16) --------- Co-authored-by: andhreljaKern <andrea.hrelja@kern.ai>
1 parent 31880f7 commit dcbd2e8

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

enums/enum-functions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InformationSourceType, LabelSource, SearchGroup, Slice, StaticOrderByKeys } from "./enums";
1+
import { InformationSourceType, IntegrationType, LabelSource, SearchGroup, Slice, StaticOrderByKeys } from "./enums";
22

33
export function informationSourceTypeToString(source: InformationSourceType, short: boolean, forDisplay: boolean = true) {
44
if (forDisplay) {
@@ -58,4 +58,10 @@ export function getOrderByDisplayName(orderByKey: string) {
5858
case StaticOrderByKeys.WEAK_SUPERVISION_CONFIDENCE: return "Weak Supervision Confidence";
5959
default: return orderByKey; //attributes
6060
}
61+
}
62+
63+
export const INTEGRATIONS_DISPLAY = {
64+
[IntegrationType.GITHUB_FILE]: "GitHub File",
65+
[IntegrationType.GITHUB_ISSUE]: "GitHub Issue",
66+
[IntegrationType.SHAREPOINT]: "SharePoint",
6167
}

enums/enums.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ export enum ModelsDownloadedStatus {
5252
DOWNLOADING = 'downloading',
5353
INITIALIZING = 'initializing',
5454
FAILED = 'failed',
55+
}
56+
57+
export enum IntegrationType {
58+
GITHUB_ISSUE = 'GITHUB_ISSUE',
59+
GITHUB_FILE = 'GITHUB_FILE',
60+
SHAREPOINT = 'SHAREPOINT',
5561
}

post-process-functions.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { jsonCopy } from "./general";
2+
3+
export function postProcessRecord(record: any, attributes: any[]) {
4+
const prepareRecord = jsonCopy(record);
5+
if (!prepareRecord.hasOwnProperty('data')) {
6+
if (prepareRecord.hasOwnProperty('fullRecordData')) {
7+
prepareRecord.data = prepareRecord.fullRecordData;
8+
}
9+
else if (prepareRecord.hasOwnProperty('recordData')) {
10+
prepareRecord.data = prepareRecord.recordData;
11+
} else {
12+
throw new Error("Cant find record data in record object");
13+
}
14+
}
15+
attributes.forEach((attribute, index) => {
16+
if (typeof prepareRecord.data[attribute.name] === 'boolean') {
17+
prepareRecord.data[attribute.name] = prepareRecord.data[attribute.name].toString();
18+
}
19+
});
20+
return prepareRecord;
21+
}
22+
23+
export function postProcessAttributes(attributes: any[]) {
24+
const prepareAttributes = jsonCopy(attributes);
25+
if (attributes && attributes.length > 0) {
26+
if (!attributes[0].hasOwnProperty('key')) {
27+
prepareAttributes.forEach((attribute, index) => {
28+
if (attribute.id !== null) {
29+
attribute.key = attribute.id;
30+
} else {
31+
throw new Error("Cant find attribute id in attribute object");
32+
}
33+
});
34+
}
35+
}
36+
return prepareAttributes;
37+
}
38+
39+
export function postProcessUpdateAndSortRecords(prev: any[], newRecords: any[]) {
40+
const merged = [...prev, ...newRecords];
41+
const uniqueRecords = Array.from(
42+
new Map(merged.map((item) => [item.data?.running_id, item])).values()
43+
);
44+
uniqueRecords.sort(
45+
(a, b) => (a.data?.running_id || 0) - (b.data?.running_id || 0)
46+
);
47+
return uniqueRecords;
48+
}

0 commit comments

Comments
 (0)