Commit Graph

22 Commits

Author SHA1 Message Date
Jono M
5e057dee11
Added tests to AdminX framework package (#19022)
refs https://github.com/TryGhost/Product/issues/4159

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖[[deprecated]](https://githubnext.com/copilot-for-prs-sunset)
Generated by Copilot at 9e68f4d</samp>

This pull request refactors several components in the `admin-x-settings`
app to use common hooks from the `@tryghost/admin-x-framework` package,
which reduces code duplication and improves consistency. It also updates
the `package.json` file and adds unit tests for the `admin-x-framework`
package, which improves the formatting, testing, and dependency
management. Additionally, it makes some minor changes to the `hooks.ts`,
`FrameworkProvider.tsx`, and `.eslintrc.cjs` files in the
`admin-x-framework` package, which enhance the public API and the
linting configuration.
2023-11-20 11:00:51 +00:00
Fabien "egg" O'Carroll
45c1a82909 Forced "latest" Collection Entity to have no posts
refs https://github.com/TryGhost/Arch/issues/95

We're going to be treating the "latest" Collection as a "virtual" Collection
where we will hydrate the posts from the posts repository. This will allow for
more performant queries, and less work to keep the "latest" Collection in sync
2023-09-22 19:05:37 +07:00
Fabien "egg" O'Carroll
62d5ca558d Validated filters for collections
refs https://github.com/TryGhost/Arch/issues/47

This ensures that we only have collections which have a valid filter in terms of
  - Valid NQL string
  - Uses only properties which are valid to filter on
  - Only has an empty filter in the case of the "latest" collection
2023-08-23 15:49:06 +07:00
Fabien "egg" O'Carroll
ad62cd4822 Removed edit method from Collection
We want to keep Entities as basic as possible, particularly when setting
property, so that each property can handle its own validation.
2023-08-17 09:45:41 +01:00
Fabien "egg" O'Carroll
9288f56649 Improved type definitions
The PostRepository type was using `any` (an anti pattern) rather than
`PostCollection`, and we had optional properties, which are not really
optional. This cleans up the types and updates the tests alongside them.
2023-07-27 16:33:16 +02:00
Naz
694ab1d32d Added support for expansions in collection filters
refs https://github.com/TryGhost/Arch/issues/46

- Similarly to post filters, collection filters now support both 'tag' and 'tags' nql filter keys when defining a filter for related tag slugs. For example, both `tag:avocado` and `tags:avocado` would both be valid collection filters that would filter by the same 'slug' property of the tags assigned to a post.
- Along with these changes had to rework the tags property of the collection posts to match the shape used in post resources. Moved from:
`tags: ['bacon', 'broc']`
to
`tags:[{slug: 'bacon'}, {slug: 'broc'}]`
2023-07-25 19:01:56 +08:00
Naz
ed91412cd5 Changed "index" collection name to "latest"
https://github.com/TryGhost/Arch/issues/25

- This naming matches how the collection will be visible in the cards and how it's marketed. Naming it "index" even for internal purposes will get confusing.
2023-07-17 18:43:21 +08:00
Naz
cb8e009c14 Allowed for index collection to have empty filter
refs https://github.com/TryGhost/Arch/issues/25

- The built in index (soon -> "latest") collection does not require any filtering so that it could contain an index of all posts in the system. All other automatic collections should have a filter defined.
2023-07-10 12:43:52 +08:00
Fabien "egg" O'Carroll
16db3bbf17 Removed deletable property in favour of protected slugs
We couldn't decide on the best way to encode this in the database.
e.g. deletable: true? or type: internal? but type conflicts with the
storage of manual/automatic.

For now we can use this, and add something in future if we're finding problems
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
0a3e36cd62 Ensured uniqueness of slug in collections
We require that slugs are unique as slugs can/are used for routing purposes and
act as an identifier for a resource. As this is a core business rule, we want
to encode it in the entity so that it can be unit tested, and be enforced
regardless of underlying persistence layer
2023-06-29 01:40:05 +01:00
Fabien "egg" O'Carroll
d29f512823 Required titles for collections
We don't want to allow collections to be created without a title, and we need
to encoe that business rule in the entity.
2023-06-29 01:40:05 +01:00
Naz
5dd6159ac6 Added handling for 'post.edited' Ghost model event
refs https://github.com/TryGhost/Team/issues/3169

- Adds optomized collection update handling for when post.edited model event is emitted.
2023-06-27 12:52:10 +07:00
Naz
a8e5cbcc3d Extracted post matching to filter to separate method
refs https://github.com/TryGhost/Team/issues/3169

- This method is also useful for external services when checking if collection needs any updates or not.
2023-06-27 12:52:10 +07:00
Naz
36783e456b Added 'post.added' event handling in Collections
refs https://github.com/TryGhost/Team/issues/3169

- This piece of logic handles the 'post.added' model event mapping to Collection's PostAddedEvent domain event and logic related to updating collections when the new post is added.
2023-06-27 12:52:10 +07:00
Naz
42539b954f Added collection editing method
refs https://github.com/TryGhost/Team/issues/3169

- The collection entity properties used to be modified, which is not a good practice for logic encapsulation. Extracted editing logic to it's own method which can also contain validation logic when wrong data is passed when editing a collection.
2023-06-27 12:52:10 +07:00
Naz
fab5b1845c
Made builtin collections un-deletable
closes https://github.com/TryGhost/Team/issues/3376

- It should not be possible to delete a built-in collection.
2023-06-06 22:04:16 +07:00
Naz
6e224f3702
Added automatic collection validation
refs https://github.com/TryGhost/Team/issues/3170

- When an automatic collection is created it should always have a valid filter assigned
2023-06-05 13:39:52 +07:00
Naz
e8220b1387
Added DEL /collections/:id/posts/:post_id to Admin API
refs https://github.com/TryGhost/Team/issues/3260

- We need a way to remove posts form collections without fetching the whole collection's content. This API method allows to remove posts from manual collections by collection id and post id.
- As a response it returns up to date collection state without the removed post.
2023-06-01 14:59:05 +07:00
Fabien "egg" O'Carroll
27f60b4ab5 Added logic for adding posts to collection
Also removes concept of CollectionPost in an effort to simplify the structure
2023-06-01 14:25:49 +07:00
Naz
66d489b8b3 Added Posts relation support to collections package
refs https://github.com/TryGhost/Team/issues/3260

- Adds "posts" relation to Collection entity to manage posts belonging to the collection
2023-05-31 22:55:35 +07:00
Naz
b52ec948b0
Added property mapper to collections responses
closes https://github.com/TryGhost/Team/issues/3259

- API output mappers (soon to be serializers) are meant to work based on allowlist set of output properties. Having the allowlist early on will allow to track the API evolution consistently.
2023-05-24 17:01:28 +07:00
Naz
fdd73d01b7
Refactored collections entity logic
refs https://github.com/TryGhost/Team/issues/3294

- The factory method for the Collection and validations should live close together based on our latest architectural direction
2023-05-24 17:01:28 +07:00