Skip to content

Commit

Permalink
search+filter+sort for Competition, Semester, Series, Problems
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrembecky committed Dec 14, 2024
1 parent 0bac577 commit 0c6cbc8
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 37 deletions.
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">
<AutocompleteInput helperText={false} />
</ReferenceInput>
</FilterLiveForm>
</FilterListSection>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const FilterSidebar: FC<PropsWithChildren> = ({children}) => {
<FilterListIcon />
Filters
</Button>

<Card sx={{mt: 8, mr: filterOpen ? 2 : 0, width: filterOpen ? 200 : 0, transition: 'width 0.2s'}}>
<CardContent>
<FilterLiveSearch />
Expand Down
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 src/components/Admin/custom/list-filtering/SeriesFilterSection.tsx
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>
)
}
2 changes: 1 addition & 1 deletion src/components/Admin/resources/cms/post/PostList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {FC} from 'react'
import {Datagrid, FilterList, FilterListItem, FunctionField, List, RaRecord, TextField} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {FilterSidebar} from '@/components/Admin/custom/FilterSidebar'
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'
Expand Down
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 />
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export const EventRegistrationList: FC = () => (
</Datagrid>
</List>
)

// TODO: filtre a ordering podla https://github.com/ZdruzenieSTROM/webstrom-backend/pull/460/files#diff-148e08b739e60a78edfc1e546340f501840b75f1646afa58ee524ff82cfc061eR905-R908
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export const EventList: FC = () => (
</Datagrid>
</List>
)

// TODO: filtre a ordering podla https://github.com/ZdruzenieSTROM/webstrom-backend/pull/460/files#diff-148e08b739e60a78edfc1e546340f501840b75f1646afa58ee524ff82cfc061eR832-R838
31 changes: 15 additions & 16 deletions src/components/Admin/resources/competition/problems/ProblemList.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import {FC} from 'react'
import {
AutocompleteInput,
BooleanField,
Datagrid,
FilterList,
FilterListItem,
FilterListSection,
FilterLiveForm,
FunctionField,
ImageField,
List,
NumberField,
RaRecord,
ReferenceField,
ReferenceInput,
} from 'react-admin'

import {FilterSidebar} from '@/components/Admin/custom/FilterSidebar'
import {CompetitionFilterSection} from '@/components/Admin/custom/list-filtering/CompetitionFilterSection'
import {FilterSidebar} from '@/components/Admin/custom/list-filtering/FilterSidebar'
import {SemesterFilterSection} from '@/components/Admin/custom/list-filtering/SemesterFilterSection'
import {SeriesFilterSection} from '@/components/Admin/custom/list-filtering/SeriesFilterSection'
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField'

export const ProblemList: FC = () => (
<List aside={<ProblemListFilters />}>
<Datagrid>
<ReferenceField source="series" reference="competition/series" link={false} />
<ReferenceField source="series" reference="competition/series" link={false} sortable={false} />
<NumberField source="order" />
<TruncatedTextField source="text" maxTextWidth={50} />
<ImageField source="image" sx={{'& .RaImageField-image': {width: 100, height: 75}}} />
<TruncatedTextField source="text" maxTextWidth={50} sortable={false} />
<ImageField source="image" sx={{'& .RaImageField-image': {width: 100, height: 75}}} sortable={false} />
<FunctionField<RaRecord>
label="content.labels.has_vzorak"
render={(record) => record && <BooleanField record={{xxx: !!record['solution_pdf']}} source="xxx" />}
sortable={false}
/>
<NumberField source="num_comments" />
<NumberField source="num_comments" sortable={false} />
</Datagrid>
</List>
)

