-
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 - Flatpage management (#251)
* expandable TruncatedTextField * flatpage management * multiline inputs * multiline inputs for posts * remove unnecessary boolean pages
- Loading branch information
1 parent
72a0ba6
commit 3bc981e
Showing
10 changed files
with
105 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
import {FC} from 'react' | ||
import {Typography} from '@mui/material' | ||
import {FC, useState} from 'react' | ||
import {FieldProps, useRecordContext} from 'react-admin' | ||
|
||
type TruncatedTextFieldProps = FieldProps & { | ||
maxTextWidth: number | ||
expandable?: boolean | ||
} | ||
|
||
export const TruncatedTextField: FC<TruncatedTextFieldProps> = ({source, maxTextWidth}) => { | ||
export const TruncatedTextField: FC<TruncatedTextFieldProps> = ({source, maxTextWidth, expandable = false}) => { | ||
const [truncate, setTruncate] = useState(true) | ||
|
||
const record = useRecordContext() | ||
if (!record || !source) return null | ||
|
||
const text = record[source] | ||
const isString = typeof text === 'string' | ||
const isOverLimit = isString && text.length > maxTextWidth | ||
|
||
const expandableProps = | ||
expandable && isOverLimit | ||
? { | ||
onClick: () => setTruncate((prev) => !prev), | ||
sx: {cursor: 'pointer'}, | ||
} | ||
: {} | ||
|
||
return <span>{isString && text.length > maxTextWidth ? text.slice(0, maxTextWidth - 3) + '...' : text}</span> | ||
return ( | ||
<Typography variant="body2" {...expandableProps}> | ||
{isOverLimit && truncate ? text.slice(0, maxTextWidth - 3) + '...' : text} | ||
</Typography> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/Admin/resources/base/flat-page/FlatpageCreate.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,17 @@ | ||
import {FC} from 'react' | ||
import {NumberInput, required, SimpleForm, TextInput} from 'react-admin' | ||
|
||
import {MyCreate} from '@/components/Admin/custom/MyCreate' | ||
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput' | ||
|
||
export const FlatpageCreate: FC = () => ( | ||
<MyCreate> | ||
<SimpleForm> | ||
<NumberInput source="id" fullWidth disabled /> | ||
<TextInput source="url" fullWidth validate={required()} /> | ||
<TextInput source="title" fullWidth validate={required()} /> | ||
<TextInput source="content" multiline fullWidth validate={required()} /> | ||
<SitesCheckboxInput source="sites" validate={required()} /> | ||
</SimpleForm> | ||
</MyCreate> | ||
) |
17 changes: 17 additions & 0 deletions
17
src/components/Admin/resources/base/flat-page/FlatpageEdit.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,17 @@ | ||
import {FC} from 'react' | ||
import {NumberInput, required, SimpleForm, TextInput} from 'react-admin' | ||
|
||
import {MyEdit} from '@/components/Admin/custom/MyEdit' | ||
import {SitesCheckboxInput} from '@/components/Admin/custom/SitesCheckboxInput' | ||
|
||
export const FlatpageEdit: FC = () => ( | ||
<MyEdit> | ||
<SimpleForm> | ||
<NumberInput source="id" fullWidth disabled /> | ||
<TextInput source="url" fullWidth validate={required()} /> | ||
<TextInput source="title" fullWidth validate={required()} /> | ||
<TextInput source="content" multiline fullWidth validate={required()} /> | ||
<SitesCheckboxInput source="sites" validate={required()} /> | ||
</SimpleForm> | ||
</MyEdit> | ||
) |
17 changes: 17 additions & 0 deletions
17
src/components/Admin/resources/base/flat-page/FlatpageList.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,17 @@ | ||
import {FC} from 'react' | ||
import {Datagrid, List, NumberField, TextField} from 'react-admin' | ||
|
||
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' | ||
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' | ||
|
||
export const FlatpageList: FC = () => ( | ||
<List> | ||
<Datagrid rowClick="show"> | ||
<NumberField source="id" /> | ||
<TextField source="url" /> | ||
<TextField source="title" /> | ||
<TruncatedTextField source="content" maxTextWidth={30} /> | ||
<SitesArrayField source="sites" /> | ||
</Datagrid> | ||
</List> | ||
) |
18 changes: 18 additions & 0 deletions
18
src/components/Admin/resources/base/flat-page/FlatpageShow.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,18 @@ | ||
import {FC} from 'react' | ||
import {NumberField, Show, SimpleShowLayout, TextField} from 'react-admin' | ||
|
||
import {MyShowActions} from '@/components/Admin/custom/MyShowActions' | ||
import {SitesArrayField} from '@/components/Admin/custom/SitesArrayField' | ||
import {TruncatedTextField} from '@/components/Admin/custom/TruncatedTextField' | ||
|
||
export const FlatpageShow: FC = () => ( | ||
<Show actions={<MyShowActions />}> | ||
<SimpleShowLayout> | ||
<NumberField source="id" /> | ||
<TextField source="url" /> | ||
<TextField source="title" /> | ||
<TruncatedTextField source="content" maxTextWidth={200} expandable /> | ||
<SitesArrayField source="sites" /> | ||
</SimpleShowLayout> | ||
</Show> | ||
) |
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
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