-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Opetushallitus/OK-498-hakukohteen-suodatt…
…imet Ok 498 hakukohteen suodattimet
- Loading branch information
Showing
10 changed files
with
312 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Oletko lisännyt tarvittavat yksikkö- tai ui-testit toiminnallisuudelle? Kyllä/En | ||
Oletko tarkistanut ja päivittänyt riippuvuudet? Kyllä/En | ||
Oletko kokeillut toimiiko käyttöliittymä mobiilissa landscape moodissa? Kyllä/En/Ei koske | ||
Oletko testannut että lisäämäsi toiminto on saavutettava? Kyllä/En/Ei koske |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use client'; | ||
|
||
import { styled, IconButton, FormLabel, CircularProgress } from '@mui/material'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import KeyboardDoubleArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight'; | ||
import HakukohdeList from './hakukohde-list'; | ||
import HakukohdeSearch from './hakukohde-search'; | ||
import { useState } from 'react'; | ||
import { colors } from '@/app/theme'; | ||
import { useTranslations } from '@/app/hooks/useTranslations'; | ||
import { QuerySuspenseBoundary } from '@/app/components/query-suspense-boundary'; | ||
|
||
const StyledPanel = styled('div')({ | ||
width: '20vw', | ||
textAlign: 'left', | ||
minHeight: '85vh', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
rowGap: '7px', | ||
paddingRight: '5px', | ||
alignItems: 'start', | ||
transition: 'width 300ms ease-in-out', | ||
['label, button']: { | ||
color: colors.blue2, | ||
maxWidth: '50px', | ||
alignSelf: 'end', | ||
marginRight: '15px', | ||
marginBottom: '5px', | ||
}, | ||
'&.minimized': { | ||
width: '50px', | ||
rowGap: '3px', | ||
['label, button']: { | ||
margin: 0, | ||
alignSelf: 'start', | ||
}, | ||
}, | ||
}); | ||
|
||
export const HakukohdePanel = ({ oid }: { oid: string }) => { | ||
const [minimized, setMinimized] = useState(false); | ||
const { t } = useTranslations(); | ||
|
||
return ( | ||
<StyledPanel className={minimized ? 'minimized' : ''}> | ||
{!minimized && ( | ||
<QuerySuspenseBoundary | ||
suspenseFallback={ | ||
<CircularProgress aria-label={t('yleinen.ladataan')} /> | ||
} | ||
> | ||
<IconButton | ||
sx={{ alignSelf: 'right', width: '1rem', height: '1rem' }} | ||
onClick={() => setMinimized(true)} | ||
aria-label={t('haku.pienenna')} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
<HakukohdeSearch /> | ||
|
||
<HakukohdeList hakuOid={oid} /> | ||
</QuerySuspenseBoundary> | ||
)} | ||
{minimized && ( | ||
<> | ||
<IconButton | ||
id="expand-button" | ||
name="expand-button" | ||
onClick={() => setMinimized(false)} | ||
aria-label={t('haku.suurenna')} | ||
> | ||
<KeyboardDoubleArrowRightIcon /> | ||
</IconButton> | ||
<FormLabel htmlFor="expand-button">{t('yleinen.haku')}</FormLabel> | ||
</> | ||
)} | ||
</StyledPanel> | ||
); | ||
}; | ||
|
||
export default HakukohdePanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useHakukohdeSearchParams } from '@/app/hooks/useHakukohdeSearch'; | ||
import { useTranslations } from '@/app/hooks/useTranslations'; | ||
import { Search } from '@mui/icons-material'; | ||
import { FormControl, InputAdornment, OutlinedInput } from '@mui/material'; | ||
import { ChangeEvent } from 'react'; | ||
|
||
export const HakukohdeSearch = () => { | ||
const { searchPhrase, setSearchPhrase } = useHakukohdeSearchParams(); | ||
const { t } = useTranslations(); | ||
const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setSearchPhrase(e.target.value); | ||
}; | ||
|
||
return ( | ||
<FormControl | ||
sx={{ | ||
flexGrow: 4, | ||
minWidth: '180px', | ||
textAlign: 'left', | ||
}} | ||
> | ||
<OutlinedInput | ||
id="hakukohde-search" | ||
name="hakukohde-search" | ||
defaultValue={searchPhrase} | ||
onChange={handleSearchChange} | ||
autoFocus={true} | ||
type="text" | ||
placeholder={t('haku.haehakukohde')} | ||
endAdornment={ | ||
<InputAdornment position="end"> | ||
<Search /> | ||
</InputAdornment> | ||
} | ||
/> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export default HakukohdeSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
'use client'; | ||
|
||
import { useTranslations } from '@/app/hooks/useTranslations'; | ||
import { colors } from '@/app/theme'; | ||
import { ListAlt } from '@mui/icons-material'; | ||
import { styled } from '@mui/material'; | ||
|
||
export default function HakuPage() { | ||
const { t } = useTranslations(); | ||
|
||
const Container = styled('div')({ | ||
textAlign: 'center', | ||
padding: '5rem 2rem 1rem', | ||
width: '70%', | ||
}); | ||
|
||
return ( | ||
<div style={{ alignSelf: 'center', width: '70%', padding: '1rem 2rem' }}> | ||
<Container> | ||
<ListAlt | ||
sx={{ | ||
borderRadius: '45px', | ||
backgroundColor: colors.grey50, | ||
padding: '15px', | ||
}} | ||
/> | ||
<h2>{t('hakukohde.valitse')}</h2> | ||
</div> | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use client'; | ||
import { useMemo } from 'react'; | ||
import { Hakukohde } from '../lib/kouta-types'; | ||
import { useDebounce } from '@/app/hooks/useDebounce'; | ||
import { useQueryState } from 'nuqs'; | ||
import { useSuspenseQuery } from '@tanstack/react-query'; | ||
import { HAKU_SEARCH_PHRASE_DEBOUNCE_DELAY } from '@/app/lib/constants'; | ||
import { useTranslations } from './useTranslations'; | ||
import { getHakukohteet } from '../lib/kouta'; | ||
import { useUserPermissions } from './useUserPermissions'; | ||
|
||
const DEFAULT_NUQS_OPTIONS = { | ||
history: 'push', | ||
clearOnDefault: true, | ||
defaultValue: '', | ||
} as const; | ||
|
||
export const useHakukohdeSearchParams = () => { | ||
const [searchPhrase, setSearchPhrase] = useQueryState( | ||
'hksearch', | ||
DEFAULT_NUQS_OPTIONS, | ||
); | ||
|
||
const setSearchDebounce = useDebounce( | ||
setSearchPhrase, | ||
HAKU_SEARCH_PHRASE_DEBOUNCE_DELAY, | ||
); | ||
|
||
return { | ||
searchPhrase, | ||
setSearchPhrase: setSearchDebounce, | ||
}; | ||
}; | ||
|
||
export const useHakukohdeSearchResults = (hakuOid: string) => { | ||
const { translateEntity } = useTranslations(); | ||
const { data: userPermissions } = useUserPermissions(); | ||
|
||
const { data: hakukohteet } = useSuspenseQuery({ | ||
queryKey: ['getHakukohteet' + hakuOid], | ||
queryFn: () => getHakukohteet(hakuOid, userPermissions), | ||
}); | ||
|
||
const { searchPhrase } = useHakukohdeSearchParams(); | ||
|
||
const results = useMemo(() => { | ||
return hakukohteet.filter( | ||
(hakukohde: Hakukohde) => | ||
translateEntity(hakukohde.nimi) | ||
.toLowerCase() | ||
.includes(searchPhrase?.toLowerCase() ?? '') || | ||
translateEntity(hakukohde.jarjestyspaikkaHierarkiaNimi) | ||
.toLowerCase() | ||
.includes(searchPhrase?.toLowerCase() || '') || | ||
hakukohde.oid.includes(searchPhrase?.toLowerCase() || ''), | ||
); | ||
}, [hakukohteet, searchPhrase]); | ||
|
||
return { | ||
results, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.