Skip to content

Commit 10ff572

Browse files
committed
Clicking on roles in user table to set filter
Allows users to click on a role in the user table to set that role as filter.
1 parent 294064b commit 10ff572

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/components/users/partials/UsersRolesCell.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useTranslation } from "react-i18next";
2-
import { User } from "../../../slices/userSlice";
2+
import { fetchUsers, User } from "../../../slices/userSlice";
3+
import MultiValueCell from "../../shared/MultiValueCell";
4+
import { loadUsersIntoTable } from "../../../thunks/tableThunks";
35

46
/**
57
* This component renders the roles cells of users in the table view
@@ -13,6 +15,7 @@ const UsersRolesCell = ({
1315

1416
const getRoleString = () => {
1517
const displayRoles = [];
18+
const squashedRoles = [];
1619
let roleCountUI = 0;
1720
let roleCountAPI = 0;
1821
let roleCountCaptureAgent = 0;
@@ -31,21 +34,36 @@ const UsersRolesCell = ({
3134

3235
if (roleCountUI > 0) {
3336
const desc = t("USERS.USERS.TABLE.COLLAPSED.UI");
34-
displayRoles.push(`${roleCountUI} ${desc}`);
37+
squashedRoles.push(`${roleCountUI} ${desc}`);
3538
}
3639
if (roleCountAPI > 0) {
3740
const desc = t("USERS.USERS.TABLE.COLLAPSED.API");
38-
displayRoles.push(`${roleCountAPI} ${desc}`);
41+
squashedRoles.push(`${roleCountAPI} ${desc}`);
3942
}
4043
if (roleCountCaptureAgent > 0) {
4144
const desc = t("USERS.USERS.TABLE.COLLAPSED.CAPTURE_AGENT");
42-
displayRoles.push(`${roleCountCaptureAgent} ${desc}`);
45+
squashedRoles.push(`${roleCountCaptureAgent} ${desc}`);
4346
}
4447

45-
return displayRoles.join(", ");
48+
return { displayRoles, squashedRoles };
4649
};
4750

48-
return <span>{getRoleString()}</span>;
51+
const { displayRoles, squashedRoles } = getRoleString();
52+
53+
return (
54+
<>
55+
<MultiValueCell
56+
resource="users"
57+
values={displayRoles}
58+
filterName="Role"
59+
fetchResource={fetchUsers}
60+
loadResourceIntoTable={loadUsersIntoTable}
61+
tooltipText="USERS.USERS.TABLE.TOOLTIP.ROLES"
62+
/>
63+
{ displayRoles.length > 0 && squashedRoles.length > 0 && <span>, </span> }
64+
<span>{squashedRoles.join(", ")}</span>
65+
</>
66+
);
4967
};
5068

5169
export default UsersRolesCell;

src/i18n/org/opencastproject/adminui/languages/lang-en_US.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@
13521352
"PROVIDER": "Provider",
13531353
"ACTION": "Actions",
13541354
"TOOLTIP": {
1355+
"ROLES": "Filter for this role",
13551356
"DELETE": "Delete user",
13561357
"DETAILS": "Open user details"
13571358
}

0 commit comments

Comments
 (0)