[CM] Client-side content client: setup update delete search methods#151041
Conversation
| } | ||
|
|
||
| // -- Update content | ||
| const updateSchemas: ProcedureSchemas = { |
There was a problem hiding this comment.
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 = () => { |
There was a problem hiding this comment.
Making tests cleaner following @vadimkibana's suggestion from another pr
|
Pinging @elastic/appex-sharedux (Team:SharedUX) |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
sebelga
left a comment
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
Can we call it query instead of params to align with the rpc query naming?
There was a problem hiding this comment.
Also, can we now rename type with id as we use id to uniquely identify a ContentType ?
There was a problem hiding this comment.
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) => {
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Shouldn't we JSON.stringify the params? Or is that done under the hood?
| }, | ||
| search: <I extends SearchIn = SearchIn, O extends SearchOut = SearchOut>(input: I) => { | ||
| return { | ||
| queryKey: queryKeyBuilder.search(input.contentType, input.params), |
There was a problem hiding this comment.
I think this should be input.contentTypeId
There was a problem hiding this comment.
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>() => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
If that works we can apply the same for queries
There was a problem hiding this comment.
Sounds good. I'll try and see if there are any issues
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Public APIs missing comments
History
To update your PR or re-run it, just comment with: |
…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
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.
updatedeleteandsearchmethods. TheINandOUTargs will be changes when we glue these to the rpc service and its types