From 4f81e7ae151d535f62567b947523ae8d68a21af1 Mon Sep 17 00:00:00 2001 From: Ugo Palatucci Date: Thu, 21 Mar 2024 14:56:02 +0100 Subject: [PATCH] CNV-39752: Button to expand all sections --- .../en/plugin__nmstate-console-plugin.json | 2 + src/views/states/list/StatesList.tsx | 65 ++++++++++--------- .../list/components/InterfacesTable.tsx | 8 ++- .../list/components/InterfacesTypeSection.tsx | 8 ++- src/views/states/list/components/StateRow.tsx | 19 ++++-- 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/locales/en/plugin__nmstate-console-plugin.json b/locales/en/plugin__nmstate-console-plugin.json index 90453adc..bb1163f0 100644 --- a/locales/en/plugin__nmstate-console-plugin.json +++ b/locales/en/plugin__nmstate-console-plugin.json @@ -20,6 +20,7 @@ "Cannot delete in view-only mode": "Cannot delete in view-only mode", "Cannot edit in view-only mode": "Cannot edit in view-only mode", "Click <1>Create NodeNetworkConfigurationPolicy to create your first policy": "Click <1>Create NodeNetworkConfigurationPolicy to create your first policy", + "Collapse all": "Collapse all", "Confirm deletion by typing <1>{{name}} below:": "Confirm deletion by typing <1>{{name}} below:", "Copied": "Copied", "Copy": "Copy", @@ -51,6 +52,7 @@ "Enactment states": "Enactment states", "Enactments categorized by status": "Enactments categorized by status", "Enter name": "Enter name", + "Expand all": "Expand all", "Explore {{kind}} list": "Explore {{kind}} list", "Failing": "Failing", "Features": "Features", diff --git a/src/views/states/list/StatesList.tsx b/src/views/states/list/StatesList.tsx index e5ee9ff0..7f1ba26f 100644 --- a/src/views/states/list/StatesList.tsx +++ b/src/views/states/list/StatesList.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react'; +import React, { FC, useState } from 'react'; import { NodeNetworkStateModelGroupVersionKind, NodeNetworkStateModelRef, @@ -13,7 +13,7 @@ import { useK8sWatchResource, useListPageFilter, } from '@openshift-console/dynamic-plugin-sdk'; -import { Pagination } from '@patternfly/react-core'; +import { Button, Flex, Pagination } from '@patternfly/react-core'; import { Table, TableGridBreakpoint, Th, Thead, Tr } from '@patternfly/react-table'; import { V1beta1NodeNetworkState } from '@types'; import usePagination from '@utils/hooks/usePagination/usePagination'; @@ -35,6 +35,8 @@ const StatesList: FC = () => { const { t } = useNMStateTranslation(); const { selectedInterfaceName, selectedStateName, selectedInterfaceType } = useDrawerInterface(); + const [expandAll, setExpandAll] = useState(false); + const [states, statesLoaded, statesError] = useK8sWatchResource({ groupVersionKind: NodeNetworkStateModelGroupVersionKind, isList: true, @@ -67,32 +69,37 @@ const StatesList: FC = () => {
- { - onFilterChange(...args); - onPaginationChange({ - endIndex: pagination?.perPage, - page: 1, - perPage: pagination?.perPage, - startIndex: 0, - }); - }} - columnLayout={{ - columns: columns?.map(({ id, title, additional }) => ({ - id, - title, - additional, - })), - id: NodeNetworkStateModelRef, - selectedColumns: new Set(activeColumns?.map((col) => col?.id)), - type: t('NodeNetworkState'), - }} - /> + + { + onFilterChange(...args); + onPaginationChange({ + endIndex: pagination?.perPage, + page: 1, + perPage: pagination?.perPage, + startIndex: 0, + }); + }} + columnLayout={{ + columns: columns?.map(({ id, title, additional }) => ({ + id, + title, + additional, + })), + id: NodeNetworkStateModelRef, + selectedColumns: new Set(activeColumns?.map((col) => col?.id)), + type: t('NodeNetworkState'), + }} + /> + + onPaginationChange({ endIndex, page, perPage, startIndex }) @@ -128,7 +135,7 @@ const StatesList: FC = () => { key={nnstate?.metadata?.name} obj={nnstate} activeColumnIDs={new Set(activeColumns.map(({ id }) => id))} - rowData={{ rowIndex: index, selectedFilters }} + rowData={{ rowIndex: index, selectedFilters, expandAll }} /> ))} diff --git a/src/views/states/list/components/InterfacesTable.tsx b/src/views/states/list/components/InterfacesTable.tsx index 1e4f5725..ab995675 100644 --- a/src/views/states/list/components/InterfacesTable.tsx +++ b/src/views/states/list/components/InterfacesTable.tsx @@ -12,9 +12,14 @@ import './interfaces-table.scss'; interface InterfacesTableProps { interfacesByType: { [interfaceType in string]: NodeNetworkConfigurationInterface[] }; nodeNetworkState: V1beta1NodeNetworkState; + expandAll: boolean; } -const InterfacesTable: FC = ({ interfacesByType, nodeNetworkState }) => { +const InterfacesTable: FC = ({ + interfacesByType, + nodeNetworkState, + expandAll, +}) => { const columns = useInterfaceColumns(); return ( @@ -41,6 +46,7 @@ const InterfacesTable: FC = ({ interfacesByType, nodeNetwo interfaceType={interfaceType} interfaces={interfacesByType[interfaceType]} nodeNetworkState={nodeNetworkState} + expandAll={expandAll} /> ))} diff --git a/src/views/states/list/components/InterfacesTypeSection.tsx b/src/views/states/list/components/InterfacesTypeSection.tsx index 425b7975..90ff7c89 100644 --- a/src/views/states/list/components/InterfacesTypeSection.tsx +++ b/src/views/states/list/components/InterfacesTypeSection.tsx @@ -22,21 +22,23 @@ interface InterfacesTypeSectionProps { interfaces: NodeNetworkConfigurationInterface[]; interfaceType: string; nodeNetworkState: V1beta1NodeNetworkState; + expandAll: boolean; } const InterfacesTypeSection: FC = memo( - ({ interfaceType, interfaces, nodeNetworkState }) => { - const [isExpanded, setIsExpanded] = useState(false); + ({ interfaceType, interfaces, nodeNetworkState, expandAll }) => { + const [expand, setExpand] = useState(false); const { setSelectedInterfaceName } = useDrawerInterface(); + const isExpanded = expandAll || expand; return ( <> diff --git a/src/views/states/list/components/StateRow.tsx b/src/views/states/list/components/StateRow.tsx index 6f3bc4b5..fde56764 100644 --- a/src/views/states/list/components/StateRow.tsx +++ b/src/views/states/list/components/StateRow.tsx @@ -16,9 +16,12 @@ import { filterInterfaces, getInterfacesByType } from './utils'; import './state-row.scss'; const StateRow: FC< - RowProps -> = ({ obj, activeColumnIDs, rowData: { rowIndex, selectedFilters } }) => { - const [isExpanded, setIsExpanded] = useState(false); + RowProps< + V1beta1NodeNetworkState, + { rowIndex: number; selectedFilters: SelectedFilters; expandAll: boolean } + > +> = ({ obj, activeColumnIDs, rowData: { rowIndex, selectedFilters, expandAll } }) => { + const [expand, setExpand] = useState(false); const { t } = useNMStateTranslation(); const interfaces = obj?.status?.currentState?.interfaces as NodeNetworkConfigurationInterface[]; @@ -32,6 +35,8 @@ const StateRow: FC< [filteredInterfaces], ); + const isExpanded = expandAll || expand; + return ( @@ -39,7 +44,7 @@ const StateRow: FC< expand={{ rowIndex, isExpanded, - onToggle: (event, rowIndex, isOpen) => setIsExpanded(isOpen), + onToggle: (event, rowIndex, isOpen) => setExpand(isOpen), expandId: 'expand-interfaces-list', }} /> @@ -93,7 +98,11 @@ const StateRow: FC< - +