Skip to content

Commit 9b3f6b2

Browse files
committed
feat(semantic-search): Refactor and enhance component PART 2
1 parent b544a95 commit 9b3f6b2

File tree

10 files changed

+110
-170
lines changed

10 files changed

+110
-170
lines changed

locales/de-global.json5

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,13 @@
1919
attribution: 'Attribution',
2020
changelog: 'Versionshistorie',
2121
},
22-
applicationMenu: {
23-
about: 'Über ESID',
24-
accessibility: 'Barrierefreiheit',
25-
changelog: 'Änderungsprotokoll',
26-
imprint: 'Impressum',
27-
privacyPolicy: 'Datenschutzerklärung',
28-
termsOfUse: 'Nutzungsbedingungen',
29-
},
30-
scenarioSelector: {
31-
label: 'Szenario',
32-
},
33-
tour: 'Tour',
3422
},
3523
'icon-bar': {
3624
'previous-day-tooltip': 'Vorheriger Tag',
3725
'next-day-tooltip': 'Nächster Tag',
3826
'play-pause-tooltip': 'Start/Pause',
3927
'fullscreen-tooltip': 'Vollbild',
4028
},
41-
history: {
42-
placeholder: 'history',
43-
title: 'Verlauf',
44-
},
4529
BEZ: {
4630
K: 'Kreis',
4731
LK: 'Landkreis',
@@ -132,12 +116,6 @@
132116
today: 'Heute',
133117
more: 'Mehr',
134118
less: 'Weniger',
135-
search: {
136-
articles: {
137-
placeholder: 'Artikel suchen...',
138-
ariaLabel: 'Suchen Sie nach Artikeln und Dokumentationen',
139-
},
140-
},
141119
germany: 'Deutschland',
142120
WIP: 'Diese Funktionalität befindet sich noch in der Entwicklung.',
143121
'no-data': 'Keine Daten',
@@ -154,7 +132,6 @@
154132
purpose: 'Was ist der Zweck von ESID?',
155133
},
156134
results: {
157-
initialPrompt: 'Geben Sie eine Frage ein, um nach relevanten Artikeln und Dokumentationen zu suchen.',
158135
noResults: 'Keine Ergebnisse gefunden. Versuchen Sie, Ihre Frage umzuformulieren oder andere Schlüsselwörter zu verwenden.',
159136
resultsFound_one: '1 Ergebnis gefunden für',
160137
resultsFound_other: '{{count}} Ergebnisse gefunden für',
@@ -164,11 +141,6 @@
164141
high: 'Hohe Relevanz',
165142
related: 'Verwandt',
166143
},
167-
pagination: {
168-
previous: 'Zurück',
169-
next: 'Weiter',
170-
pageOf: 'Seite {{current}} von {{total}}',
171-
},
172144
},
173145
language: 'Sprache',
174146
legal: {
@@ -235,11 +207,4 @@
235207
reset: 'Auf Standardwert zurücksetzen',
236208
r0: 'Basisreproduktionszahl (R0)',
237209
},
238-
history: {
239-
title: 'Verlauf',
240-
},
241-
language: 'Sprache',
242-
legal: {
243-
attributions: 'Namensnennung',
244-
},
245210
}

locales/en-global.json5

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@
1919
attribution: 'Attribution',
2020
changelog: 'Changelog',
2121
},
22-
applicationMenu: {
23-
about: 'About ESID',
24-
accessibility: 'Accessibility',
25-
changelog: 'Changelog',
26-
imprint: 'Imprint',
27-
privacyPolicy: 'Privacy Policy',
28-
termsOfUse: 'Terms of Use',
29-
},
30-
scenarioSelector: {
31-
label: 'Scenario',
32-
},
33-
tour: 'Tour',
3422
},
3523
'icon-bar': {
3624
'previous-day-tooltip': 'Previous Day',
@@ -45,7 +33,6 @@
4533
placeholder: 'Main Content',
4634
},
4735
history: {
48-
Tabtitle: 'history',
4936
title: 'History',
5037
},
5138
details: {
@@ -141,12 +128,6 @@
141128
today: 'Today',
142129
more: 'More',
143130
less: 'Less',
144-
search: {
145-
articles: {
146-
placeholder: 'Search articles...',
147-
ariaLabel: 'Search for articles and documentation',
148-
},
149-
},
150131
germany: 'Germany',
151132
'no-data': 'No Data',
152133
'loki-logo': 'LOKI logo',
@@ -172,7 +153,6 @@
172153
purpose: 'What is ESID purpose?',
173154
},
174155
results: {
175-
initialPrompt: 'Enter a question to search for relevant articles and documentation.',
176156
noResults: 'No results found. Try rephrasing your question or using different keywords.',
177157
resultsFound_one: 'Found 1 result for',
178158
resultsFound_other: 'Found {{count}} results for',
@@ -182,11 +162,6 @@
182162
high: 'High Relevance',
183163
related: 'Related',
184164
},
185-
pagination: {
186-
previous: 'Previous',
187-
next: 'Next',
188-
pageOf: 'Page {{current}} of {{total}}',
189-
},
190165
},
191166
language: 'Language',
192167
legal: {
@@ -253,8 +228,4 @@
253228
reset: 'Reset to default value',
254229
r0: 'Basic Reproduction Number (R0)',
255230
},
256-
language: 'Language',
257-
legal: {
258-
attributions: 'Attributions',
259-
},
260231
}

