mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Use custom field input size in admin
This commit is contained in:
parent
5942cce591
commit
cb3588782c
@ -9,7 +9,13 @@ import flatMap from 'lodash/flatMap';
|
|||||||
import isEqual from 'lodash/isEqual';
|
import isEqual from 'lodash/isEqual';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import set from 'lodash/set';
|
import set from 'lodash/set';
|
||||||
import { useNotification, useTracking, ConfirmDialog, Link } from '@strapi/helper-plugin';
|
import {
|
||||||
|
useNotification,
|
||||||
|
useTracking,
|
||||||
|
useCustomFields,
|
||||||
|
ConfirmDialog,
|
||||||
|
Link,
|
||||||
|
} from '@strapi/helper-plugin';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
Main,
|
Main,
|
||||||
@ -52,6 +58,11 @@ const EditSettingsView = ({ mainLayout, components, isContentTypeView, slug, upd
|
|||||||
const modelName = get(mainLayout, ['info', 'displayName'], '');
|
const modelName = get(mainLayout, ['info', 'displayName'], '');
|
||||||
const attributes = get(modifiedData, ['attributes'], {});
|
const attributes = get(modifiedData, ['attributes'], {});
|
||||||
const fieldSizes = useSelector(selectFieldSizes);
|
const fieldSizes = useSelector(selectFieldSizes);
|
||||||
|
const customFieldsRegistry = useCustomFields();
|
||||||
|
console.log('registry', customFieldsRegistry.getAll());
|
||||||
|
|
||||||
|
// TODO: find out why logs don't show on port 8000
|
||||||
|
// TODO: find out why custom fields registry is empty
|
||||||
|
|
||||||
const entryTitleOptions = Object.keys(attributes).filter((attr) => {
|
const entryTitleOptions = Object.keys(attributes).filter((attr) => {
|
||||||
const type = get(attributes, [attr, 'type'], '');
|
const type = get(attributes, [attr, 'type'], '');
|
||||||
@ -322,6 +333,7 @@ const EditSettingsView = ({ mainLayout, components, isContentTypeView, slug, upd
|
|||||||
type: 'ON_ADD_FIELD',
|
type: 'ON_ADD_FIELD',
|
||||||
name: field,
|
name: field,
|
||||||
fieldSizes,
|
fieldSizes,
|
||||||
|
getCustomField: customFieldsRegistry.get,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onRemoveField={(rowId, index) => {
|
onRemoveField={(rowId, index) => {
|
||||||
|
@ -30,8 +30,14 @@ const reducer = (state = initialState, action) =>
|
|||||||
}
|
}
|
||||||
case 'ON_ADD_FIELD': {
|
case 'ON_ADD_FIELD': {
|
||||||
const newState = cloneDeep(state);
|
const newState = cloneDeep(state);
|
||||||
const type = get(newState, ['modifiedData', 'attributes', action.name, 'type'], '');
|
const attribute = get(newState, ['modifiedData', 'attributes', action.name], {});
|
||||||
const size = action.fieldSizes[type]?.default ?? DEFAULT_FIELD_SIZE;
|
|
||||||
|
// Get the default size, checking custom fields first, then the type and generic defaults
|
||||||
|
const size =
|
||||||
|
action.fieldSizes[attribute?.customField]?.default ??
|
||||||
|
action.fieldSizes[attribute?.type]?.default ??
|
||||||
|
DEFAULT_FIELD_SIZE;
|
||||||
|
|
||||||
const listSize = get(newState, layoutPathEdit, []).length;
|
const listSize = get(newState, layoutPathEdit, []).length;
|
||||||
const actualRowContentPath = [...layoutPathEdit, listSize - 1, 'rowContent'];
|
const actualRowContentPath = [...layoutPathEdit, listSize - 1, 'rowContent'];
|
||||||
const rowContentToSet = get(newState, actualRowContentPath, []);
|
const rowContentToSet = get(newState, actualRowContentPath, []);
|
||||||
|
@ -25,7 +25,7 @@ const getDefaultFieldSize = (attribute) => {
|
|||||||
if (attribute.customField) {
|
if (attribute.customField) {
|
||||||
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
||||||
if (customField.inputSize) {
|
if (customField.inputSize) {
|
||||||
return customField.inputSize;
|
return customField.inputSize.default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user