-
Notifications
You must be signed in to change notification settings - Fork 664
CONSOLE-4772: Update list pages to use DataView in Workloads Tab #15653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
frontend/packages/console-app/src/components/pdb/AvailabilityDisplay.tsx
This file contains hidden or 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,35 @@ | ||
| import * as React from 'react'; | ||
| import * as _ from 'lodash'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { DASH } from '@console/shared/src/constants/ui'; | ||
| import { PodDisruptionBudgetKind } from './types'; | ||
|
|
||
| const AvailabilityDisplay: React.FC<AvailabilityDisplayProps> = ({ pdb }) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| if (_.isNil(pdb.spec.maxUnavailable) && _.isNil(pdb.spec.minAvailable)) { | ||
| return <>{DASH}</>; | ||
| } | ||
|
|
||
| if (_.isNil(pdb.spec.maxUnavailable)) { | ||
| return ( | ||
| <> | ||
| {t('console-app~Min available {{minAvailable}}', { minAvailable: pdb.spec.minAvailable })} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {t('console-app~Max unavailable {{maxUnavailable}}', { | ||
| maxUnavailable: pdb.spec.maxUnavailable, | ||
| })} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| type AvailabilityDisplayProps = { | ||
| pdb: PodDisruptionBudgetKind; | ||
| }; | ||
|
|
||
| export default AvailabilityDisplay; |
28 changes: 28 additions & 0 deletions
28
frontend/packages/console-app/src/components/pdb/DisruptionsAllowed.tsx
This file contains hidden or 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,28 @@ | ||
| import * as React from 'react'; | ||
| import { Tooltip } from '@patternfly/react-core'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { YellowExclamationTriangleIcon } from '@console/dynamic-plugin-sdk'; | ||
| import { PodDisruptionBudgetKind } from './types'; | ||
| import { isDisruptionViolated } from './utils/get-pdb-resources'; | ||
|
|
||
| const DisruptionsAllowed: React.FC<DisruptionsAllowedProps> = ({ pdb }) => { | ||
| const { t } = useTranslation(); | ||
| const isPDBViolated = isDisruptionViolated(pdb); | ||
|
|
||
| return ( | ||
| <> | ||
| {pdb.status.disruptionsAllowed}{' '} | ||
| {isPDBViolated && ( | ||
| <Tooltip content={t('console-app~Disruption not allowed')}> | ||
| <YellowExclamationTriangleIcon /> | ||
| </Tooltip> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| type DisruptionsAllowedProps = { | ||
| pdb: PodDisruptionBudgetKind; | ||
| }; | ||
|
|
||
| export default DisruptionsAllowed; |
170 changes: 155 additions & 15 deletions
170
frontend/packages/console-app/src/components/pdb/PDBList.tsx
This file contains hidden or 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,31 +1,171 @@ | ||
| import * as React from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { useActiveColumns } from '@console/internal/components/factory/Table/active-columns-hook'; | ||
| import VirtualizedTable from '@console/internal/components/factory/Table/VirtualizedTable'; | ||
| import { getPDBTableColumns } from './pdb-table-columns'; | ||
| import PodDisruptionBudgetTableRow from './PDBTableRow'; | ||
| import { | ||
| actionsCellProps, | ||
| cellIsStickyProps, | ||
| getNameCellProps, | ||
| initialFiltersDefault, | ||
| ConsoleDataView, | ||
| } from '@console/app/src/components/data-view/ConsoleDataView'; | ||
| import { GetDataViewRows } from '@console/app/src/components/data-view/types'; | ||
| import { TableColumn } from '@console/dynamic-plugin-sdk/src/extensions/console-types'; | ||
| import { ResourceLink, Selector } from '@console/internal/components/utils'; | ||
| import { LoadingBox } from '@console/internal/components/utils/status-box'; | ||
| import { referenceForModel } from '@console/internal/module/k8s'; | ||
| import LazyActionMenu from '@console/shared/src/components/actions/LazyActionMenu'; | ||
| import { Timestamp } from '@console/shared/src/components/datetime/Timestamp'; | ||
| import { DASH } from '@console/shared/src/constants/ui'; | ||
| import { PodDisruptionBudgetModel } from '../../models'; | ||
| import AvailabilityDisplay from './AvailabilityDisplay'; | ||
| import DisruptionsAllowed from './DisruptionsAllowed'; | ||
| import { PodDisruptionBudgetKind } from './types'; | ||
|
|
||
| const PodDisruptionBudgetList: React.FC<PodDisruptionBudgetsListProps> = (props) => { | ||
| export const tableColumnInfo = [ | ||
| { id: 'name' }, | ||
| { id: 'namespace' }, | ||
| { id: 'selector' }, | ||
| { id: 'minAvailable' }, | ||
| { id: 'disruptionsAllowed' }, | ||
| { id: 'creationTimestamp' }, | ||
| { id: '' }, | ||
| ]; | ||
|
|
||
| const getDataViewRows: GetDataViewRows<PodDisruptionBudgetKind, undefined> = (data, columns) => { | ||
| return data.map(({ obj: pdb }) => { | ||
| const { name, namespace } = pdb.metadata; | ||
| const resourceKind = referenceForModel(PodDisruptionBudgetModel); | ||
| const context = { [resourceKind]: pdb }; | ||
|
|
||
| const rowCells = { | ||
| [tableColumnInfo[0].id]: { | ||
| cell: <ResourceLink kind={resourceKind} name={name} namespace={namespace} />, | ||
| props: getNameCellProps(name), | ||
| }, | ||
| [tableColumnInfo[1].id]: { | ||
| cell: <ResourceLink kind="Namespace" name={namespace} />, | ||
| }, | ||
| [tableColumnInfo[2].id]: { | ||
| cell: <Selector selector={pdb.spec.selector} namespace={namespace} />, | ||
| }, | ||
| [tableColumnInfo[3].id]: { | ||
| cell: <AvailabilityDisplay pdb={pdb} />, | ||
| }, | ||
| [tableColumnInfo[4].id]: { | ||
| cell: <DisruptionsAllowed pdb={pdb} />, | ||
| }, | ||
| [tableColumnInfo[5].id]: { | ||
| cell: <Timestamp timestamp={pdb.metadata.creationTimestamp} />, | ||
| }, | ||
| [tableColumnInfo[6].id]: { | ||
| cell: <LazyActionMenu context={context} />, | ||
| props: actionsCellProps, | ||
| }, | ||
| }; | ||
|
|
||
| return columns.map(({ id }) => { | ||
| const cell = rowCells[id]?.cell || DASH; | ||
| return { | ||
| id, | ||
| props: rowCells[id]?.props, | ||
| cell, | ||
| }; | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => { | ||
| const { t } = useTranslation(); | ||
| const [columns] = useActiveColumns({ columns: getPDBTableColumns() }); | ||
| const columns = React.useMemo(() => { | ||
| return [ | ||
| { | ||
| title: t('console-app~Name'), | ||
| id: tableColumnInfo[0].id, | ||
| sort: 'metadata.name', | ||
| props: { | ||
| ...cellIsStickyProps, | ||
| modifier: 'nowrap', | ||
| }, | ||
| }, | ||
| { | ||
| title: t('console-app~Namespace'), | ||
| id: tableColumnInfo[1].id, | ||
| sort: 'metadata.namespace', | ||
| props: { | ||
| modifier: 'nowrap', | ||
| }, | ||
| }, | ||
| { | ||
| title: t('console-app~Selector'), | ||
| id: tableColumnInfo[2].id, | ||
| sort: 'spec.selector', | ||
| props: { | ||
| modifier: 'nowrap', | ||
| width: 20, | ||
| }, | ||
| }, | ||
| { | ||
| title: t('console-app~Availability'), | ||
| id: tableColumnInfo[3].id, | ||
| sort: 'spec.minAvailable', | ||
| props: { | ||
| modifier: 'nowrap', | ||
| }, | ||
| }, | ||
| { | ||
| title: t('console-app~Allowed disruptions'), | ||
| id: tableColumnInfo[4].id, | ||
| sort: 'status.disruptionsAllowed', | ||
| props: { | ||
| modifier: 'nowrap', | ||
| }, | ||
| }, | ||
| { | ||
| title: t('console-app~Created'), | ||
| id: tableColumnInfo[5].id, | ||
| sort: 'metadata.creationTimestamp', | ||
| props: { | ||
| modifier: 'nowrap', | ||
| }, | ||
| }, | ||
| { | ||
| title: '', | ||
| id: tableColumnInfo[6].id, | ||
| props: { | ||
| ...cellIsStickyProps, | ||
| }, | ||
| }, | ||
| ]; | ||
| }, [t]); | ||
| return columns; | ||
| }; | ||
|
|
||
| const PodDisruptionBudgetList: React.FCC<PodDisruptionBudgetsListProps> = ({ | ||
| data, | ||
| loaded, | ||
| ...props | ||
| }) => { | ||
| const columns = usePDBColumns(); | ||
|
|
||
| return ( | ||
| <VirtualizedTable<PodDisruptionBudgetKind> | ||
| {...props} | ||
| aria-label={t('console-app~PodDisruptionBudgets')} | ||
| label={t('console-app~PodDisruptionBudgets')} | ||
| columns={columns} | ||
| Row={PodDisruptionBudgetTableRow} | ||
| /> | ||
| <React.Suspense fallback={<LoadingBox />}> | ||
| <ConsoleDataView<PodDisruptionBudgetKind> | ||
| {...props} | ||
| label={PodDisruptionBudgetModel.labelPlural} | ||
| data={data} | ||
| loaded={loaded} | ||
| columns={columns} | ||
| initialFilters={initialFiltersDefault} | ||
| getDataViewRows={getDataViewRows} | ||
| hideColumnManagement | ||
| /> | ||
| </React.Suspense> | ||
| ); | ||
| }; | ||
|
|
||
| export default PodDisruptionBudgetList; | ||
|
|
||
| type PodDisruptionBudgetsListProps = { | ||
| data: PodDisruptionBudgetKind[]; | ||
| unfilteredData: PodDisruptionBudgetKind[]; | ||
| loaded: boolean; | ||
| loadError: any; | ||
| loadError?: any; | ||
| }; | ||
This file contains hidden or 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
66 changes: 0 additions & 66 deletions
66
frontend/packages/console-app/src/components/pdb/PDBTableRow.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.