Skip to content

Commit

Permalink
fix bug with search field uneditable
Browse files Browse the repository at this point in the history
also ake search text writable within similarity finder
  • Loading branch information
Sebastian Tilsch committed Jan 23, 2024
1 parent f8fd4ce commit fb41103
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
47 changes: 27 additions & 20 deletions apps/exhibition-live/components/form/SimilarityFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ import { Storage as KnowledgebaseIcon } from "@mui/icons-material";
import {
Badge,
Box,
Chip,
Divider,
Grid,
MenuItem,
Select,
Typography,
ToggleButton,
ToggleButtonGroup,
TextField,
} from "@mui/material";
import ClassicResultListWrapper from "./result/ClassicResultListWrapper";
import { dcterms } from "@tpluscode/rdf-ns-builders";
Expand Down Expand Up @@ -119,15 +114,22 @@ const SimilarityFinder: FunctionComponent<Props> = ({
search: globalSearch,
typeName: globalTypeName,
path: globalPath,
setSearch,
} = useGlobalSearch();
const { t } = useTranslation("translation");
const searchString = useMemo<string | null>(
() =>
(searchOnDataPath && Resolve.data(data, searchOnDataPath)) ||
globalSearch ||
search ||
null,
[data, searchOnDataPath, search, globalSearch],
const handleSearchStringChange = useCallback(
(value: string) => {
setSearch(value);
},
[setSearch],
);
const dataPathSearch = useMemo<string | undefined>(
() => searchOnDataPath && Resolve.data(data, searchOnDataPath),
[data, searchOnDataPath],
);
const searchString: string | undefined = useMemo<string | null>(
() => dataPathSearch || globalSearch || search || null,
[data, dataPathSearch, search, globalSearch],
);

const [typeName, setTypeName] = useState(
Expand Down Expand Up @@ -286,13 +288,18 @@ const SimilarityFinder: FunctionComponent<Props> = ({
}}
>
<Box sx={{ flexGrow: 1 }}>
<Typography gutterBottom variant="caption" component="div">
Suche in {selectedKnowledgeSources.join(",")} nach {t(typeName)}{" "}
({globalPath})
</Typography>
<Typography variant="body2" gutterBottom>
{searchString}
</Typography>
<TextField
variant={"standard"}
disabled={Boolean(dataPathSearch)}
fullWidth={true}
value={searchString || ""}
onChange={(e) =>
handleSearchStringChange(e.currentTarget.value)
}
label={`Suche in ${selectedKnowledgeSources.join(",")} nach ${t(
typeName,
)} `}
/>
</Box>
<Box
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const DiscoverAutocompleteInput: FunctionComponent<Props> = ({
// @ts-ignore
load={load}
initialQueryKey={typeIRI}
value={selectedValue || { label: "", value: null }}
value={selectedValue || { label: searchString, value: null }}
getOptionLabel={handleGetOptionLabel}
placeholder={`Suche nach ${typeName} in der aktuellen Datenbank`}
renderOption={(props, option: any) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export const useGlobalSearchWithHelper = (
const handleFocus = useCallback(() => {
setTypeName(typeName);
setPath(formsPath);
}, [setTypeName, typeName, setPath, formsPath]);
setSearch(searchString);
}, [searchString, setSearch, setTypeName, typeName, setPath, formsPath]);

return {
...globalSearch,
Expand Down

0 comments on commit fb41103

Please sign in to comment.