From 9992f8c08f8e7e8b92f87e7bb95972826b269e51 Mon Sep 17 00:00:00 2001 From: Subho Date: Tue, 18 Apr 2023 21:37:46 +0530 Subject: [PATCH] Remember VM state filter settings Fixes #1032 --- src/components/aggregateStatusCards.jsx | 8 +-- src/components/networks/networkList.jsx | 2 +- .../storagePools/storagePoolList.jsx | 2 +- src/components/vm/vmDetailsPage.jsx | 2 +- src/components/vms/hostvmslist.jsx | 36 ++++++++++-- test/check-machines-lifecycle | 58 +++++++++++++++++++ 6 files changed, 97 insertions(+), 11 deletions(-) diff --git a/src/components/aggregateStatusCards.jsx b/src/components/aggregateStatusCards.jsx index 298674559..ce15dfe89 100644 --- a/src/components/aggregateStatusCards.jsx +++ b/src/components/aggregateStatusCards.jsx @@ -42,11 +42,11 @@ export class AggregateStatusCards extends React.Component { className='ct-card-info' isSelectable onKeyDown={event => this.onCardSelect(event, 'storages')} - onClick={() => cockpit.location.go(['storages'])}> + onClick={() => cockpit.location.go(['storages'], cockpit.location.options)}> - @@ -67,11 +67,11 @@ export class AggregateStatusCards extends React.Component { className='ct-card-info' isSelectable onKeyDown={event => this.onCardSelect(event, 'networks')} - onClick={() => cockpit.location.go(['networks'])}> + onClick={() => cockpit.location.go(['networks'], cockpit.location.options)}> - diff --git a/src/components/networks/networkList.jsx b/src/components/networks/networkList.jsx index 916571c0e..46c09c5f8 100644 --- a/src/components/networks/networkList.jsx +++ b/src/components/networks/networkList.jsx @@ -47,7 +47,7 @@ export class NetworkList extends React.Component { - + {_("Virtual machines")} diff --git a/src/components/storagePools/storagePoolList.jsx b/src/components/storagePools/storagePoolList.jsx index f476a9390..95ee6ec8d 100644 --- a/src/components/storagePools/storagePoolList.jsx +++ b/src/components/storagePools/storagePoolList.jsx @@ -48,7 +48,7 @@ export class StoragePoolList extends React.Component { - + {_("Virtual machines")} diff --git a/src/components/vm/vmDetailsPage.jsx b/src/components/vm/vmDetailsPage.jsx index 91b4ad661..310121e23 100644 --- a/src/components/vm/vmDetailsPage.jsx +++ b/src/components/vm/vmDetailsPage.jsx @@ -239,7 +239,7 @@ export const VmDetailsPage = ({ - + {_("Virtual machines")} diff --git a/src/components/vms/hostvmslist.jsx b/src/components/vms/hostvmslist.jsx index 9e4833d94..9e5849783 100644 --- a/src/components/vms/hostvmslist.jsx +++ b/src/components/vms/hostvmslist.jsx @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with Cockpit; If not, see . */ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import cockpit from 'cockpit'; @@ -29,6 +29,7 @@ import { Toolbar, ToolbarContent, ToolbarItem } from "@patternfly/react-core/dis import { Select, SelectOption } from "@patternfly/react-core/dist/esm/deprecated/components/Select"; import { Page, PageSection } from "@patternfly/react-core/dist/esm/components/Page"; import { WithDialogs } from 'dialogs.jsx'; +import { usePageLocation } from 'hooks'; import VmActions from '../vm/vmActions.jsx'; import { updateVm } from '../../actions/store-actions.js'; @@ -65,11 +66,22 @@ const VmState = ({ vm, dismissError }) => { const _ = cockpit.gettext; +function getStatusFilterOption(options) { + if (!options.status) { + const defaultSelection = { value: _("All"), toString: function() { return this.value } }; + return defaultSelection; + } + + return { value: rephraseUI('resourceStates', options.status), apiState: options.status, toString: function() { return this.value } }; +} + /** * List of all VMs defined on this host */ const HostVmsList = ({ vms, config, ui, storagePools, actions, networks, onAddErrorNotification }) => { - const [statusSelected, setStatusSelected] = useState({ value: _("All"), toString: function() { return this.value } }); + const { options } = usePageLocation(); + + const [statusSelected, setStatusSelected] = useState(getStatusFilterOption(options)); const [currentTextFilter, setCurrentTextFilter] = useState(""); const [statusIsExpanded, setStatusIsExpanded] = useState(false); const combinedVms = [...vms, ...dummyVmsFilter(vms, ui.vms)]; @@ -92,6 +104,19 @@ const HostVmsList = ({ vms, config, ui, storagePools, actions, networks, onAddEr .map(state => { return { value: rephraseUI('resourceStates', state), apiState: state } }) .sort((a, b) => (prioritySorting[a.apiState] || 0) - (prioritySorting[b.apiState] || 0) || a.value.localeCompare(b.value))); + useEffect(() => { + setStatusSelected(getStatusFilterOption(options)); + }, [options]); + + const onStatusFilterChange = (selection) => { + if (selection.value === _("All")) { + delete options.status; + cockpit.location.go([], { ...options }); + } else { + cockpit.location.go([], { ...options, status: selection.apiState }); + } + }; + const toolBar = ( @@ -109,7 +134,10 @@ const HostVmsList = ({ vms, config, ui, storagePools, actions, networks, onAddEr