Skip to content

Commit

Permalink
feat: handle non_collassare_gli_elementi
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed May 30, 2024
1 parent ae6ee96 commit 50f699f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ const CartellaModulisticaView = ({ content }) => {
<DocRow
doc={doc}
key={doc['@id']}
items={items.length === 0 ? doc.items : items}
searchableText={searchableText}
/*se items.length ===0 significa che è stato fatto il match sul titolo del
documento, quindi devo mostrare tutti i suoi figli*/
collapsable={!content.non_collassare_gli_elementi}
items={
items.length === 0 ? doc.items : items
} /*se items.length ===0 significa che è stato fatto il match sul titolo del
documento, quindi devo mostrare tutti i suoi figli*/
/>
);
} else {
Expand All @@ -150,6 +152,7 @@ const CartellaModulisticaView = ({ content }) => {
doc={doc}
key={doc['@id']}
searchableText={searchableText}
collapsable={!content.non_collassare_gli_elementi}
/>
);
}
Expand All @@ -165,12 +168,17 @@ const CartellaModulisticaView = ({ content }) => {
section.items ? section.items.filter(filterItemsFN) : []
}
searchableText={searchableText}
collapsable={!content.non_collassare_gli_elementi}
/>
</div>
) : (
<div className="document-row-section" key={section['@id']}>
{/*file,immagine,link*/}
<DocRow doc={section} searchableText={searchableText} />
<DocRow
doc={section}
searchableText={searchableText}
collapsable={!content.non_collassare_gli_elementi}
/>
</div>
);
})}
Expand Down
46 changes: 25 additions & 21 deletions src/components/ItaliaTheme/View/CartellaModulisticaView/DocRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ const Downloads = ({ item, titleDoc, filteredWords }) => {
);
};

const DocRow = ({ doc, items, searchableText }) => {
const DocRow = ({ doc, items, searchableText, collapsable }) => {
const filteredWords = searchableText.split(' ');

const [itemOpen, setItemOpen] = useState(searchableText?.length > 0 ?? false);
const [itemOpen, setItemOpen] = useState(!collapsable);

useEffect(() => {
//se ho fatto una ricerca, espando l'elemento
if (searchableText?.length > 0) {
setItemOpen(true);
} else {
setItemOpen(false);
if (collapsable) {
if (searchableText?.length > 0) {
setItemOpen(true);
} else {
setItemOpen(false);
}
}
}, [searchableText]);
}, [searchableText, collapsable]);

const titleWrapper = (
<div
Expand Down Expand Up @@ -123,20 +125,22 @@ const DocRow = ({ doc, items, searchableText }) => {
<div id="headingAccordion" className="accordion-header doc">
{titleWrapper}
</div>
<button
onClick={() => {
setItemOpen(itemOpen ? false : true);
}}
aria-expanded={itemOpen}
aria-controls="collapsedContent"
aria-labelledby={`title-${doc.id}`}
>
<Icon
color="primary"
icon={itemOpen ? 'it-minus' : 'it-plus'}
padding={false}
/>
</button>
{collapsable && (
<button
onClick={() => {
setItemOpen(itemOpen ? false : true);
}}
aria-expanded={itemOpen}
aria-controls="collapsedContent"
aria-labelledby={`title-${doc.id}`}
>
<Icon
color="primary"
icon={itemOpen ? 'it-minus' : 'it-plus'}
padding={false}
/>
</button>
)}
</div>
<div
id="collapsedContent"
Expand Down

0 comments on commit 50f699f

Please sign in to comment.