-
-
Notifications
You must be signed in to change notification settings - Fork 14
1096 arborescence des thématiques + multi sélection de thématique #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "1096-arborescence-des-th\u00E9matiques-+-multi-s\u00E9lection-de-th\u00E9matique"
Changes from all commits
f6c0fd2
8d5f306
3f8b3d2
4d78c4c
ddfb916
39c9c80
05ab089
e421908
db9a2c4
73f409d
141b1fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import React from 'react'; | ||
| import { useGetList } from 'react-admin'; | ||
| import {TreeItem, TreeView, useTreeItem} from '@mui/lab'; | ||
| import { useListFilterContext } from 'ra-core'; | ||
| import LabelIcon from '@mui/icons-material/Label'; | ||
| import { IconButton } from '@mui/material'; | ||
| import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
| import ChevronRightIcon from '@mui/icons-material/ChevronRight'; | ||
| import clsx from 'clsx'; | ||
| import Typography from '@mui/material/Typography'; | ||
|
|
||
| /** | ||
| * @example | ||
| * const FilterAside = () => ( | ||
| * <Card> | ||
| * <CardContent> | ||
| * <FilterLiveSearch source="pair:label" /> | ||
| * <ReferenceFilterTree | ||
| * reference="Theme" | ||
| * source="pair:broader" | ||
| * label="pair:label" | ||
| * icon={icon} | ||
| * predicate={"http://virtual-assembly.org/ontologies/pair#hasTopic"} | ||
| * /> | ||
| * </CardContent> | ||
| * </Card> | ||
| * ); | ||
| */ | ||
|
|
||
| function GenerateTreeItem(source, label, allItems, routeTree, parentId) { | ||
| // If !parentId it's a trunkItem | ||
| const isParentLevel = !parentId; | ||
| const listToUse = isParentLevel ? routeTree : allItems.filter(({ [source]: itemSource }) => itemSource === parentId); | ||
| return ( | ||
| listToUse.map((route) => | ||
| <CustomTreeItem nodeId={route["id"]} label={route[label]} key={route["id"]}> | ||
| {GenerateTreeItem(source, label, allItems, [], route["id"])} | ||
| </CustomTreeItem> | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| const CustomContent = React.forwardRef(function CustomContent(props, ref) { | ||
| const { | ||
| classes, | ||
| className, | ||
| label, | ||
| nodeId, | ||
| icon: iconProp, | ||
| expansionIcon, | ||
| displayIcon, | ||
| } = props; | ||
|
|
||
| const { | ||
| disabled, | ||
| expanded, | ||
| selected, | ||
| focused, | ||
| handleExpansion, | ||
| handleSelection, | ||
| preventSelection, | ||
| } = useTreeItem(nodeId); | ||
|
|
||
| const icon = iconProp || expansionIcon || displayIcon; | ||
|
|
||
| const handleMouseDown = (event) => { | ||
| preventSelection(event); | ||
| }; | ||
|
|
||
| const handleExpansionClick = (event) => { | ||
| handleExpansion(event); | ||
| }; | ||
|
|
||
| const handleSelectionClick = (event) => { | ||
| handleSelection(event); | ||
| }; | ||
|
|
||
| return ( | ||
| // eslint-disable-next-line jsx-a11y/no-static-element-interactions | ||
| <div | ||
| className={clsx(className, classes.root, { | ||
| [classes.expanded]: expanded, | ||
| [classes.selected]: selected, | ||
| [classes.focused]: focused, | ||
| [classes.disabled]: disabled, | ||
| })} | ||
| onMouseDown={handleMouseDown} | ||
| ref={ref} | ||
| > | ||
| {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */} | ||
| <div onClick={handleExpansionClick} className={classes.iconContainer}> | ||
| {icon} | ||
| </div> | ||
| <Typography | ||
| onClick={handleSelectionClick} | ||
| component="div" | ||
| className={classes.label} | ||
| > | ||
| {label} | ||
| </Typography> | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| function CustomTreeItem(props) { | ||
| return <TreeItem ContentComponent={CustomContent} {...props} />; | ||
| } | ||
|
|
||
| const ReferenceFilterTree = ({ reference, source, label, limit, sort, filter, icon, predicate }) => { | ||
| const { data } = useGetList(reference, { page: 1, perPage: Infinity }, sort, filter); | ||
| const { filterValues, setFilters } = useListFilterContext(); | ||
|
|
||
| let routeTree = [], allItems = []; | ||
| for (const item in data) { | ||
| if (data[item][source] === undefined ) { | ||
| routeTree.push(data[item]); | ||
| } | ||
| allItems = allItems.concat(data[item]); | ||
| } | ||
|
|
||
| const handleSelect = (event, nodes) => { | ||
| const sparqlWhere = { | ||
| "type": "bgp", | ||
| "triples": nodes.map((node) => { | ||
| return { | ||
| subject: { | ||
| termType: 'Variable', | ||
| value: 's1', | ||
| }, | ||
| predicate: { | ||
| termType: 'NamedNode', | ||
| value: predicate, | ||
| }, | ||
| object: { | ||
| termType: 'NamedNode', | ||
| value: node, | ||
| }, | ||
| }; | ||
| }), | ||
| } | ||
|
|
||
| const encodedQuery = encodeURIComponent(JSON.stringify(sparqlWhere)); | ||
| setFilters({...filterValues, "sparqlWhere": encodedQuery }) | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| {!icon ? icon = <IconButton size="small" edge="start"> <LabelIcon style={{ color: 'black', }} /> </IconButton> : icon} | ||
| {reference} | ||
| <TreeView | ||
| multiSelect | ||
| onNodeSelect={handleSelect} | ||
| aria-label="icon expansion" | ||
| defaultCollapseIcon={<ExpandMoreIcon />} | ||
| defaultExpandIcon={<ChevronRightIcon />} | ||
| > | ||
| {GenerateTreeItem(source, label, allItems, routeTree)} | ||
| </TreeView> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| export default ReferenceFilterTree; | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.