|
| 1 | +import { t } from "@lingui/macro"; |
1 | 2 | import { TabContext, TabList, TabPanel } from "@mui/lab"; |
2 | 3 | import { |
3 | 4 | Box, |
4 | 5 | Button, |
5 | 6 | Drawer, |
6 | 7 | IconButton, |
| 8 | + Input, |
| 9 | + InputAdornment, |
7 | 10 | Tab, |
8 | 11 | Theme, |
9 | 12 | Typography, |
10 | 13 | } from "@mui/material"; |
11 | 14 | import { makeStyles } from "@mui/styles"; |
12 | | -import React from "react"; |
| 15 | +import React, { useMemo, useState } from "react"; |
13 | 16 |
|
14 | 17 | import { DataSource } from "@/configurator"; |
15 | 18 | import { DataSetMetadata } from "@/configurator/components/dataset-metadata"; |
@@ -112,6 +115,13 @@ const useStyles = makeStyles<Theme, { drawerTop?: number }>((theme) => { |
112 | 115 | marginTop: -3, |
113 | 116 | marginRight: 2, |
114 | 117 | }, |
| 118 | + search: { |
| 119 | + marginTop: theme.spacing(2), |
| 120 | + padding: "0px 12px", |
| 121 | + width: "100%", |
| 122 | + height: 40, |
| 123 | + minHeight: 40, |
| 124 | + }, |
115 | 125 | }; |
116 | 126 | }); |
117 | 127 |
|
@@ -261,10 +271,35 @@ const TabPanelData = ({ |
261 | 271 | dimensions: DimensionMetadataFragment[]; |
262 | 272 | }) => { |
263 | 273 | 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]); |
264 | 283 |
|
265 | 284 | return ( |
266 | 285 | <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) => ( |
268 | 303 | <Box key={d.iri}> |
269 | 304 | <Flex> |
270 | 305 | <Icon |
|
0 commit comments