Fix migration split ct & st

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-11-17 12:16:17 +01:00
parent 402b5db42b
commit 63f376e3fd
7 changed files with 61 additions and 75 deletions

View File

@ -180,7 +180,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
<PermissionName disabled> <PermissionName disabled>
<Checkbox <Checkbox
onChange={handleAllContentTypeActions} onChange={handleAllContentTypeActions}
name={contentType.name} name={contentType.info.name}
disabled={isSuperAdmin} disabled={isSuperAdmin}
someChecked={ someChecked={
contentTypeActions.length > 0 && contentTypeActions.length > 0 &&
@ -190,7 +190,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
value={allCurrentActionsSize === allActionsSize} value={allCurrentActionsSize === allActionsSize}
/> />
<CollapseLabel <CollapseLabel
title={contentType.name} title={contentType.info.name}
alignItems="center" alignItems="center"
isCollapsable isCollapsable
onClick={handleToggleAttributes} onClick={handleToggleAttributes}
@ -203,7 +203,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
lineHeight="20px" lineHeight="20px"
textTransform="uppercase" textTransform="uppercase"
> >
{contentType.name} {contentType.info.name}
</Text> </Text>
<Chevron icon={isActive ? 'chevron-up' : 'chevron-down'} /> <Chevron icon={isActive ? 'chevron-up' : 'chevron-down'} />
</CollapseLabel> </CollapseLabel>
@ -216,7 +216,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
hasConditions={checkConditions(permissionLayout.action)} hasConditions={checkConditions(permissionLayout.action)}
disabled disabled
value={hasContentTypeAction(permissionLayout.action)} value={hasContentTypeAction(permissionLayout.action)}
name={`${contentType.name}-${permissionLayout.action}`} name={`${contentType.info.name}-${permissionLayout.action}`}
/> />
) : ( ) : (
<PermissionCheckbox <PermissionCheckbox
@ -225,7 +225,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
disabled disabled
value={hasContentTypeAction(permissionLayout.action)} value={hasContentTypeAction(permissionLayout.action)}
someChecked={hasSomeAttributeByAction(permissionLayout.action)} someChecked={hasSomeAttributeByAction(permissionLayout.action)}
name={`${contentType.name}-${permissionLayout.action}`} name={`${contentType.info.name}-${permissionLayout.action}`}
/> />
) )
)} )}

View File

