From ef686fc9ad4d4c8a1315495cf073c2045bfd178f Mon Sep 17 00:00:00 2001 From: Ian Ballou Date: Thu, 19 Dec 2024 23:11:26 +0000 Subject: [PATCH] Refs #38107 - BROKEN attempt to use TableComposable in TableIndexPage --- .../BootedContainerImagesPage.js | 170 ++++++++++++++---- 1 file changed, 136 insertions(+), 34 deletions(-) diff --git a/webpack/scenes/BootedContainerImages/BootedContainerImagesPage.js b/webpack/scenes/BootedContainerImages/BootedContainerImagesPage.js index 7129ec48b02..2666fc8583d 100644 --- a/webpack/scenes/BootedContainerImages/BootedContainerImagesPage.js +++ b/webpack/scenes/BootedContainerImages/BootedContainerImagesPage.js @@ -1,13 +1,24 @@ import React from 'react'; +import { TableComposable, Thead, Th, Tbody, Tr, Td, ExpandableRowContent } from '@patternfly/react-table'; import TableIndexPage from 'foremanReact/components/PF4/TableIndexPage/TableIndexPage'; -import { Table } from 'foremanReact/components/PF4/TableIndexPage/Table/Table'; import { useSetParamsAndApiAndSearch, useTableIndexAPIResponse, } from 'foremanReact/components/PF4/TableIndexPage/Table/TableIndexHooks'; import { useUrlParams, + useSet, } from 'foremanReact/components/PF4/TableIndexPage/Table/TableHooks'; +import { + getColumnHelpers, +} from 'foremanReact/components/PF4/TableIndexPage/Table/helpers'; +import { + useTableSort, +} from 'foremanReact/components/PF4/Helpers/useTableSort'; +import { + Pagination, +} from 'foremanReact/components/Pagination'; +import EmptyPage from 'foremanReact/routes/common/EmptyPage'; import { translate as __ } from 'foremanReact/common/I18n'; import BOOTED_CONTAINER_IMAGES_KEY, { BOOTED_CONTAINER_IMAGES_API_PATH } from './BootedContainerImagesConstants'; @@ -29,12 +40,6 @@ const BootedContainerImagesPage = () => { }, }; - const STATUS = { - PENDING: 'PENDING', - RESOLVED: 'RESOLVED', - ERROR: 'ERROR', - }; - const { searchParam: urlSearchQuery = '', page: urlPage, @@ -44,15 +49,34 @@ const BootedContainerImagesPage = () => { if (urlPage) defaultParams.page = Number(urlPage); if (urlPerPage) defaultParams.per_page = Number(urlPerPage); const apiOptions = { key: BOOTED_CONTAINER_IMAGES_KEY }; + const response = useTableIndexAPIResponse({ apiUrl: BOOTED_CONTAINER_IMAGES_API_PATH, apiOptions, defaultParams, }); + const columnsToSortParams = {}; + Object.keys(columns).forEach(key => { + if (columns[key].isSorted) { + columnsToSortParams[columns[key].title] = key; + } + }); + const { pfSortParams } = useTableSort({ + allColumns: Object.keys(columns).map(k => columns[k].title), + columnsToSortParams, + onSort, + }); + const expandedImages = useSet([]); + const imageIsExpanded = image_name => expandedImages.has(image_name); + const STATUS = { + PENDING: 'PENDING', + RESOLVED: 'RESOLVED', + ERROR: 'ERROR', + }; const { response: { - results, + results = [], per_page: perPage, page, subtotal, @@ -68,40 +92,118 @@ const BootedContainerImagesPage = () => { setAPIOptions: response.setAPIOptions, }); + const [columnNamesKeys, keysToColumnNames] = getColumnHelpers(columns); + const onSort = (_event, index, direction) => { + setParamsAndAPI({ + ...params, + order: `${Object.keys(columns)[index]} ${direction}`, + }); + }; + const onPagination = newPagination => { + setParamsAndAPI({ ...params, ...newPagination }); + }; + const bottomPagination = ( + + ); + return ( - - setAPIOptions({ - ...apiOptions, - params: { urlSearchQuery }, - }) - } - columns={columns} - errorMessage={ - status === STATUS.ERROR && errorMessage ? errorMessage : null - } - isPending={status === STATUS.PENDING} - /> + <> + + + + {columnNamesKeys.map(k => ( + + ))} + + + + {status === STATUS.PENDING && results.length === 0 && ( + + + + )} + {!status === STATUS.PENDING && + results.length === 0 && + !errorMessage && ( + + + + )} + {errorMessage && ( + + + + )} + + {results?.map((result, rowIndex) => { + const { image_name, digests } = result; + const isExpanded = imageIsExpanded(image_name); + return ( + + + {columnNamesKeys.map(k => ( + + ))} + + {digests ? + + {digests[0].bootc_booted_digest} + + : null} + + ); + })} + + {results.length > 0 && !errorMessage && bottomPagination} + ); };
+ {keysToColumnNames[k]} +
+ +
+ +
+ +
expandedImages.onToggle(isOpen, image_name), + }} + > + {columns[k].wrapper ? columns[k].wrapper(result) : result[k]} +