Skip to content

Commit 52e1636

Browse files
committed
feat: refactor view and title components
Signed-off-by: Antonette Caldwell <[email protected]>
1 parent 65f54de commit 52e1636

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed

examples/next-14/components/Dashboard/View.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function View(props) {
4646
return (
4747
<>
4848
<div style={{ position: 'relative', height: '20px' }}>
49-
<ParentStyle>
49+
<ParentStyle>
5050
<CellStyle>
5151
{typeof value === 'object' && value !== null ? JSON.stringify(value) : value}
5252
</CellStyle>

examples/next-14/components/Dashboard/index.jsx

+82-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { ResourcesConfig } from './resources/config';
22
import TextTooltip from '../MesheryMeshInterface/TextTooltip';
33
import { KubernetesIcon } from '@layer5/sistent';
4-
import MesheryIcon from './MesheryIcon';
4+
import MesheryIcon from '../../icons/MesheryIcon';
55
import { TabPanel } from './TabPanel';
66
import Overview from './Overview';
77
import ResourcesSubMenu from './resources/ResourcesSubMenu';
88
import ResourcesTable from './resources/ResourcesTable';
99
import { withRouter } from 'next/router';
1010
import { DashboardTab } from '@/styles/DashboardTab';
1111
import { DashboardTabs } from '@/styles/DashboardTabs';
12+
import { DashboardLayout } from '@/styles/DashboardLayout';
13+
import { PaperSquare } from '@/styles/PaperSquare';
1214
import useDashboardRouter from '@/lib/hooks/useDashboardRouter';
1315

1416
const ResourceCategoryTabs = ['Overview', ...Object.keys(ResourcesConfig)];
1517

16-
function Dashboard() {
18+
/*
19+
export function Dashboard({ k8sconfig, selectedK8sContexts, updateProgress }) {
1720
const { resourceCategory, changeResourceTab, selectedResource, handleChangeSelectedResource } =
1821
useDashboardRouter();
1922
@@ -91,3 +94,80 @@ function Dashboard() {
9194
}
9295
9396
export default withRouter(Dashboard);
97+
*/
98+
99+
export function Dashboard({ k8sconfig, selectedK8sContexts, updateProgress }) {
100+
const { resourceCategory, changeResourceTab, selectedResource, handleChangeSelectedResource } =
101+
useDashboardRouter();
102+
103+
const getResourceCategoryIndex = (resourceCategory) => {
104+
return ResourceCategoryTabs.findIndex((resource) => resource === resourceCategory);
105+
};
106+
107+
const getResourceCategory = (index) => {
108+
return ResourceCategoryTabs[index];
109+
};
110+
111+
return (
112+
<DashboardLayout>
113+
<PaperSquare>
114+
<DashboardTabs
115+
indicatorColor="primary"
116+
variant="fullWidth"
117+
textColor="primary"
118+
allowScrollButtonsMobile
119+
scrollButtons="auto"
120+
value={getResourceCategoryIndex(resourceCategory)}
121+
onChange={(_e, val) => {
122+
changeResourceTab(getResourceCategory(val));
123+
}}
124+
>
125+
{ResourceCategoryTabs.map((resource, idx) => {
126+
return (
127+
<TextTooltip key={idx} title={`View ${resource}`} placement="top">
128+
<DashboardTab
129+
value={idx}
130+
key={resource}
131+
icon={
132+
resource === 'Overview' ? (
133+
<MesheryIcon width="28px" height="28px" />
134+
) : (
135+
<KubernetesIcon width="28px" height="28px" />
136+
)
137+
}
138+
/>
139+
</TextTooltip>
140+
);
141+
})}
142+
</DashboardTabs>
143+
</PaperSquare>
144+
{Object.keys(ResourcesConfig).map((resource, idx) => (
145+
<TabPanel value={resourceCategory} index={resource} key={resource}>
146+
{ResourcesConfig[resource].submenu ? (
147+
<ResourcesSubMenu
148+
key={idx}
149+
resource={ResourcesConfig[resource]}
150+
selectedResource={selectedResource}
151+
handleChangeSelectedResource={handleChangeSelectedResource}
152+
updateProgress={updateProgress}
153+
k8sConfig={k8sconfig}
154+
selectedK8sContexts={selectedK8sContexts}
155+
/>
156+
) : (
157+
<ResourcesTable
158+
key={idx}
159+
workloadType={resource}
160+
k8sConfig={k8sconfig}
161+
selectedK8sContexts={selectedK8sContexts}
162+
resourceConfig={ResourcesConfig[resource].tableConfig}
163+
menu={ResourcesConfig[resource].submenu}
164+
updateProgress={updateProgress}
165+
/>
166+
)}
167+
</TabPanel>
168+
))}
169+
</DashboardLayout>
170+
);
171+
}
172+
173+
export default Dashboard;

examples/next-14/components/Dashboard/resources/ResourcesTable.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ export function ResourcesTable(props) {
2121
const { updateProgress, k8sConfig, resourceConfig, submenu, workloadType, selectedK8sContexts } =
2222
props;
2323

24-
const { width } = useWindowDimensions();
24+
const { width } = useWindowDimensions();
2525
const { notify } = useNotification();
2626

27-
const connectionMetadataState = useSelector(
28-
(state) => state.connection.connectionMetadataState,
29-
);
27+
const connectionMetadataState = useSelector((state) => state.connection.connectionMetadataState);
3028

3129
const [meshSyncResources, setMeshSyncResources] = useState([]);
3230
const [loading, setLoading] = useState(false);

0 commit comments

Comments
 (0)