Skip to content

Commit 0159f38

Browse files
authored
feat: Add custom JSON table tab w/ formatting (#2851)
* Add metadata tab functionality Signed-off-by: Daniel Kim <[email protected]> * Undo unnecessary changes and bring back Regular FV Demo Tab Signed-off-by: Daniel Kim <[email protected]> * Change metadata tab to accept custom JSON file input. Signed-off-by: Daniel Kim <[email protected]> * Rename instances of metadata to data Signed-off-by: Daniel Kim <[email protected]>
1 parent 0ec7d1a commit 0159f38

File tree

6 files changed

+144
-3
lines changed

6 files changed

+144
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useQuery } from "react-query";
2+
3+
interface DataQueryInterface {
4+
featureView: string | undefined;
5+
}
6+
7+
const DataQuery = (featureView: string) => {
8+
const queryKey = `data-tab-namespace:${featureView}`;
9+
10+
return useQuery<any>(
11+
queryKey,
12+
() => {
13+
// Customizing the URL based on your needs
14+
const url = `/demo-custom-tabs/demo.json`;
15+
16+
return fetch(url)
17+
.then((res) => res.json())
18+
},
19+
{
20+
enabled: !!featureView, // Only start the query when the variable is not undefined
21+
}
22+
);
23+
};
24+
25+
export default DataQuery;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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;

ui/src/custom-tabs/reguar-fv-demo-tab/DemoCustomTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ const DemoCustomTab = ({
8282
);
8383
};
8484

85-
export default DemoCustomTab;
85+
export default DemoCustomTab;

ui/src/custom-tabs/reguar-fv-demo-tab/useDemoQuery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ const useDemoQuery = ({ featureView }: DemoQueryInterface) => {
4141
};
4242

4343
export default useDemoQuery;
44-
export type { DemoDataType };
44+
export type { DemoDataType };

ui/src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import FeastUI from "./FeastUI";
1515
// 3. Register the tab in the appropriate array below. Each entry
1616
// is a record with three keys: label, path, and Component.
1717
// Import your component and pass it as Component
18+
import DataTab from "./custom-tabs/data-tab/DataTab";
1819
import RFVDemoCustomTab from "./custom-tabs/reguar-fv-demo-tab/DemoCustomTab";
1920
import ODFVDemoCustomTab from "./custom-tabs/ondemand-fv-demo-tab/DemoCustomTab";
2021
import FSDemoCustomTab from "./custom-tabs/feature-service-demo-tab/DemoCustomTab";
@@ -32,6 +33,11 @@ const tabsRegistry = {
3233
path: "demo-tab", // Subpath for the tab
3334
Component: RFVDemoCustomTab,
3435
},
36+
{
37+
label: "Data Tab Demo", // Navigation Label for the tab
38+
path: "data-tab", // Subpath for the tab
39+
Component: DataTab,
40+
},
3541
],
3642
OnDemandFeatureViewCustomTabs: [
3743
{

ui/src/queries/useLoadFeatureViewSummaryStatistics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const useLoadFeatureViewSummaryStatistics = (featureViewName: string) => {
99
const { projectName } = useParams();
1010

1111
const queryKey = `featureViewSummaryStatistics:${featureViewName}`;
12-
const url = `/metadata/${projectName}/featureView/${featureViewName}.json`;
12+
const url = `/data/${projectName}/featureView/${featureViewName}.json`;
1313

1414
return useQuery(
1515
queryKey,

0 commit comments

Comments
 (0)