Skip to content

Commit

Permalink
add team search to leadership analytics (#4277)
Browse files Browse the repository at this point in the history
* add team search to leadership analytics

* linting

* add missing props in test

* typecheck
  • Loading branch information
lctrt authored May 20, 2024
1 parent 1b28a2c commit 16499c7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
7 changes: 5 additions & 2 deletions apps/crn-frontend/src/analytics/leadership/Leadership.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { analytics } from '@asap-hub/routing';
import { FC, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom';

import { usePagination, usePaginationParams } from '../../hooks';
import { usePagination, usePaginationParams, useSearch } from '../../hooks';
import { useAnalyticsLeadership } from './state';

type MetricResponse = {
Expand Down Expand Up @@ -66,11 +66,12 @@ const Leadership: FC<Record<string, never>> = () => {

const { currentPage, pageSize } = usePaginationParams();

const { debouncedSearchQuery, searchQuery, setSearchQuery } = useSearch();
const { items, total } = useAnalyticsLeadership({
sort,
currentPage,
pageSize,
searchQuery: '',
searchQuery: debouncedSearchQuery,
filters: new Set(),
});

Expand All @@ -80,6 +81,8 @@ const Leadership: FC<Record<string, never>> = () => {
<AnalyticsLeadershipPageBody
metric={metric}
setMetric={setMetric}
searchQuery={searchQuery}
onChangeSearch={setSearchQuery}
sort={sort}
setSort={setSort}
sortingDirection={sortingDirection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const renderPage = async (
currentPage: 0,
pageSize: 10,
sort: 'team_asc',
searchQuery: '',
}),
);
}}
Expand Down
4 changes: 2 additions & 2 deletions apps/crn-frontend/src/analytics/leadership/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Options = GetListOptions & { sort: SortLeadershipAndMembership };

const analyticsLeadershipIndexState = atomFamily<
{ ids: ReadonlyArray<string>; total: number } | Error | undefined,
Pick<Options, 'currentPage' | 'pageSize' | 'sort'>
Pick<Options, 'currentPage' | 'pageSize' | 'sort' | 'searchQuery'>
>({
key: 'analyticsLeadershipIndex',
default: undefined,
Expand All @@ -34,7 +34,7 @@ export const analyticsLeadershipListState = atomFamily<

export const analyticsLeadershipState = selectorFamily<
ListAnalyticsTeamLeadershipResponse | Error | undefined,
Pick<Options, 'currentPage' | 'pageSize' | 'sort'>
Pick<Options, 'currentPage' | 'pageSize' | 'sort' | 'searchQuery'>
>({
key: 'teams',
get:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
} from '@asap-hub/model';
import { css } from '@emotion/react';
import { ComponentProps } from 'react';
import { PageControls } from '..';
import { PageControls, SearchField } from '..';
import { Dropdown, Headline3, Paragraph, Subtitle } from '../atoms';
import { LeadershipMembershipTable } from '../organisms';
import { perRem } from '../pixels';
import { rem } from '../pixels';

type MetricOption = 'working-group' | 'interest-group';
type MetricData = {
Expand Down Expand Up @@ -41,20 +41,33 @@ type LeadershipAndMembershipAnalyticsProps = ComponentProps<
setSortingDirection: React.Dispatch<
React.SetStateAction<LeadershipAndMembershipSortingDirection>
>;
searchQuery: string;
onChangeSearch: (newSearchQuery: string) => void;
};

const metricDropdownStyles = css({
marginBottom: `${48 / perRem}em`,
marginBottom: rem(48),
});

const tableHeaderStyles = css({
paddingBottom: `${24 / perRem}em`,
paddingBottom: rem(24),
});

const pageControlsStyles = css({
justifySelf: 'center',
paddingTop: `${36 / perRem}em`,
paddingBottom: `${36 / perRem}em`,
paddingTop: rem(36),
paddingBottom: rem(36),
});

const searchContainerStyles = css({
display: 'flex',
gap: rem(18),
alignItems: 'center',
paddingBottom: rem(33),
});

const searchStyles = css({
flexGrow: 1,
});

const LeadershipPageBody: React.FC<LeadershipAndMembershipAnalyticsProps> = ({
Expand All @@ -65,6 +78,8 @@ const LeadershipPageBody: React.FC<LeadershipAndMembershipAnalyticsProps> = ({
metric,
setMetric,
data,
searchQuery,
onChangeSearch,
...pageControlProps
}) => (
<article>
Expand All @@ -84,6 +99,16 @@ const LeadershipPageBody: React.FC<LeadershipAndMembershipAnalyticsProps> = ({
membership role within a Working Group.
</Paragraph>
</div>
<div css={searchContainerStyles}>
<Subtitle>Teams:</Subtitle>
<span css={searchStyles}>
<SearchField
value={searchQuery}
placeholder="Enter team names..."
onChange={onChangeSearch}
/>
</span>
</div>
<LeadershipMembershipTable
metric={metric}
data={data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('AnalyticsLeadershipPageBody', () => {
setSort: jest.fn(),
sortingDirection: initialSortingDirection,
setSortingDirection: jest.fn(),
searchQuery: '',
onChangeSearch: jest.fn(),
};
it('renders interest group tab', () => {
const { getAllByText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const pageControlProps = {
it('renders the selected metric', () => {
render(
<AnalyticsLeadershipPageBody
searchQuery=""
onChangeSearch={jest.fn()}
metric={'interest-group'}
data={[]}
setMetric={() => {}}
Expand Down

0 comments on commit 16499c7

Please sign in to comment.