Skip to content

Commit 1f08db9

Browse files
committed
feat: Add searching to data panel
1 parent 67435c1 commit 1f08db9

5 files changed

Lines changed: 385 additions & 334 deletions

File tree

app/components/metadata-panel.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import { t } from "@lingui/macro";
12
import { TabContext, TabList, TabPanel } from "@mui/lab";
23
import {
34
Box,
45
Button,
56
Drawer,
67
IconButton,
8+
Input,
9+
InputAdornment,
710
Tab,
811
Theme,
912
Typography,
1013
} from "@mui/material";
1114
import { makeStyles } from "@mui/styles";
12-
import React from "react";
15+
import React, { useMemo, useState } from "react";
1316

1417
import { DataSource } from "@/configurator";
1518
import { DataSetMetadata } from "@/configurator/components/dataset-metadata";
@@ -112,6 +115,13 @@ const useStyles = makeStyles<Theme, { drawerTop?: number }>((theme) => {
112115
marginTop: -3,
113116
marginRight: 2,
114117
},
118+
search: {
119+
marginTop: theme.spacing(2),
120+
padding: "0px 12px",
121+
width: "100%",
122+
height: 40,
123+
minHeight: 40,
124+
},
115125
};
116126
});
117127

@@ -261,10 +271,35 @@ const TabPanelData = ({
261271
dimensions: DimensionMetadataFragment[];
262272
}) => {
263273
const classes = useStyles({});
274+
const [searchInput, setSearchInput] = useState("");
275+
276+
const filteredDimensions = useMemo(() => {
277+
return dimensions.filter(
278+
(d) =>
279+
d.label.toLowerCase().includes(searchInput) ||
280+
d.description?.toLowerCase().includes(searchInput)
281+
);
282+
}, [dimensions, searchInput]);
264283

265284
return (
266285
<TabPanel className={classes.tabPanel} value="data">
267-
{dimensions.map((d) => (
286+
{/* Extract into a component (as it's also used in MultiFilter drawer?) */}
287+
<Input
288+
className={classes.search}
289+
value={searchInput}
290+
onChange={(e) => setSearchInput(e.target.value.toLowerCase())}
291+
placeholder={t({
292+
id: "select.controls.metadata.search",
293+
message: "Jump to...",
294+
})}
295+
startAdornment={
296+
<InputAdornment position="start">
297+
<Icon name="search" size={16} />
298+
</InputAdornment>
299+
}
300+
sx={{ typography: "body2" }}
301+
/>
302+
{filteredDimensions.map((d) => (
268303
<Box key={d.iri}>
269304
<Flex>
270305
<Icon

0 commit comments

Comments
 (0)