fix: filter hidden options and display restrictions popover - #1325
fix: filter hidden options and display restrictions popover#1325Snehadas2005 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
33e6e98 to
d763a63
Compare
|
Thank you for the reminder, @christian-heusel! It would be very helpful if you could review the codebase and identify any necessary changes. |
christian-heusel
left a comment
There was a problem hiding this comment.
Hey, thanks a lot for working on this change! 🤗
I found a few things that require changing, although I need to defer to the actual frontend maintainers for a proper review though 😅
| "concurrently": "^9.1.0", | ||
| "copy-webpack-plugin": "^13.0.0", | ||
| "core-js": "^3.40.0", | ||
| "core-js": "^3.40.0", |
There was a problem hiding this comment.
Please remove this extra whitespace change 😅
| @@ -95,6 +90,11 @@ declare global { | |||
| }, | |||
| response: string | ApiErrorEnvelope, | |||
| ) => Cypress.Chainable<null>) & | |||
| (( | |||
| type: 'POST /api/:apiVersion/workspaces/:namespace/:workspaceName/actions/pause', | |||
| options: { path: { apiVersion: string; namespace: string; workspaceName: string } }, | |||
| response: ApiWorkspaceActionPauseEnvelope | ApiErrorEnvelope, | |||
| ) => Cypress.Chainable<null>) & | |||
There was a problem hiding this comment.
I think you moved this on accident without changing it 🤔 Given that it is unchanged, please remove that diff from the PR 🤗
| if (defaultOption && !defaultOption.restrictions?.deny) { | ||
| return defaultId; | ||
| } |
There was a problem hiding this comment.
We should also check here whether the option is hidden (and not only for .deny)
Maybe you could just move the isUsable up a bit and check for defaultOption && isUsable? 🤔
There was a problem hiding this comment.
Thank you for your feedback on this! I intentionally kept it set to deny only, as outlined in the Cypress contracts for optionCardDisplay.cy.ts and createWorkspace.cy.ts. The expectation is that hidden options remain selectable and eligible by default, as they are indicated by the hidden badge and associated confirmation modal. Introducing a hidden check would disrupt this workflow. However, I am open to adapting if you see merit in revising the test contract. Happy to have your thoughts on this one. 😊
| const podConfigOptions = filteredValuesData.podConfig.values ?? []; | ||
| const isStillValid = podConfigOptions.some((pc) => pc.id === data.podConfig); | ||
| const current = podConfigOptions.find((pc) => pc.id === data.podConfig); | ||
| const isStillValid = !!current; // denied-but-present is left alone on purpose |
There was a problem hiding this comment.
Should we also check for hidden here? 🤔
Show more detailed finding (backed by 🤖, so treat with caution):
The podConfig re-validation effect only checks that the current selection still exists in the list, not whether it's become hidden. A podConfig that flips to hidden: true (but isn't denied) stays selected, contradicting the PR description's rule to clear hidden (even non-denied) selections.
The bug: isStillValid only checks that the id is still present in the returned list (!!current). It never looks at current.hidden. A podConfig option that becomes incompatible with the newly selected image but is represented as hidden: true (rather than removed from the array or restrictions.deny: true) still passes isStillValid, so the selection is silently kept.
Concrete failure scenario:
- User selects image A, then picks
podConfig"Large" — visible, not hidden, not denied for image A. - User goes back and switches the image to B.
- filteredValuesData refetches with imageId: B. The backend marks "Large" as hidden: true for this image (still present in the array, not denyd).
- The effect finds current (id still in the list) →
isStillValid = true→data.podConfigis left as "Large". - The pod-config picker (which presumably filters out hidden options from the visible list, same as the image picker) no longer shows "Large" as selectable/visible, but the form state still carries it forward to Summary and submission — the user has a selection they can't see, can't consciously confirm, and can't change without noticing something's off.
This contradicts the PR's own stated rule (per the review) that a selection should be preserved only "if they exist and are not hidden (even if denied)" — i.e., hidden should clear it, but a merely-denied-and-visible option should not.
Fix: add the hidden check, keeping the deny exemption the comment describes:
const isStillValid = !!current && !current.hidden; // denied-but-present is left alone on purpose| const useWorkspacePodTemplateDetails = ( | ||
| namespace?: string, | ||
| name?: string, | ||
| ): FetchState<ApiWorkspaceDetailsEnvelope['data'] | null> => { | ||
| const { api, apiAvailable } = useNotebookAPI(); | ||
|
|
||
| const call = useCallback< | ||
| FetchStateCallbackPromise<ApiWorkspaceDetailsEnvelope['data'] | null> | ||
| >(async () => { | ||
| if (!apiAvailable) { | ||
| return Promise.reject(new Error('API not yet available')); | ||
| } | ||
| if (!namespace || !name) { | ||
| return null; | ||
| } | ||
|
|
||
| const envelope = await api.workspaces.getWorkspacePodTemplateDetails(namespace, name); | ||
| return envelope.data; | ||
| }, [api, apiAvailable, namespace, name]); | ||
|
|
||
| return useFetchState(call, null); | ||
| }; | ||
|
|
||
| export default useWorkspacePodTemplateDetails; |
There was a problem hiding this comment.
This duplicates the existing hook in useWorkspaceDetails.ts (🤖 -finding):
Both hooks wrap the exact same backend call, api.workspaces.getWorkspacePodTemplateDetails(namespace, name):
workspaces/frontend/src/app/hooks/useWorkspaceDetails.tsworkspaces/frontend/src/app/hooks/useWorkspacePodTemplateDetails.ts
WorkspaceDetails.tsx (and its test) were switched over to useWorkspacePodTemplateDetails in this PR, but useWorkspaceDetails was left in the tree instead of being reused/renamed. A repo-wide search shows it now has zero callers outside its own file and its own spec test (useWorkspaceDetails.spec.tsx) hence it's now orphaned.
The two hooks differ only slightly (return-type wrapper: DetailsWorkspaceDetails | null vs ApiWorkspaceDetailsEnvelope['data'] | null, which are structurally the same; missing-args behavior: rejects with NotReadyError vs returns null; named vs default export), so this reads like a copy made to fit the new call site rather than an intentional second hook.
Suggestion: delete useWorkspaceDetails.ts + useWorkspaceDetails.spec.tsx (if the null-on-missing-args behavior of useWorkspacePodTemplateDetails is acceptable everywhere), or fold the two into a single hook and update the one call site. Otherwise this leaves two near-identically-named hooks for the same data in the codebase, which will confuse future readers about which one is actually live.
There was a problem hiding this comment.
This PR also seems to mess with the sizing in the create workflow, i.e. when selecting the GPU podOption this now resizes things:
Before (notebooks-v2 checkout at 07a611c):
After:
Since this expansion only happens for selected items this is rather surprising for the user 🤔
8e4b94a to
3c6ffbc
Compare
|
Thank you for the review, @christian-heusel! I have updated the PR and addressed all the cleanup points:
Everything is green locally ( /cc @thaorell for frontend review whenever you get a chance. |
3c6ffbc to
b21c56b
Compare
Signed-off-by: Sneha Das <154408198+Snehadas2005@users.noreply.github.com>
b21c56b to
53ab940
Compare
Fixes issue where restricted or hidden options were not properly evaluated or displayed in the Workspace creation/edit wizard.
This PR implements rule-based option filtering and restriction handling for both Image Config and Pod Config selection steps:
hidden: truefrom the available selection lists.restrictions.deny: trueas disabled (isDisabled) and non-selectable, displaying aBanIconwith a hover popover containing the restriction message (denyMessage.text).Key Changes:
WorkspaceFormOptionCard.tsx: Updated option card to checkrestrictions.deny, apply disabled styling (workspace-option-card--restricted), block card click interactions, and renderRestrictedIconWithPopover.RestrictedIconWithPopover.tsx: Added PatternFlyPopoverwrapper withBanIconto show restriction explanation text on hover.WorkspaceFormImageList.tsx&WorkspaceFormPodConfigList.tsx: Added defensive check in option click/change handlers to prevent selection of denied options.WorkspaceForm.tsx: AddedresolveUsableDefaulthelper to resolve usable (non-hidden, non-denied) default options forimageConfigandpodConfig. Updated podConfig re-validation effect to leave denied-but-present options selected for clear UI feedback.testBuilders.ts: AddedbuildMockImageWithRestrictionstest helper for unit and Cypress tests.Screenshots / UI Verification:
How to Test:
npm run start:devhidden: truedo not appear.restrictions.deny: trueare disabled and hovering over the icon displays the restriction text.closes: #1209
related: #735