Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

feat(groups): add virtual scrolling at groups list #619

Merged
merged 3 commits into from
Jul 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions client/src/components/AddToGroupModal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect } from "react";
import { List } from "react-virtualized";
import PT from "prop-types";

import Button from "../Button";
@@ -159,6 +160,42 @@ export default function AddToGroupModal({ onCancel, updateUser, user }) {
setFilter("");
};

const filteredOtherGroups = otherGroups.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
);
const filteredMyGroups = myGroups.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
);

const myGroupsListEstimatedWidth = filteredMyGroups.length > 10 ? 540 : 560;
const otherGroupsListEstimatedWidth =
filteredOtherGroups.length > 10 ? 540 : 560;
const listWidth =
myGroupsListEstimatedWidth > otherGroupsListEstimatedWidth
? myGroupsListEstimatedWidth
: otherGroupsListEstimatedWidth;

/**
* Row renderer for react-virtualized#List.
* Renders each item as a row.
* @param {String} key unique key for the item
* @param {Number} index index of the item (row)
* @param {Object} style
* @return {SectionRow} row element
*/
function rowRenderer({ key, index, style, items }) {
return (
<div key={key} style={style}>
<Group
checked={items[index].isSelected === true}
group={items[index]}
key={items[index].id}
onSwitch={() => switchSelected(items[index])}
/>
</div>
);
}

return (
<Modal
onCancel={onCancel}
@@ -201,19 +238,22 @@ export default function AddToGroupModal({ onCancel, updateUser, user }) {
My groups{loadingGroups && " (Loading...)"}
</h3>
<div>
{!loadingGroups &&
myGroups
.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
)
.map((g) => (
<Group
checked={g.isSelected === true}
group={g}
key={g.id}
onSwitch={() => switchSelected(g)}
/>
))}
{!loadingGroups && (
<List
className={style.groupsList}
width={listWidth}
height={
filteredMyGroups.length > 10
? 450
: filteredMyGroups.length * 45
}
rowCount={filteredMyGroups.length}
rowHeight={45}
rowRenderer={(params) =>
rowRenderer({ ...params, items: filteredMyGroups })
}
/>
)}
</div>
{myGroups.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
@@ -225,19 +265,22 @@ export default function AddToGroupModal({ onCancel, updateUser, user }) {
Other Groups{loadingGroups && " (Loading...)"}
</h3>
<div>
{!loadingGroups &&
otherGroups
.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
)
.map((g) => (
<Group
checked={g.isSelected === true}
group={g}
key={g.id}
onSwitch={() => switchSelected(g)}
/>
))}
{!loadingGroups && (
<List
className={style.groupsList}
width={listWidth}
height={
filteredOtherGroups.length > 10
? 450
: filteredOtherGroups.length * 45
}
rowCount={filteredOtherGroups.length}
rowHeight={45}
rowRenderer={(params) =>
rowRenderer({ ...params, items: filteredOtherGroups })
}
/>
)}
</div>
{otherGroups.filter((g) =>
g.name.toLowerCase().includes(filter.toLowerCase())
4 changes: 4 additions & 0 deletions client/src/components/AddToGroupModal/style.module.scss
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@
overflow-y: auto;
}

.groupsList {
outline: 0;
}

.search {
background: $lightGray2;
border: none;
47 changes: 34 additions & 13 deletions client/src/components/GroupsSideMenu/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { List } from "react-virtualized";
import PT from "prop-types";

import SearchBox from "../searchBox";
@@ -133,23 +134,42 @@ function GroupsSection({
selectedItemId,
loadingGroups,
}) {
/**
* Row renderer for react-virtualized#List.
* Renders each item as a row.
* @param {String} key unique key for the item
* @param {Number} index index of the item (row)
* @param {Object} style
* @return {SectionRow} row element
*/
function rowRenderer({ key, index, style }) {
return (
<div key={key} style={style}>
<SectionRow
key={`${title}${index}`}
title={items[index].name}
badge={items[index].count + ""}
action={(isSelected) =>
!isSelected && onItemClicked && onItemClicked(title, items[index])
}
selected={items[index].id === selectedItemId}
/>
</div>
);
}

return (
<>
<div className={styles.sectionTitle}>{title}</div>
<div className={styles.sectionItemsContainer}>
{items.map((item, index) => {
return (
<SectionRow
key={`${title}${index}`}
title={item.name}
badge={item.count + ""}
action={(isSelected) =>
!isSelected && onItemClicked && onItemClicked(title, item)
}
selected={item.id === selectedItemId}
/>
);
})}
<List
className={styles.groupsList}
width={385}
height={items.length > 7 ? 450 : items.length * 66}
rowCount={items.length}
rowHeight={66}
rowRenderer={rowRenderer}
/>
</div>
{items.length === 0 && !loadingGroups && (
<div className={styles.message}>No results found</div>
@@ -173,6 +193,7 @@ function SectionRow({ title, badge, selected = false, action }) {
onClick={() => {
action(selected);
}}
title={title}
>
<div
className={
9 changes: 8 additions & 1 deletion client/src/components/GroupsSideMenu/filters.module.css
Original file line number Diff line number Diff line change
@@ -73,6 +73,10 @@
flex-direction: column;
}

.groupsList {
outline: 0;
}

.sectionItemsContainer > div {
margin-top: 20px;
}
@@ -101,8 +105,11 @@
}

.sectionItemTitle {
width: 280px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: gray2;
word-break: break-all;
padding-right: 12px;
}

1 change: 1 addition & 0 deletions client/src/config.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ export default {
API_URL: process.env.REACT_APP_API_URL,
API_PREFIX: process.env.REACT_APP_API_PREFIX,
GROUPS_API_URL: process.env.REACT_APP_GROUPS_API_URL,
GROUPS_PER_PAGE: process.env.REACT_APP_GROUPS_PER_PAGE || 1000,

BULK_UPLOAD_TEMPLATE_ID: process.env.REACT_APP_BULK_UPLOAD_TEMPLATE_ID,
EMSI_SKILLPROVIDER_ID: process.env.REACT_APP_EMSI_SKILLPROVIDER_ID,
4 changes: 2 additions & 2 deletions client/src/lib/groups.js
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export async function getGroups(apiClient, handle, cancelToken) {
// Now, get my groups first
try {
response = await apiClient.get(
`${config.GROUPS_API_URL}?universalUID=${userId}&membershipType=user`,
`${config.GROUPS_API_URL}?universalUID=${userId}&membershipType=user&perPage=${config.GROUPS_PER_PAGE}`,
{ cancelToken }
);
} catch (error) {
@@ -66,7 +66,7 @@ export async function getGroups(apiClient, handle, cancelToken) {
// Fetch all groups in the org
try {
response = await apiClient.get(
`${config.GROUPS_API_URL}?organizationId=${organizationId}`,
`${config.GROUPS_API_URL}?organizationId=${organizationId}&perPage=${config.GROUPS_PER_PAGE}`,
{ cancelToken }
);
} catch (error) {
71 changes: 65 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
"lodash": "^4.17.19",
"multer": "^1.4.2",
"node-cache": "^5.1.0",
"react-virtualized": "^9.21.2",
"swagger-ui-express": "^4.1.4",
"tc-bus-api-wrapper": "topcoder-platform/tc-bus-api-wrapper.git#feature/auth0-proxy-server",
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.4",