Skip to content

Commit b1d2cee

Browse files
authored
Merge branch 'main' into Hover_Cookie_Box
2 parents 46c671a + 0ec4bf9 commit b1d2cee

File tree

5 files changed

+128
-71
lines changed

5 files changed

+128
-71
lines changed

cypress/integration/pages/organizations.spec.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ describe('Organizations Page (using API)', () => {
6262
cy.get('[data-cy=organization-search]').type(affiliatedOrg).type('{enter}');
6363
cy.get('[data-cy=affiliated-organizations]').within(() => {
6464
cy.get('[data-cy=thumbnail-dropdown]').should('have.length', 1);
65-
cy.get('[data-cy=contributor-thumbnail-text]').contains(affiliatedOrg);
65+
cy.get('[data-cy=thumbnail-dropdown]').eq(0).click().within(() => {
66+
cy.get('[data-cy=contributor-thumbnail-text]').contains(affiliatedOrg);
67+
});
6668
});
6769
cy.get('[data-cy=affiliated-organizations]').within(() => {
6870
cy.get('[data-cy=thumbnail-dropdown]').should('have.length', parentOrgCount2);
6971
});
70-
cy.get('[data-cy=organization-search]').clear();
72+
cy.get('[data-cy=organization-search]').within(() => {
73+
cy.get('input').clear();
74+
});
7175
});
7276

