mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added collection handling for post's tag attach events
refs https://github.com/TryGhost/Arch/issues/41 - When a tag is attached or detached to the post automatic collections matching the tag filter should be updated.
This commit is contained in:
parent
f4301b16e8
commit
eec610dc53
3 changed files with 37 additions and 1 deletions
|
@ -3,14 +3,18 @@ type PostEditData = {
|
||||||
current: {
|
current: {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
status: string;
|
||||||
featured: boolean;
|
featured: boolean;
|
||||||
published_at: Date;
|
published_at: Date;
|
||||||
|
tags: string[];
|
||||||
},
|
},
|
||||||
previous: {
|
previous: {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
status: string;
|
||||||
featured: boolean;
|
featured: boolean;
|
||||||
published_at: Date;
|
published_at: Date;
|
||||||
|
tags: string[];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,11 +85,18 @@ export class ModelToDomainEventInterceptor {
|
||||||
title: data.attributes.title,
|
title: data.attributes.title,
|
||||||
status: data.attributes.status,
|
status: data.attributes.status,
|
||||||
featured: data.attributes.featured,
|
featured: data.attributes.featured,
|
||||||
published_at: data.attributes.published_at
|
published_at: data.attributes.published_at,
|
||||||
|
tags: data.relations?.tags?.models.map((tag: any) => (tag.get('slug')))
|
||||||
},
|
},
|
||||||
// @NOTE: this will need to represent the previous state of the post
|
// @NOTE: this will need to represent the previous state of the post
|
||||||
// will be needed to optimize the query for the collection
|
// will be needed to optimize the query for the collection
|
||||||
previous: {
|
previous: {
|
||||||
|
id: data.id,
|
||||||
|
title: data._previousAttributes?.title,
|
||||||
|
status: data._previousAttributes?.status,
|
||||||
|
featured: data._previousAttributes?.featured,
|
||||||
|
published_at: data._previousAttributes?.published_at,
|
||||||
|
tags: data._previousRelations?.tags?.models.map((tag: any) => (tag.get('slug')))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -82,7 +82,10 @@ describe('ModelToDomainEventInterceptor', function () {
|
||||||
assert.ok(event.data);
|
assert.ok(event.data);
|
||||||
assert.ok(event.data.current);
|
assert.ok(event.data.current);
|
||||||
assert.equal(event.data.current.status, 'draft');
|
assert.equal(event.data.current.status, 'draft');
|
||||||
|
assert.equal(event.data.previous.status, 'published');
|
||||||
|
|
||||||
|
assert.equal(event.data.current.tags[0], 'tag-current-slug');
|
||||||
|
assert.equal(event.data.previous.tags[0], 'tag-previous-slug');
|
||||||
interceptedEvent = event;
|
interceptedEvent = event;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -92,6 +95,28 @@ describe('ModelToDomainEventInterceptor', function () {
|
||||||
status: 'draft',
|
status: 'draft',
|
||||||
featured: false,
|
featured: false,
|
||||||
published_at: new Date()
|
published_at: new Date()
|
||||||
|
},
|
||||||
|
_previousAttributes: {
|
||||||
|
status: 'published',
|
||||||
|
featured: true
|
||||||
|
},
|
||||||
|
relations: {
|
||||||
|
tags: {
|
||||||
|
models: [{
|
||||||
|
get: function (key: string) {
|
||||||
|
return `tag-current-${key}`;
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_previousRelations: {
|
||||||
|
tags: {
|
||||||
|
models: [{
|
||||||
|
get: function (key: string) {
|
||||||
|
return `tag-previous-${key}`;
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue