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