diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.test.tsx index 3073420f4dc58..919a500477f0c 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.test.tsx @@ -109,6 +109,38 @@ describe('AgentUpgradeAgentModal', () => { }); }); + it('should make combo invalid on clearing version', async () => { + const { utils } = renderAgentUpgradeAgentModal({ + agents: [{ id: 'agent1', local_metadata: { host: 'abc' } }] as any, + agentCount: 1, + }); + + await waitFor(() => { + fireEvent.click(utils.getByTestId('comboBoxClearButton')); + const container = utils.getByTestId('agentUpgradeModal.VersionCombobox'); + const input = within(container).getByRole('combobox'); + expect(input?.value).toEqual(''); + expect(utils.getByText('Version is required')).toBeInTheDocument(); + expect(utils.getByTestId('confirmModalConfirmButton')).toBeDisabled(); + }); + }); + + it('should make combo invalid on clearing version - bulk action', async () => { + const { utils } = renderAgentUpgradeAgentModal({ + agents: '*', + agentCount: 1, + }); + + await waitFor(() => { + fireEvent.click(utils.getByTestId('comboBoxClearButton')); + const container = utils.getByTestId('agentUpgradeModal.VersionCombobox'); + const input = within(container).getByRole('combobox'); + expect(input?.value).toEqual(''); + expect(utils.getByText('Version is required')).toBeInTheDocument(); + expect(utils.getByTestId('confirmModalConfirmButton')).toBeDisabled(); + }); + }); + it('should display the custom version text input if no versions', async () => { const { utils } = renderAgentUpgradeAgentModal({ agents: [ diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 57a23cbe412f8..e333efb152ea3 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -101,6 +101,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent(''); const QUERY_STUCK_UPDATING = `status:updating AND upgrade_started_at:* AND NOT upgraded_at:* AND upgrade_started_at < now-${AGENT_UPDATING_TIMEOUT_HOURS}h`; + const EMPTY_VALUE = useMemo(() => ({ label: '', value: '' }), []); + const [isInvalid, setIsInvalid] = useState(false); useEffect(() => { const getStuckUpdatingAgentCount = async (agentsOrQuery: Agent[] | string) => { @@ -179,10 +181,10 @@ export const AgentUpgradeAgentModal: React.FunctionComponent> = MAINTENANCE_VALUES.map( @@ -292,6 +294,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent ) : isSingleAgent ? ( + selectedVersion[0].value && !isAgentUpgradeableToVersion(agents[0], selectedVersion[0].value) ? (

@@ -433,8 +440,10 @@ export const AgentUpgradeAgentModal: React.FunctionComponent )}

@@ -443,6 +452,15 @@ export const AgentUpgradeAgentModal: React.FunctionComponent + ) : undefined + } > {noVersions ? ( >) => { if (!selected.length) { - return; + setSelectedVersion([EMPTY_VALUE]); + setIsInvalid(true); + } else { + setSelectedVersion(selected); + setIsInvalid(false); } - setSelectedVersion(selected); }} onCreateOption={ config?.internal?.onlyAllowAgentUpgradeToKnownVersions ? undefined : onCreateOption } customOptionText="Use custom agent version {searchValue} (not recommended)" + isInvalid={isInvalid} /> )}