-
Notifications
You must be signed in to change notification settings - Fork 74
Wizard: let the target radios drive the official image (HMS-11166) #4737
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
Closed
lucasgarfield
wants to merge
2
commits into
lucas/cockpit/3-official-images
from
lucas/cockpit/4-target-sync
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
...ateImageWizard/steps/ImageOutput/components/ImageSourceSelect/OnPrem/ContainerSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { | ||
| Button, | ||
| ClipboardCopy, | ||
| Content, | ||
| Flex, | ||
| FlexItem, | ||
| FormGroup, | ||
| FormHelperText, | ||
| HelperText, | ||
| HelperTextItem, | ||
| Spinner, | ||
| Tooltip, | ||
| } from '@patternfly/react-core'; | ||
|
|
||
| import { | ||
| useGetImageExistsQuery, | ||
| useGetRegistryAuthStatusQuery, | ||
| usePullImageMutation, | ||
| } from '@/store/api/backend'; | ||
| import { IMAGE_REGISTRY_HOST } from '@/store/api/backend/onprem/constants'; | ||
|
|
||
| type PullButtonProps = { | ||
| onPull: () => void; | ||
| isPulling: boolean; | ||
| isAuthenticated: boolean; | ||
| isDisabled?: boolean; | ||
| }; | ||
|
|
||
| const PullButton = ({ | ||
| onPull, | ||
| isPulling, | ||
| isAuthenticated, | ||
| isDisabled, | ||
| }: PullButtonProps) => { | ||
| const button = ( | ||
| <Button | ||
| variant='secondary' | ||
| onClick={onPull} | ||
| isDisabled={isDisabled || isPulling} | ||
| isAriaDisabled={!isAuthenticated} | ||
| icon={isPulling ? <Spinner size='sm' /> : undefined} | ||
| > | ||
| {isPulling ? 'Pulling image...' : 'Pull latest image'} | ||
| </Button> | ||
| ); | ||
|
|
||
| if (isAuthenticated) { | ||
| return button; | ||
| } | ||
|
|
||
| return ( | ||
| <Tooltip content={`Log in to ${IMAGE_REGISTRY_HOST} to pull images.`}> | ||
| {button} | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
| type ContainerSectionProps = { | ||
| label: string; | ||
| // Unset until a target environment implies a container | ||
| reference?: string | undefined; | ||
| // Human-readable image name, shown as a subtitle under the reference | ||
| name?: string | undefined; | ||
| helperText?: string; | ||
| }; | ||
|
|
||
| // A container determined by the selected target environment. The | ||
| // reference is shown in a read-only, copyable field - PatternFly's | ||
| // "boxed" read-only form control - because the containers behind the | ||
| // official images are never chosen directly. When local images become | ||
| // selectable this slot swaps to a real select, so the layout | ||
| // deliberately reads as a form field. | ||
| const ContainerSection = ({ | ||
| label, | ||
| reference, | ||
| name, | ||
| helperText, | ||
| }: ContainerSectionProps) => { | ||
| const { data: authStatus, isLoading: isAuthLoading } = | ||
| useGetRegistryAuthStatusQuery(undefined, { | ||
| refetchOnMountOrArgChange: true, | ||
| }); | ||
| const isAuthenticated = authStatus?.status === 'authenticated'; | ||
|
|
||
| // Local images can be removed outside the wizard (e.g. podman rmi), | ||
| // so bypass the cache and re-check whenever this section mounts. | ||
| const { data: imageExists } = useGetImageExistsQuery( | ||
| { reference: reference! }, | ||
| { skip: !reference, refetchOnMountOrArgChange: true }, | ||
| ); | ||
|
|
||
| // The mutation state is scoped to the reference it was started with, | ||
| // so switching to another image doesn't show its busy/error state. | ||
| const [pullImage, pullState] = usePullImageMutation(); | ||
| const isPulling = | ||
| pullState.isLoading && pullState.originalArgs?.reference === reference; | ||
| const isPullError = | ||
| pullState.isError && pullState.originalArgs?.reference === reference; | ||
|
|
||
| const showPullValidation = !!reference && imageExists === false; | ||
|
|
||
| if (!reference) { | ||
| return ( | ||
| <FormGroup label={label} className='pf-v6-u-mt-md'> | ||
| <Content component='p' className='pf-v6-u-text-color-subtle'> | ||
| Select a target environment to see the container image it uses. | ||
| </Content> | ||
| </FormGroup> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <FormGroup label={label} className='pf-v6-u-mt-md'> | ||
| <Flex | ||
| spaceItems={{ default: 'spaceItemsMd' }} | ||
| alignItems={{ default: 'alignItemsCenter' }} | ||
| > | ||
| <FlexItem style={{ minWidth: '24rem', maxWidth: '100%' }}> | ||
| <ClipboardCopy isReadOnly hoverTip='Copy' clickTip='Copied'> | ||
| {reference} | ||
| </ClipboardCopy> | ||
| </FlexItem> | ||
| <FlexItem> | ||
| <PullButton | ||
| onPull={() => pullImage({ reference })} | ||
| isPulling={isPulling} | ||
| isAuthenticated={isAuthenticated} | ||
| isDisabled={isAuthLoading} | ||
| /> | ||
| </FlexItem> | ||
| </Flex> | ||
| {(name || helperText) && ( | ||
| <FormHelperText> | ||
| <HelperText> | ||
| {name && <HelperTextItem>{name}</HelperTextItem>} | ||
| {helperText && <HelperTextItem>{helperText}</HelperTextItem>} | ||
| </HelperText> | ||
| </FormHelperText> | ||
| )} | ||
| {showPullValidation && ( | ||
| <FormHelperText> | ||
| <HelperText> | ||
| <HelperTextItem variant='error'> | ||
| {isPullError | ||
| ? 'Failed to pull image. Please try again.' | ||
| : isAuthenticated | ||
| ? `${label} must be pulled before proceeding.` | ||
| : `${label} is not in local storage. Log in to ${IMAGE_REGISTRY_HOST} to pull it.`} | ||
| </HelperTextItem> | ||
| </HelperText> | ||
| </FormHelperText> | ||
| )} | ||
| </FormGroup> | ||
| ); | ||
| }; | ||
|
|
||
| export default ContainerSection; | ||
103 changes: 0 additions & 103 deletions
103
...s/CreateImageWizard/steps/ImageOutput/components/ImageSourceSelect/OnPrem/ImageSelect.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
suggestion (bug_risk): Avoid using a non-null assertion for reference when the hook is skipped
reference!is unsafe here:referenceis allowed to be undefined and the query is already guarded viaskip: !reference. The non-null assertion hides that possibility and makes future refactors more error-prone. Prefer either:reference ?? ''), orreferenceis truthy (e.g.reference ? { reference } : skipToken).This keeps the types accurate and avoids relying on
!in the hook args.Suggested implementation:
You also need to ensure
skipTokenis imported in this file. If not already present, add:near the other imports (or from the specific RTK Query entrypoint your project uses, such as
@reduxjs/toolkit/query/reactif that's the convention in this codebase).