Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import {
ToolbarContent,
ToolbarGroup,
ToolbarItem,
PageSection,
PageSectionVariants,
TextContent,
Text,
Icon,
PaginationVariant,
} from '@patternfly/react-core';
Expand All @@ -27,16 +23,16 @@ import { translate as __ } from '../../../common/I18n';
import { noop } from '../../../common/helpers';
import Pagination from '../../Pagination';
import { getControllerSearchProps, STATUS } from '../../../constants';
import BreadcrumbBar from '../../BreadcrumbBar';
import PageLayout from '../../../routes/common/PageLayout/PageLayout';
import SearchBar from '../../SearchBar';
import Head from '../../Head';
import { ActionButtons } from './ActionButtons';
import './TableIndexPage.scss';
import { Table } from './Table/Table';
import {
useSetParamsAndApiAndSearch,
useTableIndexAPIResponse,
} from './Table/TableIndexHooks';

/**

A page component that displays a table with data fetched from the API. It provides search and filtering functionality, and the ability to create new entries and export data.
Expand All @@ -62,7 +58,6 @@ A page component that displays a table with data fetched from the API. It provid
@param {boolean} {exportable} - whether or not to show export button
@param {boolean} {hasHelpPage} - whether or not to show documentation button
@param {React.ReactNode}{customHeader} - a custom header to be rendered instead of the default header
@param {string}{headerText} - DEPRECATED - the header text for the page
@param {string}{header} -the header text for the page and the title
@param {boolean} {isDeleteable} - whether or not entries can be deleted
@param {boolean} {searchable} - whether or not the table can be searched
Expand Down Expand Up @@ -101,7 +96,6 @@ const TableIndexPage = ({
exportable,
hasHelpPage,
customHeader,
headerText,
header,
isDeleteable,
searchable,
Expand Down Expand Up @@ -224,138 +218,113 @@ const TableIndexPage = ({
...customActionButtons,
].filter(item => item);

header = headerText || header;
return (
<div id="foreman-page">
<Head>
<title>{header}</title>
</Head>
{breadcrumbOptions && (
<PageSection variant={PageSectionVariants.light} type="breadcrumb">
<BreadcrumbBar {...breadcrumbOptions} />
</PageSection>
)}
<PageSection
variant={PageSectionVariants.light}
className="table-title-section"
>
{customHeader || (
<TextContent>
<Text ouiaId="header-text" component="h1">
{header}
</Text>
</TextContent>
)}
</PageSection>
{beforeToolbarComponent}
<PageSection
variant={PageSectionVariants.light}
className="table-toolbar-section"
>
<Toolbar ouiaId="table-toolbar" className="table-toolbar">
<ToolbarContent>
{searchable && (
<ToolbarGroup
className="toolbar-group-search"
variant="filter-group"
>
{selectionToolbar}
<ToolbarItem className="toolbar-search">
<SearchBar
data={searchProps}
initialQuery=""
restrictedSearchQuery={restrictedSearchQuery}
onSearch={onSearch}
bookmarksPosition={bookmarksPosition}
/>
</ToolbarItem>
{status === STATUS.PENDING && (
<ToolbarItem>
<Spinner size="sm" />
</ToolbarItem>
)}
</ToolbarGroup>
)}
{(customToolbarItems || actionButtons.length > 0) && (
<ToolbarGroup
align={{ default: 'alignLeft' }}
className="table-toolbar-actions"
variant="button-group"
>
{actionButtons.length > 0 && (
<ToolbarItem>
<ActionButtons buttons={actionButtons} />
</ToolbarItem>
)}
{customToolbarItems && customToolbarItems}
</ToolbarGroup>
)}
{total > 0 && (
<Pagination
key="table-index-page-top-pagination"
updateParamsByUrl={updateParamsByUrl}
variant={PaginationVariant.top}
page={page}
perPage={perPage}
itemCount={subtotal}
onChange={onPagination}
const customToolbar = (
<Toolbar ouiaId="table-toolbar" className="table-toolbar">
<ToolbarContent>
{searchable && (
<ToolbarGroup className="toolbar-group-search" variant="filter-group">
{selectionToolbar}
<ToolbarItem className="toolbar-search">
<SearchBar
data={searchProps}
initialQuery=""
restrictedSearchQuery={restrictedSearchQuery}
onSearch={onSearch}
bookmarksPosition={bookmarksPosition}
/>
</ToolbarItem>
{status === STATUS.PENDING && (
<ToolbarItem>
<Spinner size="sm" />
</ToolbarItem>
)}
</ToolbarContent>
</Toolbar>
</PageSection>
<PageSection
variant={PageSectionVariants.light}
className="table-section"
>
{children || (
<Table
isEmbedded={!updateParamsByUrl}
params={{
...params,
page,
perPage,
}}
setParams={setParamsAndAPI}
ouiaId={ouiaId}
bottomPagination={
<Pagination
key="table-bottom-pagination-yes"
page={page}
perPage={perPage}
itemCount={subtotal}
onChange={onPagination}
updateParamsByUrl={updateParamsByUrl}
/>
}
getActions={rowKebabItems}
</ToolbarGroup>
)}
{(customToolbarItems || actionButtons.length > 0) && (
<ToolbarGroup
align={{ default: 'alignLeft' }}
className="table-toolbar-actions"
variant="button-group"
>
{actionButtons.length > 0 && (
<ToolbarItem>
<ActionButtons buttons={actionButtons} />
</ToolbarItem>
)}
{customToolbarItems && customToolbarItems}
</ToolbarGroup>
)}
{total > 0 && (
<Pagination
key="table-index-page-top-pagination"
updateParamsByUrl={updateParamsByUrl}
variant={PaginationVariant.top}
page={page}
perPage={perPage}
itemCount={subtotal}
results={results}
url={apiUrl}
isDeleteable={isDeleteable}
refreshData={() =>
setAPIOptions({
...apiOptions,
params: { search },
})
}
columns={columns}
errorMessage={
status === STATUS.ERROR && errorMessage ? errorMessage : null
}
isPending={status === STATUS.PENDING}
selectOne={selectOne}
isSelected={isSelected}
showCheckboxes={showCheckboxes}
rowSelectTd={rowSelectTd}
idColumn={idColumn}
customEmptyState={customEmptyState}
emptyMessage={emptyMessage}
emptyAction={emptyAction}
onChange={onPagination}
/>
)}
</PageSection>
</div>
</ToolbarContent>
</Toolbar>
);

return (
<PageLayout
breadcrumbOptions={breadcrumbOptions}
header={header}
customHeader={customHeader}
searchable={false}
beforeToolbarComponent={beforeToolbarComponent}
customToolbar={customToolbar}
>
{children || (
<Table
isEmbedded={!updateParamsByUrl}
params={{
...params,
page,
perPage,
}}
setParams={setParamsAndAPI}
ouiaId={ouiaId}
bottomPagination={
<Pagination
key="table-bottom-pagination-yes"
page={page}
perPage={perPage}
itemCount={subtotal}
onChange={onPagination}
updateParamsByUrl={updateParamsByUrl}
/>
}
getActions={rowKebabItems}
itemCount={subtotal}
results={results}
url={apiUrl}
isDeleteable={isDeleteable}
refreshData={() =>
setAPIOptions({
...apiOptions,
params: { search },
})
}
columns={columns}
errorMessage={
status === STATUS.ERROR && errorMessage ? errorMessage : null
}
isPending={status === STATUS.PENDING}
selectOne={selectOne}
isSelected={isSelected}
showCheckboxes={showCheckboxes}
rowSelectTd={rowSelectTd}
idColumn={idColumn}
customEmptyState={customEmptyState}
emptyMessage={emptyMessage}
emptyAction={emptyAction}
/>
)}
</PageLayout>
);
};

Expand Down Expand Up @@ -399,7 +368,6 @@ TableIndexPage.propTypes = {
replacementResponse: PropTypes.object,
exportable: PropTypes.bool,
hasHelpPage: PropTypes.bool,
headerText: PropTypes.string,
header: PropTypes.string,
customHeader: PropTypes.node,
isDeleteable: PropTypes.bool,
Expand Down Expand Up @@ -442,7 +410,6 @@ TableIndexPage.defaultProps = {
exportable: false,
hasHelpPage: false,
header: '',
headerText: '',
customHeader: undefined,
isDeleteable: false,
searchable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#foreman-page {
.table-title-section {
padding-bottom: 0;
}
.table-toolbar-section {
padding-top: 16px;
padding-bottom: 16px;
.page-toolbar-section {
padding-top: var(--pf-v5-global--spacer--md);
padding-bottom: var(--pf-v5-global--spacer--md);

.table-toolbar {
padding: 0;
.pf-v5-c-toolbar__content {
Expand All @@ -15,7 +13,7 @@
display: block;
}
.table-toolbar-actions {
padding-left: 16px;
padding-left: var(--pf-v5-global--spacer--md);
}
}
.pf-v5-c-toolbar__group {
Expand All @@ -25,7 +23,7 @@
}
}
}
.table-section {
.page-content-section {
padding-top: 0;
padding-left: 0;
padding-right: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ exports[`AuditsPage rendering render audits page 1`] = `
beforeToolbarComponent={null}
breadcrumbOptions={null}
customBreadcrumbs={null}
customHeader={null}
customToolbar={null}
header="Audits"
isLoading={false}
onSearch={[Function]}
Expand Down Expand Up @@ -79,6 +81,8 @@ exports[`AuditsPage rendering render audits page w/empty audits 1`] = `
beforeToolbarComponent={null}
breadcrumbOptions={null}
customBreadcrumbs={null}
customHeader={null}
customToolbar={null}
header="Audits"
isLoading={false}
onSearch={[Function]}
Expand Down Expand Up @@ -155,6 +159,8 @@ exports[`AuditsPage rendering render audits page w/error 1`] = `
beforeToolbarComponent={null}
breadcrumbOptions={null}
customBreadcrumbs={null}
customHeader={null}
customToolbar={null}
header="Audits"
isLoading={false}
onSearch={[Function]}
Expand Down Expand Up @@ -231,6 +237,8 @@ exports[`AuditsPage rendering render loading audits page 1`] = `
beforeToolbarComponent={null}
breadcrumbOptions={null}
customBreadcrumbs={null}
customHeader={null}
customToolbar={null}
header="Audits"
isLoading={false}
onSearch={[Function]}
Expand Down
Loading
Loading