src/components/OnboardingComponents/SemanticSearch/ArticleDialog.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
4040
const [zoom, setZoom] = useState(1);
4141
const containerRef = useRef<HTMLDivElement>(null);
4242

43+
// Effect to register ResizeObserver to adjust Dialog to window resizes.
4344
useEffect(() => {
4445
const observer = new ResizeObserver((entries: ResizeObserverEntry[]) => {
4546
const entry = entries[0];
@@ -55,6 +56,7 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
5556
return () => {
5657
observer.disconnect();
5758
};
59+
// Runs once to initialize the observer.
5860
}, []);
5961

6062
const goToNextPage = useCallback(() => {
@@ -77,12 +79,14 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
7779
setZoom(1);
7880
}, []);
7981

80-
// Keyboard shortcuts for zoom and navigation
82+
// Effect to handle keyboard shortcuts for zoom and navigation.
8183
useEffect(() => {
8284
const handleKeyDown = (event: KeyboardEvent) => {
8385
if (!open) return;
8486

8587
switch (event.key) {
88+
// Listen for both '+' and '=' for zooming in. On many keyboards (like the US QWERTY),
89+
// '+' is the shifted version of the '=' key, so this makes the shortcut more reliable.
8690
case '+':
8791
case '=':
8892
if (event.ctrlKey || event.metaKey) {
@@ -129,7 +133,8 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
129133

130134
function onDocumentLoadSuccess({numPages: nextNumPages}: {numPages: number}) {
131135
setNumPages(nextNumPages);
132-
setPageNumber(1); // Reset to first page on new document load
136+
// Reset to first page on new document load
137+
setPageNumber(1);
133138
}
134139

135140
return (
@@ -141,8 +146,14 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
141146
scroll='paper'
142147
sx={{'& .MuiDialog-paper': {height: '90vh'}}}
143148
>
144-
<DialogTitle sx={{m: 0, p: 6, pb: 5}}>
145-
<Typography variant='h2' sx={{pr: '2rem'}}>
149+
<DialogTitle
150+
sx={{
151+
margin: 0,
152+
padding: 6,
153+
paddingBottom: 5,
154+
}}
155+
>
156+
<Typography variant='h2' sx={{paddingRight: '2rem'}}>
146157
{article.title}
147158
</Typography>
148159
<IconButton
@@ -161,7 +172,12 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
161172
<DialogContent
162173
ref={containerRef}
163174
dividers
164-
sx={{display: 'flex', flexDirection: 'column', alignItems: 'center', p: 1}}
175+
sx={{
176+
display: 'flex',
177+
flexDirection: 'column',
178+
alignItems: 'center',
179+
padding: 1,
180+
}}
165181
>
166182
<Document
167183
file={article.hyperlink}
@@ -172,7 +188,15 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
172188
<Page pageNumber={pageNumber} width={containerWidth > 0 ? containerWidth : undefined} scale={zoom} />
173189
</Document>
174190
</DialogContent>
175-
<Box sx={{display: 'flex', justifyContent: 'center', alignItems: 'center', p: 1, gap: 2}}>
191+
<Box
192+
sx={{
193+
display: 'flex',
194+
justifyContent: 'center',
195+
alignItems: 'center',
196+
padding: 1,
197+
gap: 2,
198+
}}
199+
>
176200
<IconButton onClick={goToPreviousPage} disabled={pageNumber <= 1} aria-label='previous page'>
177201
<ArrowBackIosNewIcon />
178202
</IconButton>
@@ -182,7 +206,7 @@ export default function ArticleDialog({open, onClose, article}: ArticleDialogPro
182206
<IconButton onClick={goToNextPage} disabled={pageNumber >= numPages} aria-label='next page'>
183207
<ArrowForwardIosIcon />
184208
</IconButton>
185-
<Box sx={{display: 'flex', alignItems: 'center', gap: 1, ml: 2}}>
209+
<Box sx={{display: 'flex', alignItems: 'center', gap: 1, marginLeft: 2}}>
186210
<Tooltip title='Zoom Out (Ctrl/Cmd + -)'>
187211
<IconButton onClick={handleZoomOut} disabled={zoom <= 0.25} aria-label='zoom out'>
188212
<ZoomOutIcon />

src/components/OnboardingComponents/SemanticSearch/QuerySuggestions.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import React, {useCallback, useMemo} from 'react';
5-
import {Box, Chip, Typography} from '@mui/material';
5+
import {Box, Chip, Typography, alpha, useTheme} from '@mui/material';
66
import {useTranslation} from 'react-i18next';
77
import {Localization} from 'types/localization';
88

@@ -23,6 +23,7 @@ export default function QuerySuggestions({
2323
onSuggestionClick,
2424
localization,
2525
}: QuerySuggestionsProps): JSX.Element {
26+
const theme = useTheme();
2627
const {t: defaultT, i18n} = useTranslation();
2728

2829
const memoizedLocalization = useMemo(
@@ -44,11 +45,28 @@ export default function QuerySuggestions({
4445
);
4546

4647
return (
47-
<Box mb={2}>
48-
<Typography variant='caption' sx={{color: 'GrayText', mb: 1, display: 'block'}}>
48+
<Box
49+
sx={{
50+
marginBottom: 2,
51+
}}
52+
>
53+
<Typography
54+
variant='caption'
55+
sx={{
56+
color: 'GrayText',
57+
marginBottom: 1,
58+
display: 'block',
59+
}}
60+
>
4961
{tOverride('semanticSearch.suggestions.title')}
5062
</Typography>
51-
<Box display='flex' flexWrap='wrap' gap={1}>
63+
<Box
64+
sx={{
65+
display: 'flex',
66+
flexWrap: 'wrap',
67+
gap: 1,
68+
}}
69+
>
5270
{suggestions.map((suggestion) => (
5371
<Chip
5472
key={suggestion}
@@ -61,7 +79,8 @@ export default function QuerySuggestions({
6179
borderColor: 'primary.light',
6280
color: 'primary.main',
6381
'&:hover': {
64-
backgroundColor: 'primary.main_10', // Assuming a 10% opacity color from your theme
82+
// Applying the primary color at 10% opacity from the theme.
83+
backgroundColor: alpha(theme.palette.primary.main, 0.1),
6584
borderColor: 'primary.main',
6685
},
6786
}}

src/components/OnboardingComponents/SemanticSearch/SemanticSearchContainer.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {useSemanticSearch} from 'context/SemanticSearchContext';
77
import QuerySuggestions from './QuerySuggestions';
88
import {useTranslation} from 'react-i18next';
99
import SearchIcon from '@mui/icons-material/Search';
10-
import {useAppDispatch, useAppSelector} from 'store/hooks';
11-
import {setSemanticSearchQuery} from 'store/SemanticSearchSlice';
1210
import SearchResultsList from './SearchResultsList';
1311
import ArticleDialog from './ArticleDialog';
1412
import {SearchResult} from 'types/semanticSearch';
@@ -19,19 +17,16 @@ import {Localization} from 'types/localization';
1917
* It will manage the search state and orchestrate the child components.
2018
*/
2119
export default function SemanticSearchContainer({localization}: {localization?: Localization}): JSX.Element {
22-
const {searchResults, isLoading, performSearch, clearSearch} = useSemanticSearch();
23-
const dispatch = useAppDispatch();
24-
const query = useAppSelector((state) => state.semanticSearch.searchQuery);
25-
const searchStatus = useAppSelector((state) => state.semanticSearch.searchStatus);
20+
const {searchResults, isLoading, performSearch, clearSearch, searchStatus} = useSemanticSearch();
21+
const [query, setQuery] = useState('');
2622
const {t: defaultT, i18n} = useTranslation();
2723
const [selectedArticle, setSelectedArticle] = useState<SearchResult | null>(null);
2824

2925
useEffect(() => {
3026
return () => {
31-
dispatch(setSemanticSearchQuery(''));
3227
clearSearch();
3328
};
34-
}, [dispatch, clearSearch]);
29+
}, [clearSearch]);
3530

3631
const memoizedLocalization = useMemo(
3732
() =>
@@ -68,12 +63,12 @@ export default function SemanticSearchContainer({localization}: {localization?:
6863
};
6964

7065
const handleClear = () => {
71-
dispatch(setSemanticSearchQuery(''));
66+
setQuery('');
7267
clearSearch();
7368
};
7469

7570
const handleSuggestionClick = (suggestion: string) => {
76-
dispatch(setSemanticSearchQuery(suggestion));
71+
setQuery(suggestion);
7772
if (performSearch) {
7873
performSearch(suggestion);
7974
}
@@ -103,7 +98,7 @@ export default function SemanticSearchContainer({localization}: {localization?:
10398
variant='outlined'
10499
placeholder={tOverride('semanticSearch.placeholder')}
105100
value={query}
106-
onChange={(e) => dispatch(setSemanticSearchQuery(e.target.value))}
101+
onChange={(e) => setQuery(e.target.value)}
107102
onKeyDown={(e) => {
108103
if (e.key === 'Enter') {
109104
handleSearch();

0 commit comments

Comments
 (0)