Skip to content

Commit

Permalink
Add filtering by text/role/status, sorting, pagination, collection pr…
Browse files Browse the repository at this point in the history
…efs (#367)

* Add filtering by text/role/status, sorting, pagination, collection prefs via collection hooks

* Fix prettier sgs

* Fix more prettier sgs

* One more prettier error

* Change select->multi, add searching by composite name, three columns filter

* Fix prettiers

* Fix text filter

* More prettiers

* More prettiers

* Merge main, resolve conflicts

* Merge main conflicts again

* Add day checkins to default visible columns

* More prettiers

* More prettiers

* Add icons to status filter

* Prettier run everything

* fix: type error

---------

Co-authored-by: Sam Der <[email protected]>
  • Loading branch information
alanchangxyz and samderanova authored Jan 27, 2024
1 parent 9a1d8e1 commit f4407d3
Show file tree
Hide file tree
Showing 4 changed files with 356 additions and 69 deletions.
1 change: 1 addition & 0 deletions apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@cloudscape-design/collection-hooks": "^1.0.34",
"@cloudscape-design/components": "^3.0.475",
"@cloudscape-design/global-styles": "^1.0.20",
"@fireworks-js/react": "^2.10.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { Dispatch, SetStateAction } from "react";

import FormField from "@cloudscape-design/components/form-field";
import { IconProps } from "@cloudscape-design/components/icon";
import Multiselect, {
MultiselectProps,
} from "@cloudscape-design/components/multiselect";
import SpaceBetween from "@cloudscape-design/components/space-between";
import TextFilter, {
TextFilterProps,
} from "@cloudscape-design/components/text-filter";

import {
Decision,
PostAcceptedStatus,
ReviewStatus,
Status,
} from "@/lib/admin/useApplicant";
import { StatusLabels } from "../../applicants/components/ApplicantStatus";
import type { Options } from "./ParticipantsTable";

interface ParticipantsFiltersProps {
filteredItemsCount: number | undefined;
filterProps: TextFilterProps;
roles: Options;
selectedRoles: Options;
setSelectedRoles: Dispatch<SetStateAction<Options>>;
statuses: Options;
selectedStatuses: Options;
setSelectedStatuses: Dispatch<SetStateAction<Options>>;
}

const StatusIcons: Record<Status, IconProps.Name> = {
[ReviewStatus.pending]: "status-pending",
[ReviewStatus.reviewed]: "status-in-progress",
[ReviewStatus.released]: "status-positive",
[Decision.accepted]: "status-positive",
[Decision.rejected]: "status-pending",
[Decision.waitlisted]: "status-negative",
[PostAcceptedStatus.signed]: "status-in-progress",
[PostAcceptedStatus.confirmed]: "status-positive",
[PostAcceptedStatus.attending]: "status-positive",
[PostAcceptedStatus.void]: "status-negative",
};

const statusOption = (status: MultiselectProps.Option) => {
if (status.value === undefined) {
throw Error();
}
return {
label: StatusLabels[status.value as Status],
value: status.value,
iconName: StatusIcons[status.value as Status],
};
};

function ParticipantsFilters({
filteredItemsCount,
filterProps,
roles,
selectedRoles,
setSelectedRoles,
statuses,
selectedStatuses,
setSelectedStatuses,
}: ParticipantsFiltersProps) {
return (
<SpaceBetween size="l" direction="horizontal">
<div style={{ marginTop: "24px" }}>
<TextFilter
{...filterProps}
countText={
filteredItemsCount === 1
? "1 participant"
: `${filteredItemsCount} participants`
}
filteringAriaLabel="Filter participants"
filteringPlaceholder="Search participants"
/>
</div>
<FormField label="Role">
<Multiselect
data-testid="role-filter"
placeholder="Filter by role"
options={roles}
selectedAriaLabel="Selected"
selectedOptions={selectedRoles}
onChange={(event) => setSelectedRoles(event.detail.selectedOptions)}
expandToViewport={true}
/>
</FormField>
<FormField label="Status">
<Multiselect
data-testid="status-filter"
placeholder="Filter by status"
options={statuses.map(statusOption)}
selectedAriaLabel="Selected"
selectedOptions={selectedStatuses}
onChange={(event) =>
setSelectedStatuses(event.detail.selectedOptions)
}
expandToViewport={true}
/>
</FormField>
</SpaceBetween>
);
}

export default ParticipantsFilters;
Loading

0 comments on commit f4407d3

Please sign in to comment.