-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36720 - Composable Expandable Table for Smart Proxy content
(cherry picked from commit c5dc9dd)
- Loading branch information
Showing
4 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { TableComposable, Thead, Tr, Th, Tbody, Td, TableVariant } from '@patternfly/react-table'; | ||
import { CheckCircleIcon, TimesCircleIcon } from '@patternfly/react-icons'; | ||
import LongDateTime from 'foremanReact/components/common/dates/LongDateTime'; | ||
import { urlBuilder } from 'foremanReact/common/urlHelpers'; | ||
import ContentViewIcon from '../ContentViews/components/ContentViewIcon'; | ||
|
||
const ExpandableCvDetails = ({ data }) => { | ||
const columnHeaders = [ | ||
__('Content View'), | ||
__('Last published'), | ||
__('Repositories'), | ||
__('Last sync'), | ||
]; | ||
|
||
return ( | ||
<TableComposable | ||
variant={TableVariant.compact} | ||
aria-label="content-views" | ||
> | ||
<Thead> | ||
<Tr> | ||
{columnHeaders.map(col => ( | ||
<Th | ||
key={col} | ||
> | ||
{col} | ||
</Th> | ||
))} | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{data.map((cv, rowIndex) => { | ||
Check failure on line 34 in webpack/scenes/SmartProxy/ExpandableCvDetails.js GitHub Actions / build
|
||
const { | ||
id, name: cvName, composite, last_published: lastPublished, up_to_date: upToDate, counts, | ||
Check failure on line 36 in webpack/scenes/SmartProxy/ExpandableCvDetails.js GitHub Actions / build
|
||
} = cv; | ||
const { repositories } = counts; | ||
const cvType = <ContentViewIcon composite={composite} />; | ||
const upToDateVal = upToDate ? <CheckCircleIcon /> : <TimesCircleIcon />; | ||
return ( | ||
<Tr key={cv.name}> | ||
<Td><a href={cv.default ? urlBuilder('products', '') : urlBuilder('content_views', '', id)}>{cvName}</a></Td> | ||
<Td><LongDateTime date={cv.last_published} showRelativeTimeTooltip /></Td> | ||
<Td>{repositories}</Td> | ||
<Td>{upToDateVal}</Td> | ||
</Tr> | ||
); | ||
})} | ||
</Tbody> | ||
</TableComposable> | ||
|
||
); | ||
}; | ||
|
||
export default ExpandableCvDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { omit } from 'lodash'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { TableVariant, Thead, Tbody, Th, Tr, Td, ExpandableRowContent } from '@patternfly/react-table'; | ||
import getSmartProxyContent from './SmartProxyContentActions'; | ||
import { | ||
selectSmartProxyContent, | ||
selectSmartProxyContentStatus, | ||
selectSmartProxyContentError, | ||
} from './SmartProxyContentSelectors'; | ||
import { useSet, useTableSort } from '../../components/Table/TableHooks'; | ||
import TableWrapper from '../../components/Table/TableWrapper'; | ||
import ExpandableCvDetails from './ExpandableCvDetails'; | ||
|
||
const SmartProxyExpandableTable = ({ smartProxyId }) => { | ||
const response = useSelector(selectSmartProxyContent); | ||
const status = useSelector(selectSmartProxyContentStatus); | ||
const error = useSelector(selectSmartProxyContentError); | ||
const [searchQuery, updateSearchQuery] = useState(''); | ||
const expandedTableRows = useSet([]); | ||
const tableRowIsExpanded = id => expandedTableRows.has(id); | ||
let metadata = {}; | ||
const { | ||
lifecycle_environments: results, | ||
} = response; | ||
if (results) { | ||
metadata = { total: results.length, subtotal: results.length }; | ||
} | ||
console.log(results); | ||
const columnHeaders = [ | ||
__('Environment'), | ||
]; | ||
const fetchItems = useCallback(() => getSmartProxyContent({ smartProxyId })); | ||
|
||
const emptyContentTitle = __('No content views yet'); | ||
const emptyContentBody = __('You currently have no content views to display'); | ||
const emptySearchTitle = __('No matching content views found'); | ||
const emptySearchBody = __('Try changing your search settings.'); | ||
const alwaysHideToolbar = true; | ||
const hidePagination = true; | ||
return ( | ||
<TableWrapper | ||
{...{ | ||
error, | ||
metadata, | ||
emptyContentTitle, | ||
emptyContentBody, | ||
emptySearchTitle, | ||
emptySearchBody, | ||
searchQuery, | ||
updateSearchQuery, | ||
fetchItems, | ||
alwaysHideToolbar, | ||
hidePagination, | ||
}} | ||
ouiaId="capsule-content-table" | ||
status={status} | ||
> | ||
<Thead> | ||
<Tr ouiaId="cvTableHeaderRow"> | ||
<Th key="expand-carat" /> | ||
{columnHeaders.map(col => ( | ||
<Th | ||
key={col} | ||
> | ||
{col} | ||
</Th> | ||
))} | ||
</Tr> | ||
</Thead> | ||
{ | ||
results?.map((env, rowIndex) => { | ||
const { name, id, content_views: contentViews } = env; | ||
const isExpanded = tableRowIsExpanded(id); | ||
return ( | ||
<Tbody isExpanded={isExpanded} key={id}> | ||
<Tr key={id} ouiaId={`EnvRow-${id}`}> | ||
<Td | ||
expand={{ | ||
rowIndex, | ||
isExpanded, | ||
onToggle: (_event, _rInx, isOpen) => | ||
expandedTableRows.onToggle(isOpen, id), | ||
}} | ||
/> | ||
<Td>{name}</Td> | ||
</Tr> | ||
<Tr key="child_row" ouiaId={`ContentViewTableRowChild-${id}`} isExpanded={isExpanded}> | ||
<Td colSpan={2}> | ||
<ExpandableCvDetails data={contentViews} /> | ||
</Td> | ||
</Tr> | ||
</Tbody> | ||
); | ||
}) | ||
} | ||
</TableWrapper > | ||
); | ||
}; | ||
|
||
export default SmartProxyExpandableTable; |