expFunction.ts 1.26 KB
Newer Older
Lijiaoa's avatar
Lijiaoa committed
1
2
import { AllExperimentList, SortInfo } from '@static/interface';
import { copyAndSort } from '@static/function';
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

function compareDate(date1: Date, date2: Date): boolean {
    if (date1 !== undefined && date2 !== undefined) {
        if (date1.getFullYear() === date2.getFullYear()) {
            if (date1.getMonth() === date2.getMonth()) {
                if (date1.getDate() === date2.getDate()) {
                    return true;
                }
            }
        }
    }

    return false;
}

18
19
20
21
22
23
24
25
26
27
28
29
30
31
const filterByStatusOrPlatform = (
    val: string | string[],
    type: string,
    data: AllExperimentList[]
): AllExperimentList[] => {
    if (typeof val === 'string' && val !== '') {
        return data.filter(temp => temp[type] === val);
    }

    if (Array.isArray(val) && val.length !== 0) {
        return data.filter(temp => val.includes(temp[type]));
    }

    return data;
32
33
34
};

function fillOptions(arr: string[]): any {
35
    return arr.map(item => ({ key: item, text: item }));
36
37
38
39
40
41
42
43
}

function getSortedSource(source: AllExperimentList[], sortInfo: SortInfo): AllExperimentList[] {
    const keepSortedSource = copyAndSort(source, sortInfo.field, sortInfo.isDescend);
    return keepSortedSource;
}

export { compareDate, filterByStatusOrPlatform, fillOptions, getSortedSource };