Skip to content

Commit

Permalink
RA - Competitions - only certain fields on Edit, show and link events…
Browse files Browse the repository at this point in the history
…, remove Create (#279)

admin: revisit competitions - allow only certain fields on Edit, show and link events, remove Create
  • Loading branch information
rtrembecky authored Dec 9, 2023
1 parent 51a0456 commit 4d45bd5
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 89 deletions.
10 changes: 2 additions & 8 deletions src/components/Admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {PostCreate} from './resources/cms/post/PostCreate'
import {PostEdit} from './resources/cms/post/PostEdit'
import {PostList} from './resources/cms/post/PostList'
import {PostShow} from './resources/cms/post/PostShow'
import {CompetitionCreate} from './resources/competition/competition/CompetitionCreate'
import {CompetitionEdit} from './resources/competition/competition/CompetitionEdit'
import {CompetitionList} from './resources/competition/competition/CompetitionList'
import {CompetitionShow} from './resources/competition/competition/CompetitionShow'
Expand All @@ -31,13 +30,8 @@ export const Admin: FC = () => {
<Resource name="cms/post" list={PostList} edit={PostEdit} show={PostShow} create={PostCreate} />
<Resource name="competition/series" list={SeriesList} edit={SeriesEdit} show={SeriesShow} />
<Resource name="competition/event" list={EventList} edit={EventEdit} show={EventShow} create={EventCreate} />
<Resource
name="competition/competition"
list={CompetitionList}
edit={CompetitionEdit}
show={CompetitionShow}
create={CompetitionCreate}
/>
{/* nedovolujeme create na competition - velmi rare vec, ani nemame BE POST endpoint na to */}
<Resource name="competition/competition" list={CompetitionList} edit={CompetitionEdit} show={CompetitionShow} />
<Resource
name="base/flat-page"
list={FlatpageList}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
import {FC} from 'react'
import {ArrayInput, FormTab, NumberInput, required, SimpleFormIterator, TabbedForm, TextInput} from 'react-admin'
import {NumberInput, SimpleForm, TextInput} from 'react-admin'

import {MyEdit} from '@/components/Admin/custom/MyEdit'
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput'

export const CompetitionEdit: FC = () => (
<MyEdit>
<TabbedForm>
<FormTab label="general">
<TextInput source="name" fullWidth />
<NumberInput source="start_year" fullWidth />
<TextInput source="description" fullWidth />
<TextInput source="rules" fullWidth />
<NumberInput source="competition_type" fullWidth />
<NumberInput source="min_years_until_graduation" fullWidth />
<SitesCheckboxInput source="sites" validate={required()} />
</FormTab>
<FormTab label="events">
<ArrayInput source="event_set" defaultValue={[]}>
<SimpleFormIterator>
{/* unspecifiedpublication_set: UnspecifiedPublication[]
registration_links: RegistrationLink[] */}
<NumberInput source="year" fullWidth />
<TextInput source="shool_year" fullWidth /* validate={required()} */ />
<TextInput source="start" fullWidth validate={required()} />
<TextInput source="end" fullWidth validate={required()} />
<NumberInput source="competition" fullWidth />
</SimpleFormIterator>
</ArrayInput>
</FormTab>
</TabbedForm>
<SimpleForm>
<TextInput source="name" fullWidth disabled />
<TextInput source="slug" fullWidth disabled />
<NumberInput source="start_year" fullWidth disabled />
<TextInput source="description" multiline fullWidth />
<TextInput source="rules" multiline fullWidth />
<TextInput source="competition_type.name" label="Competition type" fullWidth disabled />
<SitesCheckboxInput source="sites" disabled />
<TextInput source="who_can_participate" multiline fullWidth />
<NumberInput source="min_years_until_graduation" fullWidth disabled />
</SimpleForm>
</MyEdit>
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const CompetitionList: FC = () => (
<NumberField source="start_year" />
<TruncatedTextField source="description" maxTextWidth={30} />
<TruncatedTextField source="rules" maxTextWidth={30} />
{/* <NumberField source="competition_type.id" /> */}
<TextField source="competition_type.name" label="Competition type" />
<SitesArrayField source="sites" />
<TextField source="who_can_participate" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import {Divider} from '@mui/material'
import {FC} from 'react'
import {
ArrayField,
Datagrid,
DateField,
FunctionField,
NumberField,
RaRecord,
Show,
SimpleShowLayout,
Tab,
TabbedShowLayout,
TextField,
} from 'react-admin'

import {JsonField} from '@/components/Admin/custom/JsonField'
import {MyShowActions} from '@/components/Admin/custom/MyShowActions'
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField'
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField'

import {UpcomingOrCurrentEvent} from './UpcomingOrCurrentEvent'

export const CompetitionShow: FC = () => (
<Show actions={<MyShowActions />}>
<TabbedShowLayout>
Expand All @@ -26,24 +30,29 @@ export const CompetitionShow: FC = () => (
<NumberField source="start_year" />
<TruncatedTextField source="description" maxTextWidth={100} expandable />
<TruncatedTextField source="rules" maxTextWidth={200} expandable />
<NumberField source="competition_type.id" />
<TextField source="competition_type.name" />
<TextField source="competition_type.name" label="Competition type" />
<SitesArrayField source="sites" />
<NumberField source="min_years_until_graduation" />
<TextField source="who_can_participate" />
<JsonField source="upcoming_or_current_event" />
<NumberField source="min_years_until_graduation" />

<Divider />
<UpcomingOrCurrentEvent />
</SimpleShowLayout>
</Tab>
<Tab label="history_events">
<SimpleShowLayout>
<ArrayField source="history_events">
<Datagrid>
<Datagrid rowClick={(id) => `/competition/event/${id}/show`}>
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<NumberField source="season_code" />
<NumberField source="competition" />
<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
render={(record) => record && <span>{record['publication_set'].length}</span>}
/>
</Datagrid>
</ArrayField>
</SimpleShowLayout>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {FC} from 'react'
import {
DateField,
FunctionField,
Labeled,
NumberField,
RaRecord,
SimpleShowLayout,
TextField,
useRecordContext,
useRedirect,
} from 'react-admin'

export const UpcomingOrCurrentEvent: FC = () => {
const record = useRecordContext()
const redirect = useRedirect()

return (
<Labeled
label="Prebiehajúca alebo najbližšia akcia"
onClick={() => redirect('show', 'competition/event', record.upcoming_or_current_event.competition)}
sx={{cursor: 'pointer'}}
>
<SimpleShowLayout record={record.upcoming_or_current_event}>
<NumberField source="year" />
<NumberField source="season_code" />
<TextField source="school_year" />
<DateField source="start" />
<DateField source="end" />
<TextField source="additional_name" />

<TextField source="registration_link.url" />
<DateField source="registration_link.start" />
<DateField source="registration_link.end" />
<TextField source="registration_link.additional_info" />

<FunctionField<RaRecord>
source="publication_set"
label="Publication count"
render={(record) => record && <span>{record['publication_set'].length}</span>}
/>
</SimpleShowLayout>
</Labeled>
)
}

0 comments on commit 4d45bd5

Please sign in to comment.