-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prerequisites for upcoming forms and actions #938
base: master
Are you sure you want to change the base?
Conversation
Open needs to be controllable from outside Header and Dialog z-index was whacky, fix it
@@ -14,6 +14,7 @@ | |||
> = { | |||
schema: Schema; | |||
endpoint: ApiEndpoint<z.infer<Schema>, Result>; | |||
metaData: any; |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
@@ -12,6 +12,7 @@ | |||
Z extends ZodRawShape | |||
> = { | |||
schema: Schema; | |||
metaData: any; |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
@@ -3,11 +3,12 @@ | |||
|
|||
export type ApiEndpoint<Data, Result> = ( | |||
config: RequestConfig, | |||
data: Data | |||
data: Data, | |||
metaData: any |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
) => Promise<Result>; | ||
export function useApiCall<Data, Result>( | ||
endpoint: ApiEndpoint<Data, Result> | ||
): (data: Data) => Promise<Result> { | ||
): (data: Data, metaData: any) => Promise<Result> { |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
const apiConfig = useApiConfig(); | ||
return (data: Data) => endpoint(apiConfig, data); | ||
return (data: Data, metaData: any) => endpoint(apiConfig, data, metaData); |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
> { | ||
schema: Schema; | ||
endpoint: ApiEndpoint<z.infer<Schema>, Result>; | ||
metaData: any; |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What ever happens to this whole file, as per my earlier reviews I would prefer a) better typing b) silencing the warning and adding a comment describing why it was necessary. I like this approach since writing the comment usually (not necessarily in this case) works as rubber ducking, and makes it obvious to others that the choice to use any
was deliberate and necessary.
Needless to say, this comment applies to all these warnings.
Result extends object, | ||
Z extends ZodRawShape | ||
> = { | ||
metaData: any; |
Check warning
Code scanning / ESLint
Disallow the `any` type Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this as a comment since I think we should discuss the two main points of the review before moving forward:
- The ApiAction as a concept
- Setting default values to form components
@@ -0,0 +1,64 @@ | |||
.SelectTrigger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use camelCase, not PascalCase, to be consistent with the Cyberstorm package. Applies to other selectors in this files as well.
EDIT: to think of it, these are all used in Select component, so I need no reason to use the Select
prefix in the names at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, fixed the classnames
@@ -0,0 +1,64 @@ | |||
.SelectTrigger { | |||
display: inline-flex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also generally speaking I feel this file doesn't adhere to all the style things we've set up so far and I'm not sure why you're actively creating code debt by ignoring them. I'm talking about variables for colors, sizes, spaces etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added usage of variables
"use client"; | ||
|
||
import { z, ZodObject } from "zod"; | ||
import { ZodRawShape } from "zod/lib/types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my earlier review, this should be imported from "zod".
// The schema is required to allow TS to infer valid values for the name field | ||
schema: Schema; | ||
name: Path<z.infer<Schema>>; | ||
options: { value: string; label: string }[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see you've chosen to use the value/label approach instead of a single string this time around. Although it does make the SelectSear
stick out like a sore thumb.
schema: Schema; | ||
name: Path<z.infer<Schema>>; | ||
options: { value: string; label: string }[]; | ||
placeholder?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never passed to TempSelect
?
@@ -28,7 +28,7 @@ | |||
"@radix-ui/react-dialog": "^1.0.2", | |||
"@radix-ui/react-dropdown-menu": "^2.0.1", | |||
"@radix-ui/react-radio-group": "^1.1.3", | |||
"@radix-ui/react-select": "^1.2.0", | |||
"@radix-ui/react-select": "^2.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK how Radix uses semver but is it wise to mix components from v2 with components from v1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I could find, it's alright to mix them.
transform: translate(calc(var(--left) * -1), calc(var(--top) * -1)); | ||
|
||
box-shadow: hsl(206deg 22% 7% / 0.35) 0 10px 38px -10px, hsl(206deg 22% 7% / 0.2) 0 10px 20px -15px; | ||
transform: translate(-50%, -50%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit offtopic but is this still the preferred way of centering stuff? I would have thought there's something better by now. @gkurck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can use flex 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, flex is preferred here, no need to take the element out of the document flow.
@@ -1,7 +1,7 @@ | |||
.root { | |||
position: sticky; | |||
top: 0; | |||
z-index: 999; | |||
z-index: auto; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't auto
the default value? Is this actually needed at all?
@@ -0,0 +1,52 @@ | |||
"use client"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole thing confuses me. According to commit message, the idea is to "use API without forms". So why is this located in ts-api-react-forms
package? Why not ts-api-react
, or better yet directly in thunderstore-api
?
Secondly, what seems to me to basically be a "onChange" function is for some reason formatted as a React component? Why?
This uses zod, which might be a good idea, but on the other hand might be overkill. It was used on the forms since RHF supports it and helps reduce boilerplate(?). Now were not using RHF. Would regular TS interfaces do the same job?
Also I'm not a fan of the metaData
, as a variable name nor as a concept. YMMV but if you compare this to Dapper, everything above thunderstore-api
methods treats data as "everything that is needed to make the request, defined by the ts-api method arguments". It's then up to the method to decide what parts of information goes to URL and what goes to query parameters (or request body, although no such use case has been created by me). This way Cyberstorm components don't (need to) know how the data is used, they're just responsible to providing it all.
In summary: I would cut out out ts-api-react-forms
/ts-api-react
and go either directly to thunderstore-api
or possibly through a separate ts-api-actions
package. That being said, I feel a lot of the above might be due to me not comprehending the inner workings of ts-api-react-forms
/ts-api-react
so you might want a second opinion from @MythicManiac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to elaborate on the naming of metaData
: It's one word, so metadata
. Even then I'm not sure if it's really "data about the rest of the data". It's additional data, and in this care very much required to form the complete set of "data".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved ApiAction
and useApiAction
underneath ts-api-react
. And added better typing.
The idea that I got from @MythicManiac was that the ApiForm
would wrap the usage of RHF and other stuff (like the usage of toasts) to be under one usable component.
I could have added the "actions" just where those were needed, but it seemed like a good idea to add a similar centralized point for the actions as forms have one. Having a bit hard time explaining my reasonings though.
Also about zod; It does feel a bit overkill, but TBH, I'd rather have it than not have it.
Let's continue this discussion in #963
> { | ||
schema: Schema; | ||
endpoint: ApiEndpoint<z.infer<Schema>, Result>; | ||
metaData: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What ever happens to this whole file, as per my earlier reviews I would prefer a) better typing b) silencing the warning and adding a comment describing why it was necessary. I like this approach since writing the comment usually (not necessarily in this case) works as rubber ducking, and makes it obvious to others that the choice to use any
was deliberate and necessary.
Needless to say, this comment applies to all these warnings.
Improve CreateTeamForm
Add AddTeamMemberForm
Add TeamDetailsEdit form
…form Add AddServiceAccountForm
…nt-form Add RemoveServiceAccountForm
Add DeleteAccountForm
Add DisbandTeamForm
…-change-role Add team member kick and change role
Add TeamLeaveForm
No description provided.