-
Notifications
You must be signed in to change notification settings - Fork 45
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
ui - enhance flow typing #3002
ui - enhance flow typing #3002
Conversation
Hello jbwatenbergscality,My role is to assist you with the merge of this Status report is not available. |
Branches have divergedThis pull request's source branch To avoid any integration risks, please re-synchronize them using one of the
Note: If you choose to rebase, you may have to ask me to rebuild |
67edd45
to
208308d
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list: |
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.
Super cool stuff, thanks for starting this heavy lifting, I'm confident this will increase productivity a lot!
Some comments and suggestions here and there 😉 , just adding a more general one here: are you running Prettier
? We have a committed .prettierrc
for you to use, the goal being to keep the code consistent without spending time on aesthetics in PR reviews 😜
ui/src/services/k8s/api.js
Outdated
kind: 'Volume', | ||
metadata?: V1ObjectMeta, | ||
spec: { | ||
mode: 'Filesystem', |
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.
ui/src/services/k8s/api.js
Outdated
storageClassName: string | ||
}, | ||
status: { | ||
deviceName: 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.
If this was not yet reconciled (e.g. because the Volume is Pending
), this will be empty from the Operator's PoV, and absent in the API object.
ui/src/services/k8s/api.js
Outdated
}, | ||
storageClassName: string | ||
}, | ||
status: { |
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.
If you want to be exhaustive, there is also a status.job
key (which is also optional, and its usage is internal to the Operator).
ui/src/ducks/app/volumes.js
Outdated
return { type: UPDATE_VOLUMES, payload }; | ||
}; | ||
|
||
export const fetchCurrentVolumeObjectAction = (volumeName) => { | ||
export const fetchCurrentVolumeObjectAction = (volumeName: 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.
I guess we can safely assume this should be a string
, no?
ui/src/ducks/app/volumes.js
Outdated
export function* fetchVolumes(): Generator<{ | ||
body: {items: Metalk8sV1Alpha1Volume[]}; | ||
} | {error: any, body: null}, { | ||
body: {items: Metalk8sV1Alpha1Volume[]}; | ||
} | {error: any, body: null}, { | ||
body: {items: Metalk8sV1Alpha1Volume[]}; | ||
} | {error: any, body: null}> { |
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'm not sure that's a valid type for sagas. IIUC, the type signature for a coroutine is Generator<Yield, Return, Next>
. Sagas only yield "effects" (in the sense of redux-saga
), and they may be fed with any
thing.
For this reason, there is a handy type definition in flow-typed
for the redux-saga
library:
import type { Saga } from 'redux-saga';
// same as:
declare type Saga<T> = Generator<Effect, T, any>
See the definitions here
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.
Thanks I was looking for those typings desperately 👍 👍
ui/src/ducks/config.js
Outdated
export type ConfigState = { | ||
language: string, | ||
theme: Theme, | ||
api: Config | null, |
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.
?Config
would work here as well, IIUC
return { type: SET_THEMES, payload: themes }; | ||
} | ||
|
||
// Selectors | ||
export const languageSelector = (state) => state.config.language; | ||
export const apiConfigSelector = (state) => state.config.api; | ||
export const languageSelector = (state: RootState) => state.config.language; |
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.
Just a question: since RootState
is properly typed, is flow able to infer the return type of these selectors?
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, flow is inferring the type of languageSelector
from state.config.language
ui/src/ducks/login.js
Outdated
const result = yield call(ApiSalt.authenticate, user); | ||
if (!result.error) { | ||
export function* authenticateSaltApi(): Generator<any, void, any> { | ||
const api: Config | null = yield select(apiConfigSelector); |
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.
(ugh, even if flow was able to infer the return type of a selector, it can't guess the value injected by the coroutine's "owner"... some big limitation of sagas here)
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 the simplest way I found to type complex saga with different return type over iterations is to type Next
as any and force the type of each of the variables 😞 . Even through this is not directly linked to redux but more to typing, IMO redux and redux saga are adding a lot of complexity for such simple tasks as data fetching, I prefer using libraries such as react-query
or swr
that greatly ease data fetching and caching use cases and that are way more easier to type as in most cases the typing would be inferred from API clients typing.
ui/src/ducks/login.js
Outdated
export function* authenticateSaltApi(): Generator<any, void, any> { | ||
const api: Config | null = yield select(apiConfigSelector); | ||
const user: User = yield select((state: RootState) => state.oidc?.user); | ||
const result: { error: any } | ApiSalt.SaltToken = yield call(ApiSalt.authenticate, user); |
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.
Could be handy to have type aliases for such "result" values:
declare type Result<T> = { error: any } | T
// Or for API results under a `body` key
declare type APIResult<T> = Result<{ body: T }>
Here we'd have:
const result: Result<Api.SaltToken> = yield call(...)
ui/src/ducks/reducer.js
Outdated
export const useTypedSelector: <TSelected>( | ||
selector: (state: RootState) => TSelected, | ||
equalityFn?: (left: TSelected, right: TSelected) => boolean | ||
) => TSelected = useSelector; |
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.
Two comments:
- I think we have defined custom hooks in
src/services/utils.js
(though granted, it doesn't make much sense either) - IMHO, adding a plainsrc/hooks.js
could make it easier to find in the future - the purpose of this custom hook is not obvious at first glance, so I'd suggest we add a comment to explain it (and remind the reader that they should use it instead of the standard
useSelector
hook)
ConflictThere is a conflict between your branch Please resolve the conflict on the feature branch ( $ git fetch
$ git checkout origin/improvement/flow-typing
$ git merge origin/development/2.7
$ # <intense conflict resolution>
$ git commit
$ git push origin HEAD:improvement/flow-typing |
735be21
to
6d11214
Compare
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list:
The following reviewers are expecting changes from the author, or must review again: |
@@ -0,0 +1,23 @@ | |||
## Metalk8s client generator | |||
|
|||
It generates a flow client based on `@kubernetes/client` custom objects client from kubernetes `CustomResourceDefinition` of metalk8s volumes. |
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.
Awesome 👍
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.
LGTM!
Can't wait to get it to merge and benefit from the typing.
ConflictThere is a conflict between your branch Please resolve the conflict on the feature branch ( $ git fetch
$ git checkout origin/improvement/flow-typing
$ git merge origin/development/2.7
$ # <intense conflict resolution>
$ git commit
$ git push origin HEAD:improvement/flow-typing |
e7b7008
to
932ee75
Compare
Integration data createdI have created the integration data for the additional destination branches.
The following branches will NOT be impacted:
You can set option
|
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list:
The following reviewers are expecting changes from the author, or must review again: |
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.
Could we squash the commits into logical units, now that reviewers approved? I'm not too fond of fix stuff
commits, especially for fixing things introduced in the same PR.
6f43719
to
defb178
Compare
History mismatchMerge commit #6e03a09581f9c41616f1bf5816c34e72ea53663c on the integration branch It is likely due to a rebase of the branch Please use the |
export async function get${singleName}(${singleName}Name: string): Promise<Result<${singleName}>> { | ||
if (!customObjects) { | ||
return { error: 'customObject has not yet been initialized' }; | ||
} | ||
try { | ||
return await customObjects.getClusterCustomObject( | ||
'${crdSpec.spec.group}', | ||
'${crdSpec.spec.version}', | ||
'${crdSpec.spec.names.plural}', | ||
${singleName}Name, | ||
); | ||
} catch (error) { | ||
return { error }; | ||
} | ||
} |
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.
Maybe this part should be squashed with ui: add a flow typed client generator
(it's more than just ui: use generated metalk8s client and types
)
defb178
to
71db196
Compare
Checked the CI, it looks like unit tests are failing (apparently src/ducks/app/volumes.test.js
was not updated to use the generated client, and something changed in the pods state, which makes src/ducks/app/pods.test.js
fail).
71db196
to
ffbed03
Compare
/approve |
History mismatchMerge commit #6e03a09581f9c41616f1bf5816c34e72ea53663c on the integration branch It is likely due to a rebase of the branch Please use the The following options are set: approve |
/reset |
Reset completeI have successfully deleted this pull request's integration branches. The following options are set: approve |
Integration data createdI have created the integration data for the additional destination branches.
The following branches will NOT be impacted:
You can set option
The following options are set: approve |
The goal of this commit is to introduce a generator of a client based upon `@kubernetes/client` custom objects client from kubernetes `CustomResourceDefinition`. The idea behind this is to have always up to date types definition for our custom resource definition and be in sync with the json schema contained within those definitions. Refs: #2999
7083006
to
dbc6f8b
Compare
History mismatchMerge commit #9a1bb97024ac924946876225330345dcd94bf116 on the integration branch It is likely due to a rebase of the branch Please use the The following options are set: approve |
/reset |
Reset completeI have successfully deleted this pull request's integration branches. The following options are set: approve |
Integration data createdI have created the integration data for the additional destination branches.
The following branches will NOT be impacted:
You can set option
The following options are set: approve |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
Peer approvals must include at least 1 approval from the following list:
The following options are set: approve |
In the queueThe changeset has received all authorizations and has been added to the The changeset will be merged in:
The following branches will NOT be impacted:
There is no action required on your side. You will be notified here once IMPORTANT Please do not attempt to modify this pull request.
If you need this pull request to be removed from the queue, please contact a The following options are set: approve |
I have successfully merged the changeset of this pull request
The following branches have NOT changed:
Please check the status of the associated issue None. Goodbye jbwatenbergscality. |
Component:
ui, typing
Context:
This pull request is a first milestone to introduce better typings in the project.
This brings type-safety and enhanced developer experience to the project.
As introducing strong typing everywhere in the project would require a few more pull requests the idea of this one is to focus on kubernetes client and reducers that make use of kubernetes client. However it also brings typings for few others reducers and introduce starting points to expand typing to other areas in the project.
Closes: #2999
See: #3000 #3001