@ -448,7 +448,7 @@ const reducer = (state, action) =>
} }
case 'ON_GLOBAL_PUBLISH_ACTION_SELECT': { case 'ON_GLOBAL_PUBLISH_ACTION_SELECT': {
const contentTypesWithPublishAction = action.contentTypes const contentTypesWithPublishAction = action.contentTypes
.filter(contentType => contentType.schema.options.draftAndPublish === true) .filter(contentType => contentType.options.draftAndPublish === true)
.map(contentType => contentType.uid); .map(contentType => contentType.uid);
contentTypesWithPublishAction.forEach(contentTypeUID => { contentTypesWithPublishAction.forEach(contentTypeUID => {

View File

@ -56,11 +56,9 @@ export const permissions = {
export const contentTypes = [ export const contentTypes = [
{ {
uid: 'application::address.address', uid: 'application::address.address',
schema: {
options: { options: {
timestamps: ['updated_at', 'created_at'], timestamps: ['updated_at', 'created_at'],
}, },
modelType: 'contentType',
attributes: { attributes: {
id: { type: 'integer' }, id: { type: 'integer' },
city: { type: 'string', required: false }, city: { type: 'string', required: false },
@ -73,14 +71,11 @@ export const contentTypes = [
updated_at: { type: 'timestamp' }, updated_at: { type: 'timestamp' },
}, },
}, },
},
{ {
uid: 'application::places.places', uid: 'application::places.places',
schema: {
options: { options: {
timestamps: ['updated_at', 'created_at'], timestamps: ['updated_at', 'created_at'],
}, },
modelType: 'contentType',
attributes: { attributes: {
id: { type: 'integer' }, id: { type: 'integer' },
like: { type: 'string', required: false }, like: { type: 'string', required: false },
@ -90,13 +85,11 @@ export const contentTypes = [
updated_at: { type: 'timestamp' }, updated_at: { type: 'timestamp' },
}, },
}, },
},
]; ];
export const components = [ export const components = [
{ {
uid: 'default.closingperiod', uid: 'default.closingperiod',
schema: {
attributes: { attributes: {
id: { type: 'integer' }, id: { type: 'integer' },
start_date: { type: 'date', required: true }, start_date: { type: 'date', required: true },
@ -107,27 +100,22 @@ export const components = [
media: { type: 'media', multiple: false, required: false }, media: { type: 'media', multiple: false, required: false },
}, },
}, },
},
{ {
uid: 'default.dish', uid: 'default.dish',
schema: {
attributes: { attributes: {
description: { type: 'text' }, description: { type: 'text' },
id: { type: 'integer' }, id: { type: 'integer' },
name: { type: 'string', required: true, default: 'My super dish' }, name: { type: 'string', required: true, default: 'My super dish' },
}, },
}, },
},
{ {
uid: 'default.restaurantservice', uid: 'default.restaurantservice',
schema: {
attributes: { attributes: {
is_available: { type: 'boolean', required: true, default: true }, is_available: { type: 'boolean', required: true, default: true },
id: { type: 'integer' }, id: { type: 'integer' },
name: { type: 'string', required: true, default: 'something' }, name: { type: 'string', required: true, default: 'something' },
}, },
}, },
},
]; ];
export const permissionsLayout = { export const permissionsLayout = {

View File

@ -363,7 +363,7 @@ function EditView() {
}; };
const shouldShowDPEvents = useMemo( const shouldShowDPEvents = useMemo(
() => collectionTypes.some(ct => ct.schema.options.draftAndPublish === true), () => collectionTypes.some(ct => ct.options.draftAndPublish === true),
[collectionTypes] [collectionTypes]
); );

View File

@ -1,13 +1,13 @@
import { get } from 'lodash'; import { get } from 'lodash';
const getAttributesToDisplay = contentType => { const getAttributesToDisplay = contentType => {
const timestamps = get(contentType, ['schema', 'options', 'timestamps']); const timestamps = get(contentType, ['options', 'timestamps']);
// Sometimes timestamps is false // Sometimes timestamps is false
let timestampsArray = Array.isArray(timestamps) ? timestamps : []; let timestampsArray = Array.isArray(timestamps) ? timestamps : [];
const idsAttributes = ['id', '_id']; // For both SQL and mongo const idsAttributes = ['id', '_id']; // For both SQL and mongo
const unwritableAttributes = [...idsAttributes, ...timestampsArray, 'published_at']; const unwritableAttributes = [...idsAttributes, ...timestampsArray, 'published_at'];
const schemaAttributes = get(contentType, ['schema', 'attributes'], {}); const schemaAttributes = get(contentType, ['attributes'], {});
return Object.keys(schemaAttributes).reduce((acc, current) => { return Object.keys(schemaAttributes).reduce((acc, current) => {
if (!unwritableAttributes.includes(current)) { if (!unwritableAttributes.includes(current)) {

View File

@ -3,7 +3,6 @@ import { getAttributesToDisplay } from '../index';
describe('ADMIN | utils | getAttributesToDisplay', () => { describe('ADMIN | utils | getAttributesToDisplay', () => {
it('should return attributes without id and timestamps', () => { it('should return attributes without id and timestamps', () => {
const contentType = { const contentType = {
schema: {
attributes: { attributes: {
id: { type: 'number' }, id: { type: 'number' },
title: { type: 'string' }, title: { type: 'string' },
@ -15,7 +14,6 @@ describe('ADMIN | utils | getAttributesToDisplay', () => {
options: { options: {
timestamps: ['created_at', 'updated_at'], timestamps: ['created_at', 'updated_at'],
}, },
},
}; };
const actual = getAttributesToDisplay(contentType); const actual = getAttributesToDisplay(contentType);
const expectedAttributes = [ const expectedAttributes = [

View File

@ -210,7 +210,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
<PermissionName disabled={isSuperAdmin}> <PermissionName disabled={isSuperAdmin}>
<Checkbox <Checkbox
onChange={handleAllContentTypeActions} onChange={handleAllContentTypeActions}
name={contentType.name} name={contentType.info.name}
disabled={isSuperAdmin} disabled={isSuperAdmin}
someChecked={ someChecked={
contentTypeActions.length > 0 && contentTypeActions.length > 0 &&
@ -220,7 +220,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
value={allCurrentActionsSize === allActionsSize} value={allCurrentActionsSize === allActionsSize}
/> />
<CollapseLabel <CollapseLabel
title={contentType.name} title={contentType.info.name}
alignItems="center" alignItems="center"
isCollapsable isCollapsable
onClick={handleToggleAttributes} onClick={handleToggleAttributes}
@ -233,7 +233,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
lineHeight="20px" lineHeight="20px"
textTransform="uppercase" textTransform="uppercase"
> >
{contentType.name} {contentType.info.name}
</Text> </Text>
<Chevron icon={isActive ? 'chevron-up' : 'chevron-down'} /> <Chevron icon={isActive ? 'chevron-up' : 'chevron-down'} />
</CollapseLabel> </CollapseLabel>
@ -246,7 +246,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
hasConditions={checkConditions(permissionLayout.action)} hasConditions={checkConditions(permissionLayout.action)}
disabled={isSuperAdmin} disabled={isSuperAdmin}
value={hasContentTypeAction(permissionLayout.action)} value={hasContentTypeAction(permissionLayout.action)}
name={`${contentType.name}-${permissionLayout.action}`} name={`${contentType.info.name}-${permissionLayout.action}`}
onChange={() => handleContentTypeActionSelect(permissionLayout.action)} onChange={() => handleContentTypeActionSelect(permissionLayout.action)}
/> />
) : ( ) : (
@ -256,7 +256,7 @@ const ContentTypeRow = ({ index, contentType, permissionsLayout }) => {
disabled={isSuperAdmin} disabled={isSuperAdmin}
value={hasContentTypeAction(permissionLayout.action)} value={hasContentTypeAction(permissionLayout.action)}
someChecked={hasSomeAttributeByAction(permissionLayout.action)} someChecked={hasSomeAttributeByAction(permissionLayout.action)}
name={`${contentType.name}-${permissionLayout.action}`} name={`${contentType.info.name}-${permissionLayout.action}`}
onChange={() => handleActionSelect(permissionLayout.action)} onChange={() => handleActionSelect(permissionLayout.action)}
/> />
) )