Skip to content

[CM] Client-side content client: setup update delete search methods#151041

Merged
Dosant merged 4 commits intoelastic:mainfrom
Dosant:d/2023-02-13-content-client-cache-more-methods
Feb 15, 2023
Merged

[CM] Client-side content client: setup update delete search methods#151041
Dosant merged 4 commits intoelastic:mainfrom
Dosant:d/2023-02-13-content-client-cache-more-methods

Conversation

@Dosant
Copy link
Copy Markdown
Contributor

@Dosant Dosant commented Feb 13, 2023

Summary

Nothing to write home about - just a bit more boilerplate setup code. Method signatures and RPC related interfaces are expected to be changed later with an initial RPC layer implementation.

  • Follow-up to [CM] Setup client side content client #150171, adding a dummy setup for update delete and search methods. The IN and OUT args will be changes when we glue these to the rpc service and its types
  • Also clean up unit tests a bit to have setup logic contained in a helper instead of scattered in global scope

}

// -- Update content
const updateSchemas: ProcedureSchemas = {
Copy link
Copy Markdown
Contributor Author

@Dosant Dosant Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the older examples for now. It is clear that these types will change when the real RPC implementation will be implemented.

crudClient = createCrudClientMock();
contentClient = new ContentClient(() => crudClient);
});
const setup = () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making tests cleaner following @vadimkibana's suggestion from another pr

@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes Feature:Content Management User generated content (saved objects) management Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// labels Feb 14, 2023
@Dosant Dosant marked this pull request as ready for review February 14, 2023 13:40
@Dosant Dosant requested a review from a team as a code owner February 14, 2023 13:40
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@Dosant
Copy link
Copy Markdown
Contributor Author

Dosant commented Feb 15, 2023

@elasticmachine merge upstream

@Dosant
Copy link
Copy Markdown
Contributor Author

Dosant commented Feb 15, 2023

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍 Left a few comments about naming and exposing hook types with generics. Let me know if that could solve the TS generic problem in your demo app.

item: (type: string, id: string) => {
return [...queryKeyBuilder.all(type), id] as const;
},
search: (type: string, params: unknown) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call it query instead of params to align with the rpc query naming?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we now rename type with id as we use id to uniquely identify a ContentType ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call it query instead of params to align with the rpc query naming?

Sure don't mind, I so you already did that in your pr.

Also, can we now rename type with id as we use id to uniquely identify a ContentType ?

Hm, ContentTypeRegistry id means id of the type. But here the main subject is Content (Content item itself), so id refer to the content. e.g. see item which is a key for get:

item: (type: string, id: string) => {
return [...queryKeyBuilder.all(type), id] as const;
},

maybe it should be?

item: (contentTypeId: string, itemId: string) => {
return [...queryKeyBuilder.all(contentTypeId), itemId] as const;
},

search: (contentTypeId: string, query: unknown) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, server side I am using contentTypeId, it seems more consistent to refer to ContentType.id.

return [...queryKeyBuilder.all(type), id] as const;
},
search: (type: string, params: unknown) => {
return [...queryKeyBuilder.all(type), 'search', params] as const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we JSON.stringify the params? Or is that done under the hood?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done under the hood

},
search: <I extends SearchIn = SearchIn, O extends SearchOut = SearchOut>(input: I) => {
return {
queryKey: queryKeyBuilder.search(input.contentType, input.params),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be input.contentTypeId

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current types it seems it is input.contentType

export interface SearchIn<
  T extends string = string,
  Params extends object = Record<string, unknown>,
  Options extends object = any
> {
  contentType: T;
  params: Params;
  options?: Options;
}

I understand that the current type will change so I'd not worry about the current state of them

});
};

export const useUpdateContentMutation = <I extends UpdateIn = UpdateIn, O = unknown>() => {
Copy link
Copy Markdown
Contributor

@sebelga sebelga Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to expose types that unique content can use to declare their mutation (and avoid the problem of declaring the generic everywhere).

Looking at the useCreateContentMutation we would expose

export type CreateContentMutationHook<
  I extends CreateIn = CreateIn,
  O = unknown
> = UseMutationResult<O, unknown, I, unknown>;

Each content can then expose their mutation types

type CreateFooMutation = CreateContentMutationHook<
  {
    contentTypeId: 'foo';
    data: { title: string }; // Shape of the input
  },
  { result: 'success' | 'error' } // Shape of the response
>;

And when consumed it can be used like this

const createFoo: CreateFooMutation = useCreateContentMutation();

It is properly typed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that works we can apply the same for queries

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll try and see if there are any issues

@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
contentManagement 25 42 +17
Unknown metric groups

API count

id before after diff
contentManagement 25 42 +17

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@Dosant Dosant merged commit 4076ece into elastic:main Feb 15, 2023
@kibanamachine kibanamachine added v8.8.0 backport:skip This PR does not require backporting labels Feb 15, 2023
justinkambic pushed a commit to justinkambic/kibana that referenced this pull request Feb 23, 2023
…hods (elastic#151041)

Nothing to write home about - just a bit more boilerplate setup code.
Method signatures and RPC related interfaces are expected to be changed
later with an initial RPC layer implementation.

- Follow-up to elastic#150171, adding a
dummy setup for `update` `delete` and `search` methods. **The `IN` and
`OUT` args will be changes when we glue these to the rpc service and its
types**
- Also clean up unit tests a bit to have setup logic contained in a
helper instead of scattered in global scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Content Management User generated content (saved objects) management release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v8.8.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants