Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/cma-client/__tests__/inspectItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,15 @@ describe('inspectItem', () => {
title: 'English file title',
custom_data: {},
focal_point: null,
poster_time: null,
},
it: {
upload_id: 'italian-file-id',
alt: 'Testo alternativo italiano',
title: 'Titolo file italiano',
custom_data: { locale: 'it' },
focal_point: { x: 0.6, y: 0.4 },
poster_time: null,
},
},

Expand Down
8 changes: 6 additions & 2 deletions packages/cma-client/src/fieldTypes/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import type { RequiredAltTitleValidator } from './validators/required_alt_title.
* which contain file uploads with optional metadata like alt text, title, custom data, and focal points.
*
* The challenge we're solving:
* - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point)
* - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point, poster_time)
* - For API requests, all these fields are optional and can be omitted
* - For API responses, DatoCMS provides default values for missing fields:
* - alt: null
* - title: null
* - custom_data: {}
* - focal_point: null
* - poster_time: null
* - This creates a need for different type variants for the same conceptual data structure
*
* This module provides separate types for:
Expand Down Expand Up @@ -52,6 +53,7 @@ export type FileFieldValue = {
x: number;
y: number;
} | null;
poster_time: number | null;
} | null;

/**
Expand All @@ -75,6 +77,7 @@ export type FileFieldValueInRequest = {
x: number;
y: number;
} | null;
poster_time?: number | null;
} | null;

/**
Expand All @@ -95,7 +98,8 @@ export function isFileFieldValue(value: unknown): value is FileFieldValue {
'alt' in value &&
'title' in value &&
'custom_data' in value &&
'focal_point' in value
'focal_point' in value &&
'poster_time' in value
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cma-client/src/generated/ApiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7892,7 +7892,7 @@ export type ItemValidateExistingSchema<
> = {
id?: ItemIdentity;
type?: ItemType1;
item_type: ItemTypeData<D>;
item_type?: ItemTypeData<D>;
creator?:
| AccountData
| AccessTokenData
Expand Down
4 changes: 2 additions & 2 deletions packages/cma-client/src/generated/RawApiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7599,11 +7599,11 @@ export type ItemValidateExistingSchema<
* The JSON data associated to the record
*/
attributes: ToItemAttributesInRequest<D>;
relationships: {
relationships?: {
/**
* The record's model
*/
item_type: {
item_type?: {
data: ItemTypeData<D>;
};
/**
Expand Down
8 changes: 8 additions & 0 deletions packages/cma-client/src/utilities/inspectItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ function fileInspectionTreeNodes(
nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
}

if (typeof value.poster_time === 'number') {
nodes.push({ label: `poster_time: ${value.poster_time}s` });
}

return nodes;
}

Expand Down Expand Up @@ -432,6 +436,10 @@ function galleryInspectionTreeNodes(
nodes.push({ label: `focal_point: x=${x}% y=${y}%` });
}

if (typeof item.poster_time === 'number') {
nodes.push({ label: `poster_time: ${item.poster_time}s` });
}

return {
label: `[${index}]`,
nodes: nodes,
Expand Down
Loading