RelationInputWrapper: Move publication states into a constant

This commit is contained in:
Gustav Hansen 2022-08-24 14:43:04 +02:00
parent 535dfc9dee
commit 6ff74c9455
3 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import { RelationInput, useCMEditViewDataManager, NotAllowedInput } from '@strap
import { useRelation } from '../../hooks/useRelation';
import { connect, select, normalizeRelations } from './utils';
import { PUBLICATION_STATES } from './constants';
export const RelationInputWrapper = ({
editable,
@ -97,12 +98,12 @@ export const RelationInputWrapper = ({
onSearch={() => handleSearch()}
onSearchNextPage={() => handleSearchMore()}
publicationStateTranslations={{
draft: formatMessage({
[PUBLICATION_STATES.DRAFT]: formatMessage({
id: 'tbd',
defaultMessage: 'Draft',
}),
published: formatMessage({
[PUBLICATION_STATES.PUBLISHED]: formatMessage({
id: 'tbd',
defaultMessage: 'Published',
}),

View File

@ -0,0 +1,4 @@
export const PUBLICATION_STATES = {
DRAFT: 'draft',
PUBLISHED: 'published',
};

View File

@ -1,5 +1,7 @@
import { getRelationLink } from './getRelationLink';
import { PUBLICATION_STATES } from '../constants';
export const normalizeRelations = (
relations,
{ deletions = [], shouldAddLink = false, mainFieldName, targetModel }
@ -23,7 +25,9 @@ export const normalizeRelations = (
nextRelation.publicationState = false;
if (nextRelation?.publishedAt !== undefined) {
nextRelation.publicationState = nextRelation.publishedAt ? 'published' : 'draft';
nextRelation.publicationState = nextRelation.publishedAt
? PUBLICATION_STATES.PUBLISHED
: PUBLICATION_STATES.DRAFT;
}
nextRelation.mainField = nextRelation[mainFieldName];