Skip to content

Commit

Permalink
chore(history): simplify the meta object (#19990)
Browse files Browse the repository at this point in the history
  • Loading branch information
markkaylor committed Apr 2, 2024
1 parent 4ccbba2 commit 9711681
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
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;
}

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

0 comments on commit 9711681

Please sign in to comment.