-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6217 from marmelab/ra-no-code-configuration
ra-no-code - Introduce Resource Configuration
- Loading branch information
Showing
24 changed files
with
576 additions
and
100 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
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
12 changes: 12 additions & 0 deletions
12
packages/ra-no-code/src/ResourceConfiguration/FieldConfiguration/FieldTypeInput.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,12 @@ | ||
import * as React from 'react'; | ||
import { InferenceTypes } from 'ra-core'; | ||
import { FieldProps, SelectInput } from 'ra-ui-materialui'; | ||
|
||
export const FieldTypeInput = (props: FieldProps) => ( | ||
<SelectInput choices={INFERENCE_TYPES} {...props} /> | ||
); | ||
|
||
const INFERENCE_TYPES = InferenceTypes.map(type => ({ | ||
id: type, | ||
name: type, | ||
})); |
31 changes: 31 additions & 0 deletions
31
packages/ra-no-code/src/ResourceConfiguration/FieldConfiguration/FieldViewsInput.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 * as React from 'react'; | ||
import { CheckboxGroupInput, FieldProps } from 'ra-ui-materialui'; | ||
|
||
export const FieldViewsInput = (props: FieldProps) => ( | ||
<CheckboxGroupInput | ||
{...props} | ||
choices={VIEWS} | ||
initialValue={VIEWS_INITIAL_VALUE} | ||
/> | ||
); | ||
|
||
const VIEWS = [ | ||
{ | ||
id: 'list', | ||
name: 'List', | ||
}, | ||
{ | ||
id: 'edit', | ||
name: 'Edit', | ||
}, | ||
{ | ||
id: 'create', | ||
name: 'Create', | ||
}, | ||
{ | ||
id: 'show', | ||
name: 'Show', | ||
}, | ||
]; | ||
|
||
const VIEWS_INITIAL_VALUE = ['list', 'edit', 'create', 'show']; |
2 changes: 2 additions & 0 deletions
2
packages/ra-no-code/src/ResourceConfiguration/FieldConfiguration/index.ts
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,2 @@ | ||
export * from './FieldTypeInput'; | ||
export * from './FieldViewsInput'; |
43 changes: 43 additions & 0 deletions
43
packages/ra-no-code/src/ResourceConfiguration/FieldConfigurationFormSection.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,43 @@ | ||
import * as React from 'react'; | ||
import { getFieldLabelTranslationArgs, useTranslate } from 'ra-core'; | ||
import { TextInput } from 'ra-ui-materialui'; | ||
import { CardContent } from '@material-ui/core'; | ||
import { FieldTypeInput } from './FieldConfiguration/FieldTypeInput'; | ||
import { FieldViewsInput } from './FieldConfiguration/FieldViewsInput'; | ||
|
||
export const FieldConfigurationFormSection = props => { | ||
const { sourcePrefix, field, resource } = props; | ||
const translate = useTranslate(); | ||
const labelArgs = getFieldLabelTranslationArgs({ | ||
source: field.props.source, | ||
resource, | ||
label: field.props.label, | ||
}); | ||
|
||
return ( | ||
<CardContent> | ||
<TextInput | ||
source={`${sourcePrefix}.props.source`} | ||
label="Source" | ||
fullWidth | ||
disabled | ||
/> | ||
<TextInput | ||
source={`${sourcePrefix}.props.label`} | ||
label="Label" | ||
fullWidth | ||
initialValue={translate(...labelArgs)} | ||
/> | ||
<FieldTypeInput | ||
source={`${sourcePrefix}.type`} | ||
label="Type" | ||
fullWidth | ||
/> | ||
<FieldViewsInput | ||
source={`${sourcePrefix}.views`} | ||
label="Views" | ||
fullWidth | ||
/> | ||
</CardContent> | ||
); | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/ra-no-code/src/ResourceConfiguration/FieldConfigurationTab.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,40 @@ | ||
import * as React from 'react'; | ||
import { Tab } from '@material-ui/core'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { getFieldLabelTranslationArgs, useTranslate } from 'ra-core'; | ||
|
||
export const FieldConfigurationTab = ({ field, resource, ...props }) => { | ||
const classes = useStyles(); | ||
const translate = useTranslate(); | ||
const labelArgs = getFieldLabelTranslationArgs({ | ||
source: field.props.source, | ||
resource, | ||
label: field.props.label, | ||
}); | ||
|
||
return ( | ||
<Tab | ||
{...props} | ||
key={field.props.source} | ||
label={translate(...labelArgs)} | ||
id={`nav-tab-${field.props.source}`} | ||
aria-controls={`nav-tabpanel-${field.props.source}`} | ||
classes={classes} | ||
/> | ||
); | ||
}; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
root: { | ||
paddingTop: theme.spacing(1), | ||
paddingBottom: theme.spacing(1), | ||
paddingLeft: theme.spacing(2), | ||
paddingRight: theme.spacing(2), | ||
textTransform: 'none', | ||
minHeight: 0, | ||
fontWeight: 'normal', | ||
}, | ||
selected: { | ||
fontWeight: 'bold', | ||
}, | ||
})); |
Oops, something went wrong.