refactor(review-workflow): shorten the stage attribute name on entities (#16881)

* refactor(review-workflow): shorten the stage attribute name on entities

* fix(review-workflow): update data transfer
This commit is contained in:
Nathan Pichon 2023-06-01 17:49:00 +02:00 committed by GitHub
parent 5fa0dd54a2
commit 1baeabf6f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 22 deletions

View File

@ -49,13 +49,13 @@ This means at any place where the UI displays a stage, it has to be prepared to
## List view
The information which stage is current assigned to an entity is send as part of the content-type response payload for each entity in the attribute `strapi_reviewWorkflows_stage`.
The information which stage is current assigned to an entity is send as part of the content-type response payload for each entity in the attribute `strapi_stage`.
Please see [Data Shapes](/settings/review-workflows#data-shapes) for type definitions.
```ts
{
// ... entity attributes
strapi_reviewWorkflows_stage?: Stage | null
strapi_stage?: Stage | null
}
```
@ -66,13 +66,13 @@ add an additional check if the feature toggle returned in `http://localhost:1337
## Edit View
The information which stage is current assigned to an entity is send as part of the entity response payload in the attribute `strapi_reviewWorkflows_stage`.
The information which stage is current assigned to an entity is send as part of the entity response payload in the attribute `strapi_stage`.
Please see [Data Shapes](/settings/review-workflows#data-shapes) for type definitions.
```ts
{
// ... entity attributes
strapi_reviewWorkflows_stage?: Stage | null
strapi_stage?: Stage | null
}
```

View File

@ -22,8 +22,8 @@ export default (layout) => {
}
return {
key: '__strapi_reviewWorkflows_stage_temp_key__',
name: 'strapi_reviewWorkflows_stage',
key: '__strapi_stage_temp_key__',
name: 'strapi_stage',
fieldSchema: {
type: 'relation',
},
@ -41,14 +41,14 @@ export default (layout) => {
},
},
},
cellFormatter({ strapi_reviewWorkflows_stage }) {
cellFormatter({ strapi_stage }) {
// if entities are created e.g. through lifecycle methods
// they may not have a stage assigned
if (!strapi_reviewWorkflows_stage) {
if (!strapi_stage) {
return <Typography textColor="neutral800">-</Typography>;
}
const { color, name } = strapi_reviewWorkflows_stage;
const { color, name } = strapi_stage;
return <ReviewWorkflowsStage color={color ?? STAGE_COLOR_DEFAULT} name={name} />;
},

View File

@ -15,7 +15,7 @@ import { OptionColor } from '../../../../pages/SettingsPage/pages/ReviewWorkflow
import { SingleValueColor } from '../../../../pages/SettingsPage/pages/ReviewWorkflows/components/Stages/Stage/components/SingleValueColor';
import Information from '../../../../../../admin/src/content-manager/pages/EditView/Information';
const ATTRIBUTE_NAME = 'strapi_reviewWorkflows_stage';
const ATTRIBUTE_NAME = 'strapi_stage';
export function InformationBoxEE() {
const {

View File

@ -10,7 +10,7 @@ import { createStore } from 'redux';
import { InformationBoxEE } from '../InformationBoxEE';
import { useReviewWorkflows } from '../../../../../pages/SettingsPage/pages/ReviewWorkflows/hooks/useReviewWorkflows';
const STAGE_ATTRIBUTE_NAME = 'strapi_reviewWorkflows_stage';
const STAGE_ATTRIBUTE_NAME = 'strapi_stage';
const STAGE_FIXTURE = {
id: 1,
color: '#4945FF',

View File

@ -5,5 +5,5 @@ module.exports = {
WORKFLOW_MODEL_UID: 'admin::workflow',
STAGE_MODEL_UID: 'admin::workflow-stage',
STAGE_DEFAULT_COLOR: '#4945FF',
ENTITY_STAGE_ATTRIBUTE: 'strapi_reviewWorkflows_stage',
ENTITY_STAGE_ATTRIBUTE: 'strapi_stage',
};

View File

@ -94,9 +94,9 @@ const strapiMock = {
get: () => ({
tableName: 'test',
attributes: {
strapi_reviewWorkflows_stage: {
strapi_stage: {
joinColumn: {
name: 'strapi_reviewWorkflows_stage_id',
name: 'strapi_stage_id',
},
},
},

View File

@ -83,7 +83,7 @@ describe('Entity service decorator', () => {
...input,
data: {
...input.data,
strapi_reviewWorkflows_stage: 1,
strapi_stage: 1,
},
});
});
@ -120,14 +120,14 @@ describe('Entity service decorator', () => {
const service = decorator(defaultService);
const id = 1;
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: 1 } };
const input = { data: { title: 'title ', strapi_stage: 1 } };
await service.update('test-model', id, input);
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
...input,
data: {
...input.data,
strapi_reviewWorkflows_stage: 1,
strapi_stage: 1,
},
});
});
@ -144,13 +144,13 @@ describe('Entity service decorator', () => {
const service = decorator(defaultService);
const id = 1;
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: null } };
const input = { data: { title: 'title ', strapi_stage: null } };
await service.update('test-model', id, input);
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
...input,
data: {
...omit('strapi_reviewWorkflows_stage', input.data),
...omit('strapi_stage', input.data),
},
});
});

View File

@ -11,7 +11,7 @@ const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
const { persistTables, removePersistedTablesWithSuffix } = require('../../utils/persisted-tables');
const MAX_DB_TABLE_NAME_LEN = 63; // Postgres limit
// The longest index name that Strapi can create is prefixed with '_strapi_reviewWorkflow_stage_links_inv_fk', so the content type name should be no longer than this.
// The longest index name that Strapi can create is prefixed with '_strapi_stage_links_inv_fk', so the content type name should be no longer than this.
const MAX_JOIN_TABLE_NAME_SUFFIX =
1 /* _ */ + ENTITY_STAGE_ATTRIBUTE.length + '_links_inv_fk'.length;
const MAX_CONTENT_TYPE_NAME_LEN = MAX_DB_TABLE_NAME_LEN - MAX_JOIN_TABLE_NAME_SUFFIX;
@ -83,7 +83,7 @@ function persistStagesJoinTables({ strapi }) {
])(contentTypes);
// TODO: Instead of removing all the tables, we should only remove the ones that are not in the joinTablesToPersist
await removePersistedTablesWithSuffix('_strapi_review_workflows_stage_links');
await removePersistedTablesWithSuffix('_strapi_stage_links');
await persistTables(joinTablesToPersist);
};
}

View File

@ -291,7 +291,7 @@ const getDiffHandler = (engine, { force, action }) => {
if (
uid === 'admin::workflow' ||
uid === 'admin::workflow-stage' ||
endPath?.startsWith('strapi_reviewWorkflows_')
endPath?.startsWith('strapi_stage')
) {
workflowsStatus = diff.kind;
}