Skip to content

Commit

Permalink
fix: show search filters unconditionally (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
carissa-tang authored Oct 30, 2023
1 parent bba09bf commit 5049a31
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
12 changes: 8 additions & 4 deletions frontend/src/components/admin/user-management/admin/AdminTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface AdminTabProps<SortPropTypes extends readonly string[]> {
searchBarComponent: React.ReactElement<SearchBarProps>;
UserTable: React.ReactElement<AdminUser[] | TeacherUser[]>;
search: string;
searchLength: number;
resultsLength: number;
}

export interface AdminTableProps {
Expand All @@ -26,7 +26,7 @@ const AdminTab = <SortPropTypes extends readonly string[]>({
searchBarComponent,
UserTable,
search,
searchLength,
resultsLength,
}: AdminTabProps<SortPropTypes>): React.ReactElement => {
return (
<>
Expand All @@ -37,10 +37,14 @@ const AdminTab = <SortPropTypes extends readonly string[]>({
</HStack>
{search && (
<Text color="grey.300" fontSize="16px" width="100%">
Showing {searchLength} results for &quot;{search}&quot;
Showing {resultsLength} results for &quot;{search}&quot;
</Text>
)}
{searchLength !== 0 ? UserTable : <NoResultsTableState items="users" />}
{resultsLength !== 0 ? (
UserTable
) : (
<NoResultsTableState items="users" />
)}
</VStack>
</>
);
Expand Down
20 changes: 9 additions & 11 deletions frontend/src/components/common/table/SearchableTablePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface SearchableTablePageProps<T, SortPropTypes extends readonly string[]> {
searchBarComponent: React.ReactElement<SearchBarProps>;
tableComponent: React.ReactElement<T[]>;
search: string;
searchLength: number;
resultsLength: number;
nameOfTableItems: string;
}

Expand All @@ -26,7 +26,7 @@ const SearchableTablePage = <T, SortPropTypes extends readonly string[]>({
searchBarComponent,
tableComponent,
search,
searchLength,
resultsLength,
nameOfTableItems,
}: SearchableTablePageProps<T, SortPropTypes>): React.ReactElement => {
const emptyResults = noResults ? (
Expand All @@ -37,20 +37,18 @@ const SearchableTablePage = <T, SortPropTypes extends readonly string[]>({
return (
<>
<VStack pt={4} spacing={6} w="full">
{searchLength !== 0 && (
<HStack width="100%">
{searchBarComponent}
{sortMenuComponent}
{filterMenuComponent}
</HStack>
)}
<HStack width="100%">
{searchBarComponent}
{sortMenuComponent}
{filterMenuComponent}
</HStack>
{search && (
<Text color="grey.300" fontSize="16px" width="100%">
Showing {searchLength} results for &quot;
Showing {resultsLength} results for &quot;
{search}&quot;
</Text>
)}
{searchLength !== 0 ? tableComponent : emptyResults}
{resultsLength !== 0 ? tableComponent : emptyResults}
</VStack>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ const DisplayAssessmentsPage = (): React.ReactElement => {
nameOfTableItems="assessments"
noResults={isEmpty}
noResultsComponent={<EmptyTestsMessage />}
resultsLength={assessments.length}
search={search}
searchBarComponent={<SearchBar onSearch={setSearch} />}
searchLength={assessments.length}
sortMenuComponent={
<SortMenu
initialSortOrder="descending"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/pages/admin/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ const UsersPage = (): React.ReactElement => {
<TabPanels>
<TabPanel padding="0">
<AdminTab
resultsLength={admins.length}
search={search}
searchBarComponent={<SearchBar onSearch={setSearch} />}
searchLength={admins.length}
sortMenuComponent={
<SortMenu
labels={["name", "email"]}
Expand All @@ -123,9 +123,9 @@ const UsersPage = (): React.ReactElement => {
</TabPanel>
<TabPanel padding="0">
<AdminTab
resultsLength={teachers.length}
search={search}
searchBarComponent={<SearchBar onSearch={setSearch} />}
searchLength={teachers.length}
sortMenuComponent={
<SortMenu
labels={["name", "email", "school"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const DisplayClassroomAssessmentsPage = () => {
isActive={data?.class.isActive}
/>
}
resultsLength={paginatedData.length}
search={search}
searchBarComponent={<SearchBar onSearch={setSearch} />}
searchLength={paginatedData.length}
sortMenuComponent={
<SortMenu
initialSortOrder={sortOrder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const DisplayClassroomStudentsPage = ({
onClick={onCreateStudent}
/>
}
resultsLength={students.length}
search={search}
searchBarComponent={<SearchBar onSearch={setSearch} />}
searchLength={students.length}
sortMenuComponent={
<SortMenu
initialSortOrder="descending"
Expand Down

0 comments on commit 5049a31

Please sign in to comment.