Merge pull request #1754 from payloadcms/fix/#1752

fix: #1752, removes label from row field type
This commit is contained in:
James Mikrut
2022-12-23 10:51:48 -05:00
committed by GitHub
7 changed files with 11 additions and 11 deletions

View File

@@ -39,7 +39,7 @@ const DefaultCell: React.FC<Props> = (props) => {
if (!CellComponent) {
return (
<WrapElement {...wrapElementProps}>
{(cellData === '' || typeof cellData === 'undefined') && t('noLabel', { label: getTranslation(typeof field.label === 'function' ? 'data' : field.label || 'data', i18n) })}
{((cellData === '' || typeof cellData === 'undefined') && 'label' in field) && t('noLabel', { label: getTranslation(typeof field.label === 'function' ? 'data' : field.label || 'data', i18n) })}
{typeof cellData === 'string' && cellData}
{typeof cellData === 'number' && cellData}
{typeof cellData === 'object' && JSON.stringify(cellData)}

View File

@@ -1,8 +1,8 @@
import { Field } from '../fields/config/types';
import { FieldAffectingData } from '../fields/config/types';
import APIError from './APIError';
class InvalidFieldName extends APIError {
constructor(field: Field, fieldName: string) {
constructor(field: FieldAffectingData, fieldName: string) {
super(`Field ${field.label} has invalid name '${fieldName}'. Field names can not include periods (.) and must be alphanumeric.`);
}
}

View File

@@ -1,8 +1,8 @@
import { Field } from '../fields/config/types';
import { RelationshipField, UploadField } from '../fields/config/types';
import APIError from './APIError';
class InvalidFieldRelationship extends APIError {
constructor(field: Field, relationship: string) {
constructor(field: RelationshipField | UploadField, relationship: string) {
super(`Field ${field.label} has invalid relationship '${relationship}'.`);
}
}

View File

@@ -1,8 +1,8 @@
import { Field } from '../fields/config/types';
import { RadioField, SelectField } from '../fields/config/types';
import APIError from './APIError';
class MissingFieldInputOptions extends APIError {
constructor(field: Field) {
constructor(field: SelectField | RadioField) {
super(`Field ${field.label} is missing options.`);
}
}

View File

@@ -1,6 +1,6 @@
import sanitizeFields from './sanitize';
import { MissingFieldType, InvalidFieldRelationship, InvalidFieldName } from '../../errors';
import { ArrayField, Block, BlockField, CheckboxField, Field, TextField } from './types';
import { ArrayField, Block, BlockField, CheckboxField, Field, NumberField, TextField } from './types';
describe('sanitizeFields', () => {
it('should throw on missing type field', () => {
@@ -143,7 +143,7 @@ describe('sanitizeFields', () => {
expect(sanitizedField.label).toStrictEqual('Special Block');
expect(sanitizedField.type).toStrictEqual('blocks');
expect(sanitizedField.labels).toMatchObject({ singular: 'Special Block', plural: 'Special Blocks' });
expect(sanitizedField.blocks[0].fields[0].label).toStrictEqual('Test Number');
expect((sanitizedField.blocks[0].fields[0] as NumberField).label).toStrictEqual('Test Number');
});
});

View File

@@ -15,7 +15,7 @@ const sanitizeFields = (fields: Field[], validRelationships: string[]): Field[]
if (!field.type) throw new MissingFieldType(field);
// assert that field names do not contain forbidden characters
if ('name' in field && field.name && field.name.includes('.')) {
if (fieldAffectsData(field) && field.name.includes('.')) {
throw new InvalidFieldName(field, field.name);
}

View File

@@ -183,7 +183,7 @@ export type GroupField = FieldBase & {
export type RowAdmin = Omit<Admin, 'description'>;
export type RowField = Omit<FieldBase, 'admin' | 'name'> & {
export type RowField = Omit<FieldBase, 'admin' | 'name' | 'label'> & {
admin?: RowAdmin;
type: 'row';
fields: Field[];