-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathDataTab.tsx
More file actions
101 lines (91 loc) · 2.46 KB
/
DataTab.tsx
File metadata and controls
101 lines (91 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from "react";
import { z } from "zod";
import {
EuiCode,
EuiFlexGroup,
EuiHorizontalRule,
EuiLoadingSpinner,
EuiTable,
EuiTitle,
EuiTableHeader,
EuiTableHeaderCell,
EuiPanel,
EuiFlexItem,
EuiTableRow,
EuiTableRowCell,
} from "@elastic/eui";
import DataQuery from "./DataQuery";
const FeatureViewDataRow = z.object({
name: z.string(),
value: z.string(),
});
type FeatureViewDataRowType = z.infer<typeof FeatureViewDataRow>;
const LineHeightProp: React.CSSProperties = {
lineHeight: 1,
};
const EuiFeatureViewDataRow = ({ name, value }: FeatureViewDataRowType) => {
return (
<EuiTableRow>
<EuiTableRowCell>{name}</EuiTableRowCell>
<EuiTableRowCell textOnly={false}>
<EuiCode data-code-language="text">
<pre style={LineHeightProp}>{value}</pre>
</EuiCode>
</EuiTableRowCell>
</EuiTableRow>
);
};
const FeatureViewDataTable = (data: any) => {
var items: FeatureViewDataRowType[] = [];
for (let element in data.data) {
const row: FeatureViewDataRowType = {
name: element,
value: JSON.stringify(data.data[element], null, 2),
};
items.push(row);
console.log(row);
}
return (
<EuiTable>
<EuiTableHeader>
<EuiTableHeaderCell>Data Item Name</EuiTableHeaderCell>
<EuiTableHeaderCell>Data Item Value</EuiTableHeaderCell>
</EuiTableHeader>
{items.map((item) => {
return <EuiFeatureViewDataRow name={item.name} value={item.value} />;
})}
</EuiTable>
);
};
const DataTab = () => {
const fName = "credit_history";
const { isLoading, isError, isSuccess, data } = DataQuery(fName);
const isEmpty = data === undefined;
return (
<React.Fragment>
{isLoading && (
<React.Fragment>
<EuiLoadingSpinner size="m" /> Loading
</React.Fragment>
)}
{isEmpty && <p>No feature view with name: {fName}</p>}
{isError && <p>Error loading feature view: {fName}</p>}
{isSuccess && data && (
<React.Fragment>
<EuiFlexGroup>
<EuiFlexItem>
<EuiPanel hasBorder={true}>
<EuiTitle size="xs">
<h3>Properties</h3>
</EuiTitle>
<EuiHorizontalRule margin="xs" />
<FeatureViewDataTable data={data} />
</EuiPanel>
</EuiFlexItem>
</EuiFlexGroup>
</React.Fragment>
)}
</React.Fragment>
);
};
export default DataTab;