V1 Wizard: Add search parameter for release selection

Adding an optional search parameter to the wizard like so:

/insights/image-builder/imagewizard?release=rhel8

results in the wizard being opened and RHEL 8 being pre-selected as the
release.

The Insights assistant chat bot will make use of this feature.
This commit is contained in:
lucasgarfield 2024-03-01 14:24:40 +01:00 committed by Klara Simickova
parent 2bed43645d
commit 3493772672
2 changed files with 39 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { FormSpy } from '@data-driven-forms/react-form-renderer';
import useFieldApi from '@data-driven-forms/react-form-renderer/use-field-api';
@ -10,6 +10,7 @@ import {
SelectVariant,
} from '@patternfly/react-core/deprecated';
import PropTypes from 'prop-types';
import { useSearchParams } from 'react-router-dom';
import {
RELEASES,
@ -29,6 +30,14 @@ const ImageOutputReleaseSelect = ({ label, isRequired, ...props }) => {
const [isOpen, setIsOpen] = useState(false);
const [showDevelopmentOptions, setShowDevelopmentOptions] = useState(false);
const [searchParams] = useSearchParams();
// Used to set release to RHEL 8 via search parameter, used by Insights assistant
const preloadRelease = searchParams.get('release');
useEffect(() => {
preloadRelease === 'rhel8' && change(input.name, RHEL_8);
}, [change, input.name, preloadRelease]);
const setRelease = (_, selection) => {
change(input.name, selection);
setIsOpen(false);