Skip to content

Commit 8ab376c

Browse files
committed
Add functionality to filter teams by organisation
1 parent d44f26d commit 8ab376c

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

frontend/src/components/teamsAndOrgs/management.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from 'react';
22
import { Link } from '@reach/router';
3+
import { useSelector } from 'react-redux';
34
import { FormattedMessage } from 'react-intl';
45

56
import messages from './messages';
7+
import { useFetch } from '../../hooks/UseFetch';
68
import { CustomButton } from '../button';
79
import { PlusIcon, WasteIcon } from '../svgIcons';
10+
import { ProjectFilterSelect } from '../projects/filterSelectFields';
811

912
export const ViewAllLink = ({ link }: Object) => (
1013
<Link to={link} className="dib mt2 fr red link">
@@ -53,6 +56,34 @@ export function InviteOnlyBox({ className }: Object) {
5356
);
5457
}
5558

59+
export function TeamFilter({ query, setQuery }) {
60+
const userDetails = useSelector((state) => state.auth.get('userDetails'));
61+
const [orgsError, orgsLoading, organisations] = useFetch(
62+
`organisations/?omitManagerList=true${
63+
userDetails.role === 'ADMIN' ? '' : `&manager_user_id=${userDetails.id}`
64+
}`,
65+
userDetails && userDetails.id,
66+
);
67+
68+
const { organisation: orgInQuery } = query;
69+
70+
return (
71+
<ProjectFilterSelect
72+
fieldsetName="organisation"
73+
fieldsetStyle={'w-20-l w-25-m w-50 ph1 pv2 mh0 v-top bn dib'}
74+
titleStyle={'dn'}
75+
selectedTag={orgInQuery}
76+
options={{
77+
isError: orgsError,
78+
isLoading: orgsLoading,
79+
tags: organisations ? organisations.organisations : [],
80+
}}
81+
setQueryForChild={setQuery}
82+
allQueryParamsForChild={query}
83+
/>
84+
);
85+
}
86+
5687
export function Management(props) {
5788
// admin users can switch between all teams/orgs and only their teams/orgs
5889
return (
@@ -85,7 +116,6 @@ export function Management(props) {
85116
</div>
86117
)}
87118
</div>
88-
89119
<div className="w-100 cf dib">{props.children}</div>
90120
</div>
91121
);

frontend/src/components/teamsAndOrgs/teams.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ import { Link } from '@reach/router';
44
import { FormattedMessage } from 'react-intl';
55
import ReactPlaceholder from 'react-placeholder';
66
import { Form, Field } from 'react-final-form';
7+
import { useQueryParams, StringParam } from 'use-query-params';
78

89
import messages from './messages';
910
import { useEditTeamAllowed } from '../../hooks/UsePermissions';
1011
import { UserAvatar, UserAvatarList } from '../user/avatar';
11-
import { AddButton, ViewAllLink, Management, VisibilityBox, InviteOnlyBox } from './management';
12+
import {
13+
AddButton,
14+
ViewAllLink,
15+
Management,
16+
VisibilityBox,
17+
InviteOnlyBox,
18+
TeamFilter,
19+
} from './management';
1220
import { SwitchToggle, RadioField, OrganisationSelectInput } from '../formInputs';
1321
import { Button, EditButton } from '../button';
22+
import ClearFilters from '../projects/clearFilters';
1423

1524
export function TeamsManagement({
1625
teams,
@@ -23,6 +32,12 @@ export function TeamsManagement({
2332
(state) => state.auth.get('organisations') && state.auth.get('organisations').length > 0,
2433
);
2534

35+
const [query, setQuery] = useQueryParams({ organisation: StringParam });
36+
37+
const filteredTeams = query.organisation
38+
? teams.filter((t) => t.organisation === query.organisation)
39+
: teams;
40+
2641
return (
2742
<Management
2843
title={
@@ -42,8 +57,15 @@ export function TeamsManagement({
4257
setUserOnly={setUserTeamsOnly}
4358
userOnlyLabel={<FormattedMessage {...messages.myTeams} />}
4459
>
45-
{teams.length ? (
46-
teams.map((team, n) => <TeamCard team={team} key={n} managementView={managementView} />)
60+
<div>
61+
<TeamFilter query={query} setQuery={setQuery} />
62+
<ClearFilters url={'/manage/teams/'} className="v-top mh1 mt1 mt2-ns dib" />
63+
</div>
64+
65+
{filteredTeams.length ? (
66+
filteredTeams.map((team, n) => (
67+
<TeamCard team={team} key={n} managementView={managementView} />
68+
))
4769
) : (
4870
<div className="pb3 pt2">
4971
<FormattedMessage {...messages.noTeams} />

0 commit comments

Comments
 (0)