refactor: decouple resource pairing into hook#11
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
useClusterService returned Knative Services and Deployments as separate arrays, forcing FunctionsListPage to do ksvc-to-deployment matching (revision label lookup with function name fallback). This is a cluster-domain concern that belongs in the hook. Introduce ClusterFunction type pairing both resources by name, move the matching logic into the hook behind useMemo, and simplify the page to a name-based lookup. Rename FunctionTableItem.deployment to mainResource since it holds the ksvc (for the delete modal), not a Deployment. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Matej Vašek <matejvasek@gmail.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matejvasek The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@matejvasek: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
| const { t } = useTranslation('plugin__console-functions-plugin'); | ||
| const launchDelete = useDeleteModal( | ||
| deployment as K8sResourceKind, | ||
| mainResource as K8sResourceKind, |
There was a problem hiding this comment.
Agree, but this is pre-existing issue. I would prefer to fix it in some other PR.
There was a problem hiding this comment.
Also I am not sure about clean fix. Following is not much better IMO.
diff --git a/src/pages/function-list/components/FunctionTable.tsx b/src/pages/function-list/components/FunctionTable.tsx
index c0c4b07..3a92d39 100644
--- a/src/pages/function-list/components/FunctionTable.tsx
+++ b/src/pages/function-list/components/FunctionTable.tsx
@@ -88,7 +88,11 @@ export function FunctionTable({
/>
</ActionListItem>
<ActionListItem>
- <DeleteActionButton mainResource={fn.mainResource} />
+ {fn.mainResource ? (
+ <DeleteActionButton mainResource={fn.mainResource} />
+ ) : (
+ <DisabledDeleteButton />
+ )}
</ActionListItem>
</ActionList>
</Td>
@@ -133,21 +137,20 @@ function UrlCell({ url }: { url?: string }) {
);
}
-function DeleteActionButton({ mainResource }: { mainResource?: K8sResourceKind }) {
+function DisabledDeleteButton() {
const { t } = useTranslation('plugin__console-functions-plugin');
- const launchDelete = useDeleteModal(
- mainResource as K8sResourceKind,
- undefined,
- undefined,
- t('Undeploy'),
- );
+ return <Button variant="plain" aria-label={t('Delete')} icon={<TrashIcon />} isDisabled />;
+}
+
+function DeleteActionButton({ mainResource }: { mainResource: K8sResourceKind }) {
+ const { t } = useTranslation('plugin__console-functions-plugin');
+ const launchDelete = useDeleteModal(mainResource, undefined, undefined, t('Undeploy'));
return (
<Button
variant="plain"
aria-label={t('Delete')}
icon={<TrashIcon />}
- isDisabled={!mainResource}
onClick={() => launchDelete()}
/>
);There was a problem hiding this comment.
and mainResource ?? {} changes thruthines
There was a problem hiding this comment.
and
mainResource ?? {}changes thruthines
But maybe it's valid approach, I don't know.
| const functions = useMemo(() => { | ||
| const safeKnSvcs = knLoaded ? (knSvcs ?? []) : []; | ||
| const safeDeps = depLoaded ? (deps ?? []) : []; | ||
| return pairResources(safeKnSvcs, safeDeps); | ||
| }, [knSvcs, knLoaded, deps, depLoaded]); |
There was a problem hiding this comment.
| const functions = useMemo(() => { | |
| const safeKnSvcs = knLoaded ? (knSvcs ?? []) : []; | |
| const safeDeps = depLoaded ? (deps ?? []) : []; | |
| return pairResources(safeKnSvcs, safeDeps); | |
| }, [knSvcs, knLoaded, deps, depLoaded]); | |
| const functions = useMemo( | |
| () => pairResources( | |
| knLoaded ? (knSvcs ?? []) : [], | |
| depLoaded ? (deps ?? []) : [], | |
| ), | |
| [knSvcs, knLoaded, deps, depLoaded], | |
| ); |
Summary
ClusterFunctionpaired type inuseClusterService, moving ksvc-to-deployment matching logic out ofFunctionsListPageinto the hookClusterFunctionobjectsFunctionTableItem.deploymenttomainResource(it holds the ksvc, not a Deployment)Test plan
yarn cipasses (147 tests, lint clean, build succeeds)FunctionCreatePagestill works (only usesgenerateKubeconfig, unchanged)🤖 Generated with Claude Code