Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering by text/role/status, sorting, pagination, collection prefs #367

Merged
merged 18 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
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
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
Loading