-
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
6 changed files
with
193 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
<%= javascript_include_tag *webpack_asset_paths('katello', extension: 'js') %> | ||
|
||
<br /> | ||
<% @smartProxyId= @smart_proxy.id %> | ||
<%= react_component('Content', smartProxyId: @smartProxyId,) %> |
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,71 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
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 = ({ contentViews }) => { | ||
const columnHeaders = [ | ||
__('Content view'), | ||
__('Last published'), | ||
__('Repositories'), | ||
__('Synced to smart proxy'), | ||
]; | ||
|
||
return ( | ||
<TableComposable | ||
variant={TableVariant.compact} | ||
aria-label="expandable-content-views" | ||
ouiaId="expandable-content-views" | ||
> | ||
<Thead> | ||
<Tr ouiaId="column-headers"> | ||
{columnHeaders.map(col => ( | ||
<Th | ||
modifier="fitContent" | ||
key={col} | ||
> | ||
{col} | ||
</Th> | ||
))} | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{contentViews.map((cv) => { | ||
const { | ||
id, name: cvName, composite, up_to_date: upToDate, counts, | ||
} = cv; | ||
const { repositories } = counts; | ||
const upToDateVal = upToDate ? <CheckCircleIcon /> : <TimesCircleIcon />; | ||
return ( | ||
<Tr key={cv.name} ouiaId={cv.name}> | ||
<Td> | ||
<ContentViewIcon | ||
composite={composite} | ||
description={<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> | ||
|
||
); | ||
}; | ||
|
||
ExpandableCvDetails.propTypes = { | ||
contentViews: PropTypes.arrayOf(PropTypes.shape({})), | ||
}; | ||
|
||
ExpandableCvDetails.defaultProps = { | ||
contentViews: [], | ||
}; | ||
|
||
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,109 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { Thead, Tbody, Th, Tr, Td } from '@patternfly/react-table'; | ||
import getSmartProxyContent from './SmartProxyContentActions'; | ||
import { | ||
selectSmartProxyContent, | ||
selectSmartProxyContentStatus, | ||
selectSmartProxyContentError, | ||
} from './SmartProxyContentSelectors'; | ||
import { useSet } 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 }; | ||
} | ||
const columnHeaders = [ | ||
__('Environment'), | ||
]; | ||
const fetchItems = useCallback(() => getSmartProxyContent({ smartProxyId }), [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" | ||
autocompleteEndpoint="" | ||
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 contentViews={contentViews} /> | ||
</Td> | ||
</Tr> | ||
</Tbody> | ||
); | ||
}) | ||
} | ||
</TableWrapper > | ||
); | ||
}; | ||
|
||
SmartProxyExpandableTable.propTypes = { | ||
smartProxyId: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.string, // The API can sometimes return strings | ||
]).isRequired, | ||
}; | ||
|
||
export default SmartProxyExpandableTable; |
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