-
Notifications
You must be signed in to change notification settings - Fork 657
CONSOLE-4677: Enable strictNullChecks: true for frontend/insights-plugin and frontend/helm-plugin #15396
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
base: main
Are you sure you want to change the base?
Conversation
@krishagarwal278: This pull request references CONSOLE-4677 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the sub-task to target the "4.20.0" version, but no target version was set. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/label docs-approved |
/label tide/merge-method-squash |
079c3de
to
8a2479e
Compare
Checked on cluster launched against the pr. The regression test passed. |
@krishagarwal278: This pull request references CONSOLE-4677 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the sub-task to target the "4.20.0" version, but no target version was set. In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
/retest |
@@ -31,7 +31,7 @@ const HelmReleaseStatusDecorator: React.FC<HelmReleaseStatusDecoratorProps> = ({ | |||
|
|||
return ( | |||
<Tooltip triggerRef={ref} content={label} position={TooltipPosition.left}> | |||
<g ref={ref}> | |||
<g ref={(ref as unknown) as React.RefObject<SVGGElement>}> |
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.
can we instead change the type of ref
instead of coercing it like this?
const ref = useRef<SVGGElement>();
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.
addressed in latest commit
@@ -25,7 +26,7 @@ const HelmReleasePanelDetailsTabSection: React.FC<{ element: GraphElement }> = ( | |||
<p>Status Box</p> | |||
</> | |||
) : ( | |||
<HelmReleaseOverview obj={secret} customData={undefined} /> | |||
<HelmReleaseOverview obj={secret} customData={(undefined as unknown) as HelmRelease} /> |
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.
instead of forcing undefined
to be a HelmRelease
we should instead make HelmReleaseOverview
accept undefined
in this prop
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.
addressed in latest commit
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.
looking a lot better!
/> | ||
</TableData> | ||
<TableData className={tableColumnClasses.type}>{resource.kind}</TableData> | ||
<TableData className={tableColumnClasses.status}> | ||
<HelmReleaseResourceStatus resource={resource} /> | ||
</TableData> | ||
<TableData className={tableColumnClasses.created}> | ||
<Timestamp timestamp={resource.metadata.creationTimestamp} /> | ||
<Timestamp timestamp={resource.metadata?.creationTimestamp || ''} /> |
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 we can copy the timestamp changes from your other PR so we don't need the empty string fallback 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.
Oh yes definitely. Making that change
@@ -232,7 +237,7 @@ const HelmInstallUpgradePage: React.FunctionComponent = () => { | |||
onNamespaceChange={handleNamespaceChange} | |||
hideApplications | |||
> | |||
<DocumentTitle>{config.title}</DocumentTitle> | |||
<DocumentTitle>{config?.title || ''}</DocumentTitle> |
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 think we wouldn't want to set the title as empty string
<DocumentTitle>{config?.title || ''}</DocumentTitle> | |
{config?.title && <DocumentTitle>{config.title}</DocumentTitle> } |
helmActionConfig={config as HelmActionConfigType} | ||
onVersionChange={setChartData} | ||
chartError={chartError} | ||
namespace={namespace} | ||
chartIndexEntry={indexEntry} | ||
chartError={chartError as 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.
are these type assertions still needed?
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.
RIght, it can be removed
@@ -110,7 +125,7 @@ const RepositoriesPage: React.FC<RepositoriesPageProps> = ({ | |||
<DocumentTitle>{t('helm-plugin~Helm Repositories')}</DocumentTitle> | |||
<MultiListPage | |||
namespace={namespace} | |||
flatten={flatten} | |||
flatten={flatten as Flatten} |
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.
is this type assertion still needed?
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, giving type errors when i remove it
const [{ dragging: labelDragging }, dragLabelRef] = useDragNode(noRegroupDragSourceSpec); | ||
const nodeRefs = useCombineRefs(innerHoverRef, dragNodeRef); | ||
const nodeRefs = useCombineRefs(innerHoverRef, dragNodeRef as React.Ref<Element>); |
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.
does this work to remove the type assertion in line 90?
const nodeRefs = useCombineRefs(innerHoverRef, dragNodeRef as React.Ref<Element>); | |
const nodeRefs = useCombineRefs<SVGGElement>(innerHoverRef, dragNodeRef); |
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 removing it in line 90 isn't give me errors
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 to @krishagarwal278 explanation on this PR. Based on my understanding, the PR is trying to solve all the errors generated after upgrading from i18next: ^21.10.0 to 23.0.0
and react-i18next: ^11.12.0 to ^13.2.2
which introduced this stricter typing policy and enabling the strictNullChecks compiler option.
After I enable the compiler option strictNullChecks: true
, and complete the upgrade with the main branch code, there are errors shows up; but on this PR branch, no errors are observed after running yarn install
.
Since I am not an React expert, I couldn't provide any insightful suggestions regarding how to improve code quality or whether it is adopting the best practices. But from my reading through the PR, all the changes make sense to me, and
- There are no breaking functional changes that could break the whole application
- You are adding more type safety
Therefore, I will go ahead and give lgtm for this PR after seeing the most of the CI tests are passing and the review comments are addressed.
@@ -10,7 +10,7 @@ import HelmChartSummary from './HelmChartSummary'; | |||
|
|||
export interface HelmReleaseOverviewProps { | |||
obj: K8sResourceKind; | |||
customData: HelmRelease; | |||
customData?: HelmRelease; | |||
} | |||
|
|||
const HelmReleaseOverview: React.FC<HelmReleaseOverviewProps> = ({ obj, customData }) => { |
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.
Do we need to update the FC to FCC, as I prob see @logonoff has suggested in some other PRs before.
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.
addressed nit
77aded2
to
9a4a109
Compare
9a4a109
to
1e4a82a
Compare
LGTM! Since I am not the React expert, I will leave this PR for others to take a second look. |
chartName, | ||
chartRepoName: helmChartRepoName || '', | ||
appVersion, | ||
chartVersion, | ||
chartReadme, | ||
yamlData: initialYamlData, | ||
formData: initialFormData, | ||
formSchema: initialFormSchema, | ||
formData: initialFormData as Record<string, unknown>, |
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.
the type of formData
is typically any in HelmInstallUpgradeFormData
, should we be updating that to Record<string, unknown>
?
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 we can revert back to any
in HelmInstallUpgradeFormData
without getting any errors
let res: { | ||
prop: string; | ||
kind: string; | ||
namespaced: boolean; | ||
isList: boolean; | ||
namespace?: 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.
maybe we can deduplicate the type
let res: { | |
prop: string; | |
kind: string; | |
namespaced: boolean; | |
isList: boolean; | |
namespace?: string; | |
}[] = []; | |
let res: MultiListPageProps['resources'][] = []; |
|
||
const flatten = (resourceLists) => { | ||
const flatten = (resourceLists: Record<string, { data?: unknown[] }>) => { |
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 we do this, do we need the assertion in line 128? at least this way TS will check if flatten
is a Flatten
const flatten = (resourceLists: Record<string, { data?: unknown[] }>) => { | |
const flatten: Flatten = (resourceLists: Record<string, { data?: unknown[] }>) => { |
@@ -18,7 +18,7 @@ export const useHelmChartRepositoriesBreadcrumbs = (kindObj: K8sKind) => { | |||
return useTabbedTableBreadcrumbsFor( | |||
kindObj, | |||
location, | |||
params, | |||
params as { 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.
maybe we can update the expected params type in useTabbedTableBreadcrumbsFor
instead because this is the only place where that function is used I think
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.
made params
required in useTabbedTableBreadcrumbsFor
typedDataModel.nodes?.push( | ||
getTopologyNodeItem(resource, TYPE_HELM_WORKLOAD, data, WorkloadModelProps), | ||
); | ||
const groups = getTopologyHelmReleaseGroupItem(resource, helmResourcesMap, secrets); | ||
mergeGroups(groups, typedDataModel.nodes); | ||
mergeGroups(groups, typedDataModel.nodes as NodeModel[]); |
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.
node is always defined, do you think it would be nicer to do this in line 121, then remove the ?.push
and the as NodeModel[]
?
const typedDataModel: Required<Omit<Model, 'graph'>> = {
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 it's cleaner that way. Removed ?.
and as NodeModel[]
@@ -253,8 +259,8 @@ export const getHelmActionConfig = ( | |||
), | |||
}, | |||
helmReleaseApi: `/api/helm/chart?url=${encodeURIComponent( | |||
chartURL, | |||
)}&namespace=${namespace}&indexEntry=${encodeURIComponent(chartIndexEntry)}`, | |||
chartURL as 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.
should chartURL
be a required parameter?
chartURL, | ||
)}&namespace=${namespace}&indexEntry=${encodeURIComponent(chartIndexEntry)}`, | ||
chartURL as string, | ||
)}&namespace=${namespace}&indexEntry=${encodeURIComponent(chartIndexEntry as 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.
should chartIndexEntry
be required?
@@ -272,7 +278,7 @@ export const getHelmActionConfig = ( | |||
}, | |||
helmReleaseApi: `/api/helm/release?ns=${namespace}&name=${releaseName}`, | |||
fetch: coFetchJSON.put, | |||
redirectURL: getOriginRedirectURL(actionOrigin, namespace, releaseName), | |||
redirectURL: getOriginRedirectURL(actionOrigin as string, namespace, releaseName), |
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.
should these be required too?
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.
replaced with either fallback value(includes undefined too in cases where it's required) or made it required instead of using as
/label acknowledge-critical-fixes-only |
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: krishagarwal278, logonoff The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
@@ -697,7 +697,7 @@ export type ResourceEventStreamProps = { | |||
}; | |||
|
|||
export type TimestampProps = { | |||
timestamp: string | number | Date; | |||
timestamp: string | number | Date | 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 think this is reasonable since the component clearly handles this case. We should update the documentation for the component to discuss what happens if null
is passed.
}; | ||
|
||
const LabelComponent = ({ clusterID, ...props }) => ( | ||
<ExternalLink | ||
href={`https://console.redhat.com/openshift/insights/advisor/clusters/${clusterID}?total_risk=${ | ||
riskSorting[props.datum.id] + 1 | ||
riskSorting[props.datum?.id as string] + 1 |
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 see quite a few uses of as
in the PR. It usually indicates that there is a problem with our type declarations. It would be better to fix that in most cases.
New changes are detected. LGTM label has been removed. |
@krishagarwal278: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
No description provided.