-
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.
- Loading branch information
1 parent
1f2be85
commit 7232148
Showing
6 changed files
with
66 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,14 +1,9 @@ | ||
import {CheckboxGroupInput, required} from 'react-admin' | ||
import {CheckboxGroupInput} from 'react-admin' | ||
|
||
import {seminarIdToName} from '@/utils/useSeminarInfo' | ||
|
||
const choices = Object.entries(seminarIdToName).map(([id, name]) => ({id, name})) | ||
|
||
export const SitesCheckboxInput: typeof CheckboxGroupInput = (props) => ( | ||
<CheckboxGroupInput | ||
choices={[ | ||
{id: 1, name: 'Strom'}, | ||
{id: 2, name: 'Matik'}, | ||
{id: 3, name: 'Malynar'}, | ||
{id: 4, name: 'Zdruzenie'}, | ||
]} | ||
validate={required()} | ||
{...props} | ||
/> | ||
<CheckboxGroupInput choices={choices} {...props} /> | ||
) |
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,16 @@ | ||
import {FC} from 'react' | ||
import {FieldProps, useRecordContext} from 'react-admin' | ||
|
||
type TruncatedTextFieldProps = FieldProps & { | ||
maxTextWidth: number | ||
} | ||
|
||
export const TruncatedTextField: FC<TruncatedTextFieldProps> = ({source, maxTextWidth}) => { | ||
const record = useRecordContext() | ||
if (!record || !source) return null | ||
|
||
const text = record[source] | ||
const isString = typeof text === 'string' | ||
|
||
return <span>{isString && text.length > maxTextWidth ? text.slice(0, maxTextWidth - 3) + '...' : text}</span> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import {FC} from 'react' | ||
import {Datagrid, DateField, List, NumberField, TextField} from 'react-admin' | ||
import {Datagrid, DateField, FunctionField, List, NumberField, RaRecord, TextField} from 'react-admin' | ||
|
||
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' | ||
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' | ||
|
||
export const PostList: FC = () => ( | ||
<List> | ||
<Datagrid rowClick="show"> | ||
<NumberField source="id" /> | ||
<TextField source="caption" /> | ||
<TextField source="short_text" /> | ||
<TextField source="details" /> | ||
<TruncatedTextField source="short_text" maxTextWidth={50} /> | ||
<TruncatedTextField source="details" maxTextWidth={50} /> | ||
<DateField source="added_at" /> | ||
<DateField source="visible_after" /> | ||
<DateField source="visible_until" /> | ||
{/* <ArrayField source="links" /> */} | ||
{/* <ArrayField source="sites" /> */} | ||
<SitesArrayField source="sites" /> | ||
<FunctionField<RaRecord> | ||
source="links" | ||
label="Link count" | ||
render={(record) => record && <span>{record['links'].length}</span>} | ||
/> | ||
</Datagrid> | ||
</List> | ||
) |