7377
it('should find affiliatedOrg via partial search', () => {
@@ -81,9 +85,13 @@ describe('Organizations Page (using API)', () => {
8185
cy.get('[data-cy=organization-search-list]').click();
8286
cy.get('[data-cy=affiliated-organizations]').within(() => {
8387
cy.get('[data-cy=thumbnail-dropdown]').should('have.length', 1);
84-
cy.get('[data-cy=contributor-thumbnail-text]').contains(affiliatedOrg);
88+
cy.get('[data-cy=thumbnail-dropdown]').eq(0).click().within(() => {
89+
cy.get('[data-cy=contributor-thumbnail-text]').contains(affiliatedOrg);
90+
});
91+
});
92+
cy.get('[data-cy=organization-search]').within(() => {
93+
cy.get('input').clear();
8594
});
86-
cy.get('[data-cy=organization-search]').clear();
8795
});
8896

8997
it('should visit organizations page from home page link', () => {

src/components/Dropdown.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ const useStyles = makeStyles((theme) => ({
3636
}));
3737

3838
export const Dropdown = ({
39-
organization,
39+
checkboxValue,
4040
children,
4141
dropdownLength,
42-
isOpen,
43-
checkboxValue,
44-
inputValue,
4542
filtersActive,
43+
isOpen,
44+
onClick,
45+
organization,
4646
}) => {
4747
const [openChild, setOpenChild] = useState(isOpen ? true : false);
4848
const [colorStyle, setColor] = useState(isOpen ? true : false);
4949
const classes = useStyles();
5050

51-
const handleOpen = () => {
51+
const handleClick = () => {
52+
onClick(organization);
5253
setOpenChild(!openChild);
5354
setColor(!colorStyle);
5455
};
@@ -65,7 +66,7 @@ export const Dropdown = ({
6566
item
6667
xs={10}
6768
className={clsx(classes.dropdown, {
68-
[classes.open]: colorStyle === true,
69+
[classes.open]: isOpen,
6970
})}
7071
>
7172
<Grid>
@@ -74,7 +75,7 @@ export const Dropdown = ({
7475
filtersActive={filtersActive}
7576
checkboxValue={checkboxValue}
7677
dropdownLength={dropdownLength}
77-
isOpen={colorStyle}
78+
isOpen={isOpen}
7879
isChildThumbnail={false}
7980
/>
8081
</Grid>
@@ -83,12 +84,11 @@ export const Dropdown = ({
8384
item
8485
container
8586
className={classes.flexGrid}
86-
onClick={handleOpen}
87+
onClick={handleClick}
8788
>
8889
<DropdownArrow
89-
open={openChild}
90-
setOpenFunction={setOpenChild}
91-
handleArrow={handleOpen}
90+
open={isOpen}
91+
handleArrow={handleClick}
9292
/>
9393
</Grid>
9494
</Grid>
@@ -101,7 +101,7 @@ export const Dropdown = ({
101101
/>
102102
</Grid>
103103
)}
104-
{openChild && children}
104+
{isOpen && children}
105105
</Grid>
106106
);
107107
};

src/pages/Contributors/Affiliated.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,28 @@ const useStyles = makeStyles((theme) => ({
117117
},
118118
}));
119119
/* eslint complexity: [0, 0]*/
120-
export const Affiliated = (props) => {
121-
const {
122-
affiliatedCount,
123-
classes,
124-
inputValue,
125-
organizations,
126-
organizationData,
127-
filtersActive,
128-
totalAffiliatedCount,
129-
showIndexContrib,
130-
} = props;
120+
export const Affiliated = ({
121+
affiliatedCount,
122+
classes,
123+
expandedOrgs,
124+
inputValue,
125+
onOrgClick,
126+
organizations,
127+
organizationData,
128+
filtersActive,
129+
totalAffiliatedCount,
130+
showIndexContrib,
131+
}) => {
131132
const classesLocal = useStyles();
132133
const [dropdownOpen, setDropdownOpen] = useState(false);
133134
useEffect(() => {
134-
if (filtersActive && organizations.length) {
135+
if ((filtersActive || expandedOrgs.length) && organizations.length) {
135136
setDropdownOpen(true);
136137
} else {
137138
setDropdownOpen(false);
138139
}
139-
}, [filtersActive, organizations])
140+
}, [expandedOrgs, filtersActive, organizations])
141+
140142
return (
141143
<Grid>
142144
<Grid style={{ padding: '40px' }}>
@@ -221,11 +223,13 @@ export const Affiliated = (props) => {
221223
) : (
222224
<Grid item xs={12} sm={10} className={classesLocal.dropDownGrid}>
223225
<AffiliatedOrganizations
224-
organizations={organizations}
226+
expandedOrgs={expandedOrgs}
227+
filtersActive={filtersActive}
225228
inputValue={inputValue}
229+
onOrgClick={onOrgClick}
226230
organizationData={organizationData}
231+
organizations={organizations}
227232
showIndexContrib={showIndexContrib}
228-
filtersActive={filtersActive}
229233
/>
230234
</Grid>
231235
))}

src/pages/Contributors/AffiliatedOrganizations.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ const useStyles = makeStyles((theme) => ({
6464
}));
6565

6666
export const AffiliatedOrganizations = ({
67-
organizations,
67+
expandedOrgs,
68+
filtersActive,
6869
inputValue,
70+
onOrgClick,
6971
organizationData,
72+
organizations,
7073
showIndexContrib,
71-
filtersActive,
7274
}) => {
7375
const classes = useStyles();
7476

@@ -83,7 +85,7 @@ export const AffiliatedOrganizations = ({
8385
organizations.forEach((org) => {
8486
if (org.depth === 3) {
8587
org['childNodes'] = [];
86-
org['isOpen'] = false;
88+
org['allChildrenShown'] = false;
8789
parentdata.push(org);
8890
}
8991
if (org.depth === 4) {
@@ -99,7 +101,7 @@ export const AffiliatedOrganizations = ({
99101

100102
if (!exist) {
101103
mapsearchedChildParent['childNodes'] = [];
102-
mapsearchedChildParent['isOpen'] = false;
104+
mapsearchedChildParent['allChildrenShown'] = false;
103105
parentChildobj = mapsearchedChildParent;
104106
parentdata.push(mapsearchedChildParent);
105107
} else {
@@ -115,7 +117,7 @@ export const AffiliatedOrganizations = ({
115117
}
116118
} else {
117119
org['childNodes'] = [];
118-
org['isOpen'] = false;
120+
org['allChildrenShown'] = false;
119121
parentdata.push(org);
120122
}
121123
}
@@ -141,16 +143,16 @@ export const AffiliatedOrganizations = ({
141143
>
142144
{currentThumbnails.map((org, i) => {
143145
childSort = org.childNodes;
144-
childNode = org.isOpen ? childSort : childSort.slice(0, 6);
146+
childNode = org.allChildrenShown ? childSort : childSort.slice(0, 6);
145147
return (
146148
<Dropdown
147149
checkboxValue={showIndexContrib}
148-
organization={org}
149-
key={`affiliatedThumbnailsWrapper_${i}`}
150150
dropdownLength={org.childNodes.length}
151-
isOpen={false}
152-
inputValue={inputValue}
153151
filtersActive={filtersActive}
152+
isOpen={expandedOrgs.includes(org.id.toString())}
153+
key={`affiliatedThumbnailsWrapper_${i}`}
154+
onClick={onOrgClick}
155+
organization={org}
154156
>
155157
<Grid
156158
container
@@ -207,11 +209,11 @@ export const AffiliatedOrganizations = ({
207209
className={classes.button}
208210
onClick={() => {
209211
const data = [...currentThumbnails];
210-
data[i].isOpen = !data[i].isOpen;
212+
data[i].allChildrenShown = !data[i].allChildrenShown;
211213
setCurrentThumbnails(data);
212214
}}
213215
>
214-
{currentThumbnails[i].isOpen ? 'View Less' : 'View All'}
216+
{currentThumbnails[i].allChildrenShown ? 'View Less' : 'View All'}
215217
</Button>
216218
</Grid>
217219
) : null}
@@ -230,13 +232,13 @@ export const AffiliatedOrganizations = ({
230232
{currentThumbnails.map((org, i) => {
231233
return (
232234
<Dropdown
233-
organization={org}
234-
key={`affiliatedThumbnailsWrapper_${i}`}
235-
dropdownLength={org.childNodes.length}
236-
isOpen={org.childNodes.length <= 6 && i === 0}
237-
inputValue={inputValue}
238235
checkboxValue={showIndexContrib}
236+
dropdownLength={org.childNodes.length}
239237
filtersActive={filtersActive}
238+
isOpen={expandedOrgs.includes(org.id.toString())}
239+
onClick={onOrgClick}
240+
key={`affiliatedThumbnailsWrapper_${i}`}
241+
organization={org}
240242
>
241243
<Box className={classes.affiliatedThumbnailsWrapper}>
242244
{org.childNodes.length === 0 ? (

0 commit comments

Comments
 (0)