const ProblemListFilters: FC = () => (
<FilterSidebar>
<FilterListSection label="Séria" icon={null}>
<FilterLiveForm>
<ReferenceInput source="series" reference="competition/series">
<AutocompleteInput helperText={false} />
</ReferenceInput>
</FilterLiveForm>
</FilterListSection>
<CompetitionFilterSection />

<SemesterFilterSection />

<SeriesFilterSection />

<FilterList label="Číslo úlohy" icon={null}>
{[1, 2, 3, 4, 5, 6].map((problemNumber) => (
<FilterListItem key={problemNumber} label={problemNumber.toString()} value={{order: problemNumber}} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,47 @@ import {
} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {CompetitionFilterSection} from '@/components/Admin/custom/list-filtering/CompetitionFilterSection'
import {FilterSidebar} from '@/components/Admin/custom/list-filtering/FilterSidebar'
import {SeasonCodeField} from '@/components/Admin/custom/SeasonCodeField'

export const SemesterList: FC = () => (
<List>
<List aside={<SemesterListFilters />}>
<Datagrid>
<ReferenceField source="competition" reference="competition/competition" link={false} />
<ReferenceField source="competition" reference="competition/competition" link={false} sortable={false} />
<NumberField source="year" />
<SeasonCodeField source="season_code" />
<TextField source="school_year" />
<SeasonCodeField source="season_code" sortable={false} />
<TextField source="school_year" sortable={false} />
<DateTimeField source="start" />
<DateTimeField source="end" />
<BooleanField source="complete" />
<TextField source="additional_name" />
<NumberField source="registration_link" />
<BooleanField source="complete" sortable={false} />
<TextField source="additional_name" sortable={false} />
<NumberField source="registration_link" sortable={false} />
<FunctionField<RaRecord>
source="series_set"
render={(record) => record && <span>{record['series_set'].length}</span>}
sortable={false}
/>
<FunctionField<RaRecord>
source="publication_set"
render={(record) => record && <span>{record['publication_set'].length}</span>}
sortable={false}
/>
<FunctionField<RaRecord>
source="late_tags"
render={(record) => record && <span>{record['late_tags'].length}</span>}
sortable={false}
/>
</Datagrid>
</List>
)

const SemesterListFilters: FC = () => (
<FilterSidebar>
<CompetitionFilterSection />

{/* TODO:
- school_year
- season_code */}
</FilterSidebar>
)
38 changes: 33 additions & 5 deletions src/components/Admin/resources/competition/series/SeriesList.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
import {FC} from 'react'
import {BooleanField, Datagrid, FunctionField, List, RaRecord, ReferenceField, TextField} from 'react-admin'
import {
BooleanField,
Datagrid,
FilterList,
FilterListItem,
FunctionField,
List,
RaRecord,
ReferenceField,
TextField,
} from 'react-admin'

import {DateTimeField} from '@/components/Admin/custom/DateTimeField'
import {CompetitionFilterSection} from '@/components/Admin/custom/list-filtering/CompetitionFilterSection'
import {FilterSidebar} from '@/components/Admin/custom/list-filtering/FilterSidebar'
import {SemesterFilterSection} from '@/components/Admin/custom/list-filtering/SemesterFilterSection'

export const SeriesList: FC = () => (
<List>
<List aside={<SeriesListFilters />}>
<Datagrid>
<ReferenceField source="semester" reference="competition/semester" link={false} />
<ReferenceField source="semester" reference="competition/semester" link={false} sortable={false} />
<DateTimeField source="deadline" />
<TextField source="order" />
<BooleanField source="complete" />
<TextField source="order" sortable={false} />
<BooleanField source="complete" sortable={false} />
<FunctionField<RaRecord>
label="content.labels.problem_count"
render={(record) => record && <span>{record['problems'].length}</span>}
sortable={false}
/>
</Datagrid>
</List>
)

const SeriesListFilters: FC = () => (
<FilterSidebar>
<CompetitionFilterSection />

<SemesterFilterSection />

<FilterList label="Číslo seŕie" icon={null}>
{[1, 2].map((seriesNumber) => (
<FilterListItem key={seriesNumber} label={seriesNumber.toString()} value={{order: seriesNumber}} />
))}
</FilterList>
</FilterSidebar>
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export const SolutionList: FC = () => (
</Datagrid>
</List>
)

// TODO: filtre a ordering podla https://github.com/ZdruzenieSTROM/webstrom-backend/pull/460/files#diff-148e08b739e60a78edfc1e546340f501840b75f1646afa58ee524ff82cfc061eR537-R567

0 comments on commit 0c6cbc8

Please sign in to comment.