Skip to content

Commit 91a6555

Browse files
authored
Merge pull request #224 from dgageot/2groups
Show tools in two groups
2 parents 51a0cd3 + ff0b7a9 commit 91a6555

File tree

1 file changed

+62
-20
lines changed

1 file changed

+62
-20
lines changed

src/extension/ui/src/components/tabs/ToolCatalog.tsx

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import React, { useMemo } from 'react';
2-
import { Grid2 } from '@mui/material';
3-
import Tile from '../tile/Index';
41
import { v1 } from '@docker/extension-api-client-types';
2+
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
3+
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
4+
import { Collapse, Grid2, Typography } from '@mui/material';
5+
import React, { useMemo, useState } from 'react';
56
import { CATALOG_LAYOUT_SX } from '../../Constants';
67
import { useCatalogAll } from '../../queries/useCatalog';
8+
import Tile from '../tile/Index';
79

810
interface ToolCatalogProps {
911
search: string;
@@ -19,6 +21,8 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
1921
sort,
2022
}) => {
2123
const { catalogItems, registryLoading } = useCatalogAll(client);
24+
const [expandedEnabled, setExpandedEnabled] = useState(true);
25+
const [expandedNotEnabled, setExpandedNotEnabled] = useState(true);
2226

2327
// Memoize the filtered catalog items to prevent unnecessary recalculations
2428
const result = useMemo(() => {
@@ -32,29 +36,67 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
3236

3337
return sort === 'name-asc'
3438
? filteredItems.sort((a, b) => {
35-
return a.name.localeCompare(b.name);
36-
})
39+
return a.name.localeCompare(b.name);
40+
})
3741
: sort === 'name-desc'
38-
? filteredItems.sort((a, b) => {
42+
? filteredItems.sort((a, b) => {
3943
return b.name.localeCompare(a.name);
4044
})
41-
: filteredItems;
45+
: filteredItems;
4246
}, [catalogItems, search, showMine, sort]);
4347

48+
49+
4450
return (
45-
<Grid2 container spacing={1} sx={CATALOG_LAYOUT_SX}>
46-
{result.map((catalogItem) => {
47-
return (
48-
<Grid2 size={{ xs: 12, sm: 6, md: 4 }} key={catalogItem.name}>
49-
<Tile
50-
item={catalogItem}
51-
client={client}
52-
registryLoading={registryLoading}
53-
/>
54-
</Grid2>
55-
);
56-
})}
57-
</Grid2>
51+
<>
52+
<Typography
53+
variant='subtitle2'
54+
sx={{ color: "text.secondary", display: "flex", alignItems: "center", cursor: "pointer" }}
55+
onClick={() => setExpandedEnabled(!expandedEnabled)}>
56+
Enabled tools
57+
{expandedEnabled ? <KeyboardArrowDownIcon fontSize="small" /> : <KeyboardArrowRightIcon fontSize="small" />}
58+
</Typography>
59+
60+
<Collapse in={expandedEnabled}>
61+
<Grid2 container spacing={1} sx={CATALOG_LAYOUT_SX}>
62+
{result.filter((item) => item.registered).map((catalogItem) => {
63+
return (
64+
<Grid2 size={{ xs: 12, sm: 6, md: 4 }} key={catalogItem.name}>
65+
<Tile
66+
item={catalogItem}
67+
client={client}
68+
registryLoading={registryLoading}
69+
/>
70+
</Grid2>
71+
);
72+
})}
73+
</Grid2>
74+
</Collapse>
75+
76+
<Typography
77+
variant='subtitle2'
78+
sx={{ color: "text.secondary", display: "flex", alignItems: "center", cursor: "pointer" }}
79+
onClick={() => setExpandedNotEnabled(!expandedNotEnabled)}>
80+
All the tools
81+
{expandedNotEnabled ? <KeyboardArrowDownIcon fontSize="small" /> : <KeyboardArrowRightIcon fontSize="small" />}
82+
</Typography>
83+
84+
<Collapse in={expandedNotEnabled}>
85+
<Grid2 container spacing={1} sx={CATALOG_LAYOUT_SX}>
86+
{result.filter((item) => true).map((catalogItem) => {
87+
return (
88+
<Grid2 size={{ xs: 12, sm: 6, md: 4 }} key={catalogItem.name}>
89+
<Tile
90+
item={catalogItem}
91+
client={client}
92+
registryLoading={registryLoading}
93+
/>
94+
</Grid2>
95+
);
96+
})}
97+
</Grid2>
98+
</Collapse>
99+
</>
58100
);
59101
};
60102

0 commit comments

Comments
 (0)