-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Admin - Search/Filters/Ordering for Post/Competition/Semester/S…
…eries/Problems (#510) * add Dark mode toggle button * unrelated: redundant style * basic Post/Problem search+filter+sort * `yarn dedupe` to fix MUI styles * global medium buttons, `yarn add @mui/utils@^5`, `yarn dedupe` * search+filter+sort for Competition, Semester, Series, Problems * filter CompetitionFilterSection based on `competition_type: 0` * open FilterSidebar by default
- Loading branch information
1 parent
dca4ace
commit 4ba507f
Showing
19 changed files
with
364 additions
and
1,789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/components/Admin/custom/list-filtering/CompetitionFilterSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {FC} from 'react' | ||
import {AutocompleteInput, FilterListSection, FilterLiveForm, ReferenceInput} from 'react-admin' | ||
|
||
export const CompetitionFilterSection: FC = () => { | ||
return ( | ||
<FilterListSection label="Competition" icon={null}> | ||
<FilterLiveForm> | ||
<ReferenceInput source="competition" reference="competition/competition" filter={{competition_type: 0}}> | ||
<AutocompleteInput helperText={false} /> | ||
</ReferenceInput> | ||
</FilterLiveForm> | ||
</FilterListSection> | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
src/components/Admin/custom/list-filtering/FilterSidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {FilterList as FilterListIcon} from '@mui/icons-material' | ||
import {Button, Card, CardContent, Stack} from '@mui/material' | ||
import {FC, PropsWithChildren, useState} from 'react' | ||
import {FilterLiveSearch} from 'react-admin' | ||
|
||
export const FilterSidebar: FC<PropsWithChildren> = ({children}) => { | ||
const [filterOpen, setFilterOpen] = useState(true) | ||
const toggleFilter = () => setFilterOpen((prev) => !prev) | ||
|
||
return ( | ||
<Stack | ||
sx={{ | ||
order: -1, | ||
position: 'relative', | ||
overflow: 'visible', | ||
}} | ||
> | ||
<Button onClick={toggleFilter} sx={{mt: 0.5, position: 'absolute', width: 'max-content', gap: 1}}> | ||
<FilterListIcon /> | ||
Filters | ||
</Button> | ||
|
||
<Card sx={{mt: 8, mr: filterOpen ? 2 : 0, width: filterOpen ? 200 : 0, transition: 'width 0.2s'}}> | ||
<CardContent> | ||
<FilterLiveSearch /> | ||
{children} | ||
</CardContent> | ||
</Card> | ||
</Stack> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/components/Admin/custom/list-filtering/SemesterFilterSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {FC} from 'react' | ||
import {AutocompleteInput, FilterListSection, FilterLiveForm, ReferenceInput, useListContext} from 'react-admin' | ||
|
||
export const SemesterFilterSection: FC = () => { | ||
const {filterValues} = useListContext() | ||
|
||
return ( | ||
<FilterListSection label="Semester" icon={null}> | ||
<FilterLiveForm> | ||
<ReferenceInput | ||
source="semester" | ||
reference="competition/semester" | ||
filter={{competition: filterValues.competition}} | ||
> | ||
<AutocompleteInput helperText={false} /> | ||
</ReferenceInput> | ||
</FilterLiveForm> | ||
</FilterListSection> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/components/Admin/custom/list-filtering/SeriesFilterSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {FC} from 'react' | ||
import {AutocompleteInput, FilterListSection, FilterLiveForm, ReferenceInput, useListContext} from 'react-admin' | ||
|
||
export const SeriesFilterSection: FC = () => { | ||
const {filterValues} = useListContext() | ||
|
||
return ( | ||
<FilterListSection label="Séria" icon={null}> | ||
<FilterLiveForm> | ||
<ReferenceInput | ||
source="series" | ||
reference="competition/series" | ||
filter={{competition: filterValues.competition, semester: filterValues.semester}} | ||
> | ||
<AutocompleteInput helperText={false} /> | ||
</ReferenceInput> | ||
</FilterLiveForm> | ||
</FilterListSection> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
import {FC} from 'react' | ||
import {Datagrid, FunctionField, List, RaRecord, TextField} from 'react-admin' | ||
import {Datagrid, FilterList, FilterListItem, FunctionField, List, RaRecord, TextField} from 'react-admin' | ||
|
||
import {DateTimeField} from '@/components/Admin/custom/DateTimeField' | ||
import {FilterSidebar} from '@/components/Admin/custom/list-filtering/FilterSidebar' | ||
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' | ||
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' | ||
import {seminarIds, seminarIdToName} from '@/utils/useSeminarInfo' | ||
|
||
export const PostList: FC = () => ( | ||
<List> | ||
<List aside={<PostListFilters />}> | ||
<Datagrid> | ||
<TextField source="caption" /> | ||
<TruncatedTextField source="short_text" maxTextWidth={50} /> | ||
<TruncatedTextField source="details" maxTextWidth={50} /> | ||
<TextField source="caption" sortable={false} /> | ||
<TruncatedTextField source="short_text" maxTextWidth={50} sortable={false} /> | ||
<TruncatedTextField source="details" maxTextWidth={50} sortable={false} /> | ||
<DateTimeField source="added_at" /> | ||
<DateTimeField source="visible_after" /> | ||
<DateTimeField source="visible_until" /> | ||
<SitesArrayField source="sites" /> | ||
<FunctionField<RaRecord> source="links" render={(record) => record && <span>{record['links'].length}</span>} /> | ||
<SitesArrayField source="sites" sortable={false} /> | ||
<FunctionField<RaRecord> | ||
source="links" | ||
render={(record) => record && <span>{record['links'].length}</span>} | ||
sortable={false} | ||
/> | ||
</Datagrid> | ||
</List> | ||
) | ||
|
||
const PostListFilters: FC = () => ( | ||
<FilterSidebar> | ||
<FilterList label="Seminár" icon={null}> | ||
{seminarIds.map((seminarId) => ( | ||
<FilterListItem key={seminarId} label={seminarIdToName[seminarId]} value={{sites: seminarId}} /> | ||
))} | ||
</FilterList> | ||
</FilterSidebar> | ||
) |
20 changes: 12 additions & 8 deletions
20
src/components/Admin/resources/competition/competition/CompetitionList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import {FC} from 'react' | ||
import {Datagrid, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin' | ||
|
||
import {FilterSidebar} from '@/components/Admin/custom/list-filtering/FilterSidebar' | ||
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' | ||
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' | ||
|
||
export const CompetitionList: FC = () => ( | ||
<List> | ||
<List aside={<CompetitionListFilters />}> | ||
<Datagrid> | ||
<TextField source="name" /> | ||
<TextField source="slug" /> | ||
<TextField source="slug" sortable={false} /> | ||
<TextField source="start_year" /> | ||
<TruncatedTextField source="description" maxTextWidth={30} /> | ||
<TruncatedTextField source="rules" maxTextWidth={30} /> | ||
<TextField source="competition_type.name" label="content.labels.competition_type" /> | ||
<SitesArrayField source="sites" /> | ||
<TextField source="who_can_participate" /> | ||
<NumberField source="min_years_until_graduation" /> | ||
<TruncatedTextField source="description" maxTextWidth={30} sortable={false} /> | ||
<TruncatedTextField source="rules" maxTextWidth={30} sortable={false} /> | ||
<TextField source="competition_type.name" label="content.labels.competition_type" sortable={false} /> | ||
<SitesArrayField source="sites" sortable={false} /> | ||
<TextField source="who_can_participate" sortable={false} /> | ||
<NumberField source="min_years_until_graduation" sortable={false} /> | ||
<FunctionField<RaRecord> | ||
source="history_events" | ||
label="content.labels.history_events_count" | ||
render={(record) => record && <span>{record['history_events'].length}</span>} | ||
sortable={false} | ||
/> | ||
</Datagrid> | ||
</List> | ||
) | ||
|
||
const CompetitionListFilters: FC = () => <FilterSidebar /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.