-
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.
* OK-683 nollataan lähetysten sivutus jos hakukriteeri muuttuu * Mui v6 TreeSelectin migraatio * OK-713 korjattu organisaatiovalinta ja päivitetty käyttämään uusia mui-komponentteja * OK-713 passataan kieli parametrina eikä hookin kautta organsaatiopuulle, parametrin uudelleennimentä ja sivutuksen nollaus organisaation vaihtuessa * OK-683 nollataan sivutus myös vastaanottajalistalla jos hakukriteeri muuttuu
- Loading branch information
Showing
10 changed files
with
239 additions
and
188 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
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
109 changes: 34 additions & 75 deletions
109
viestinvalitys-raportointi/src/app/components/OrganisaatioHierarkia.tsx
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,83 +1,42 @@ | ||
'use client'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
import ChevronRightIcon from '@mui/icons-material/ChevronRight'; | ||
import { TreeItem, TreeView } from '@mui/x-tree-view'; | ||
import { TreeItem2, TreeItem2Props, TreeItem2SlotProps } from '@mui/x-tree-view'; | ||
import { LanguageCode, Organisaatio } from '../lib/types'; | ||
import { FormControl, FormControlLabel, Radio } from '@mui/material'; | ||
import { ChangeEvent, SyntheticEvent } from 'react'; | ||
import { translateOrgName } from '../lib/util'; | ||
import { useLocale, useTranslations } from 'next-intl'; | ||
import React from 'react'; | ||
import { RadioButtonChecked, RadioButtonUnchecked } from '@mui/icons-material'; | ||
|
||
type Props = { | ||
organisaatiot: Organisaatio[]; | ||
selectedOid: string | undefined; | ||
expandedOids: string[]; | ||
handleSelect: (event: SyntheticEvent<Element, Event>, nodeId: string) => void; | ||
handleChange: (event: ChangeEvent<HTMLInputElement>) => void; | ||
handleToggle: (event: SyntheticEvent<Element, Event>, nodeIds: string[]) => void; | ||
} | ||
|
||
const OrganisaatioHierarkia = ({ | ||
organisaatiot, | ||
selectedOid, | ||
expandedOids, | ||
handleSelect, | ||
handleChange, | ||
handleToggle, | ||
}: Props) => { | ||
const lng = useLocale() as LanguageCode; | ||
const t = useTranslations(); | ||
const renderTree = (org: Organisaatio) => { | ||
if (!org) { | ||
return null; | ||
} | ||
return ( | ||
<TreeItem | ||
key={org.oid} | ||
// @ts-expect-error: Tässä kohtaa tyypitys menee hankalaksi | ||
nodeId={org.oid} | ||
label={ | ||
<FormControl> | ||
<FormControlLabel | ||
label={translateOrgName(org, lng)} | ||
control={ | ||
<Radio | ||
checked={selectedOid === org.oid} | ||
name="organisaatio" | ||
value={org.oid} | ||
onChange={(e) => { | ||
handleChange(e); | ||
}} | ||
/> | ||
} | ||
/> | ||
</FormControl> | ||
} | ||
> | ||
{Array.isArray(org.children) | ||
? org.children.map((node) => renderTree(node)) | ||
: null} | ||
</TreeItem> | ||
); | ||
}; | ||
const CustomTreeItem = React.forwardRef(function CustomTreeItem( | ||
props: TreeItem2Props, | ||
ref: React.Ref<HTMLLIElement>, | ||
) { | ||
return ( | ||
<TreeItem2 | ||
{...props} | ||
ref={ref} | ||
slotProps= {{ | ||
checkbox: { | ||
icon: <RadioButtonUnchecked />, | ||
checkedIcon: <RadioButtonChecked />, | ||
}, | ||
} as TreeItem2SlotProps | ||
} | ||
/> | ||
); | ||
}); | ||
|
||
export const OrganisaatioTree = (org: Organisaatio, lng: LanguageCode) => { | ||
if (!org) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<TreeView | ||
multiSelect={false} | ||
aria-label={t('organisaatio.label')} | ||
// @ts-expect-error: Tässä kohtaa tyypitys menee hankalaksi | ||
defaultCollapseIcon={<ExpandMoreIcon />} | ||
defaultExpandIcon={<ChevronRightIcon />} | ||
onNodeSelect={handleSelect} | ||
onNodeToggle={handleToggle} | ||
selected={selectedOid} | ||
expanded={expandedOids} | ||
> | ||
{organisaatiot.map((org) => renderTree(org))} | ||
</TreeView> | ||
</> | ||
<CustomTreeItem | ||
itemId={org.oid} | ||
key={org.oid} | ||
label={translateOrgName(org, lng)} | ||
> | ||
{Array.isArray(org.children) | ||
? org.children.map((node) => OrganisaatioTree(node, lng)) | ||
: null} | ||
</CustomTreeItem> | ||
); | ||
}; | ||
|
||
export default OrganisaatioHierarkia; |
Oops, something went wrong.