Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(history): simplify the meta object #19990

Merged
merged 3 commits into from
Apr 2, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ describe('VersionHeader', () => {
data: {
title: 'Test Title',
},
meta: {
unknownAttributes: {
added: {},
removed: {},
},
},
};

it('should display the correct title and subtitle for a non-localized entry', () => {
Expand Down Expand Up @@ -130,6 +136,12 @@ describe('VersionHeader', () => {
data: {
title: 'Test Title',
},
meta: {
unknownAttributes: {
added: {},
removed: {},
},
},
};

it('should display the correct title and subtitle for a non-localized entry', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UID } from '@strapi/types';
import type { Struct, UID } from '@strapi/types';
import { scheduleJob } from 'node-schedule';
import { HISTORY_VERSION_UID } from '../../constants';
import { createHistoryService } from '../history';
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('history-version service', () => {
title: {
type: 'string',
},
},
} as Struct.SchemaAttributes,
status: 'draft' as const,
};

Expand Down Expand Up @@ -216,7 +216,7 @@ describe('history-version service', () => {
title: {
type: 'string',
},
},
} as Struct.SchemaAttributes,
status: null,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,14 @@ const createHistoryService = ({ strapi }: { strapi: Core.LoadedStrapi }) => {
]);

const versionsWithMeta = results.map((version) => {
const { added, removed } = getSchemaAttributesDiff(
version.schema,
strapi.getModel(params.contentType).attributes
);
const hasSchemaDiff = Object.keys(added).length > 0 || Object.keys(removed).length > 0;

return {
...version,
...(hasSchemaDiff ? { meta: { unknownAttributes: { added, removed } } } : {}),
meta: {
unknownAttributes: getSchemaAttributesDiff(
version.schema,
strapi.getModel(params.contentType).attributes
),
},
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Data, UID } from '@strapi/types';
import type { Data, Struct, UID } from '@strapi/types';
import { type errors } from '@strapi/utils';

/**
Expand All @@ -12,7 +12,7 @@ export interface CreateHistoryVersion {
locale: string | null;
status: 'draft' | 'published' | 'modified' | null;
data: Record<string, unknown>;
schema: Record<string, unknown>;
schema: Struct.SchemaAttributes;
}
markkaylor marked this conversation as resolved.
Show resolved Hide resolved

interface Locale {
Expand All @@ -31,10 +31,10 @@ export interface HistoryVersionDataResponse extends Omit<CreateHistoryVersion, '
email: string;
};
locale: Locale | null;
meta?: {
unknownAttributes?: {
added: Record<string, unknown>;
removed: Record<string, unknown>;
meta: {
unknownAttributes: {
added: Struct.SchemaAttributes;
removed: Struct.SchemaAttributes;
};
};
}
Expand Down