-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add column management to the custom list filter
- Loading branch information
1 parent
8d1dc2d
commit 79b3f1a
Showing
14 changed files
with
449 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
{ | ||
"viewportWidth": 1920, | ||
"viewportHeight": 1080, | ||
"defaultCommandTimeout": 40000, | ||
"fixturesFolder": false, | ||
"integrationFolder": "tests", | ||
"screenshotsFolder": "./gui-test-screenshots/screenshots/", | ||
"videosFolder": "./gui-test-screenshots/videos/", | ||
"video": true, | ||
"pluginsFile": "plugin.js", | ||
"reporter": "../node_modules/cypress-multi-reporters", | ||
"reporterOptions": { | ||
"configFile": "reporter-config.json" | ||
}, | ||
"retries": { | ||
"openMode": 0, | ||
"runMode": 1 | ||
}, | ||
"screenshotOnRunFailure": true, | ||
"screenshotsFolder": "./gui-test-screenshots/screenshots/", | ||
"supportFile": "support.ts", | ||
"pluginsFile": "plugin.js", | ||
"fixturesFolder": false, | ||
"defaultCommandTimeout": 30000, | ||
"retries": { | ||
"runMode": 1, | ||
"openMode": 0 | ||
} | ||
"video": true, | ||
"videosFolder": "./gui-test-screenshots/videos/", | ||
"viewportHeight": 1080, | ||
"viewportWidth": 1920 | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/utils/components/ColumnManagementModal/ColumnManagement.tsx
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,47 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { ColumnLayout } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { Button, ToolbarGroup, ToolbarItem, Tooltip } from '@patternfly/react-core'; | ||
import { ColumnsIcon } from '@patternfly/react-icons'; | ||
|
||
import { ColumnManagementModal } from '../ColumnManagementModal/ColumnManagementModal'; | ||
import { useModal } from '../ModalProvider/ModalProvider'; | ||
|
||
type ColumnManagementProps = { | ||
columnLayout: ColumnLayout; | ||
hideColumnManagement?: boolean; | ||
}; | ||
|
||
const ColumnManagement: FC<ColumnManagementProps> = ({ columnLayout, hideColumnManagement }) => { | ||
const { t } = useKubevirtTranslation(); | ||
const { createModal } = useModal(); | ||
|
||
if (isEmpty(columnLayout) || !columnLayout?.id || hideColumnManagement) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ToolbarGroup> | ||
<ToolbarItem> | ||
<Tooltip content={t('Manage columns')} trigger="mouseenter"> | ||
<Button | ||
onClick={() => | ||
createModal((props) => ( | ||
<ColumnManagementModal {...props} columnLayout={columnLayout} /> | ||
)) | ||
} | ||
aria-label={t('Column management')} | ||
data-test="manage-columns" | ||
variant="plain" | ||
> | ||
<ColumnsIcon /> | ||
</Button> | ||
</Tooltip> | ||
</ToolbarItem> | ||
</ToolbarGroup> | ||
); | ||
}; | ||
|
||
export default ColumnManagement; |
193 changes: 193 additions & 0 deletions
193
src/utils/components/ColumnManagementModal/ColumnManagementModal.tsx
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,193 @@ | ||
import React, { FC, MouseEventHandler, SyntheticEvent, useState } from 'react'; | ||
|
||
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import useKubevirtUserSettingsTableColumns from '@kubevirt-utils/hooks/useKubevirtUserSettings/useKubevirtUserSettingsTableColumns'; | ||
import { ColumnLayout } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { | ||
ActionList, | ||
ActionListItem, | ||
Alert, | ||
AlertVariant, | ||
Button, | ||
ButtonVariant, | ||
DataList, | ||
Form, | ||
Modal, | ||
ModalVariant, | ||
Stack, | ||
StackItem, | ||
} from '@patternfly/react-core'; | ||
|
||
import { MAX_VIEW_COLS } from './constants'; | ||
import DataListRow from './DataListRow'; | ||
import { createInputId, getColumnId } from './utils'; | ||
|
||
import './column-management-modal.scss'; | ||
|
||
type ColumnManagementModalProps = { | ||
columnLayout: ColumnLayout; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
export const ColumnManagementModal: FC<ColumnManagementModalProps> = ({ | ||
columnLayout, | ||
isOpen, | ||
onClose, | ||
}) => { | ||
const { t } = useKubevirtTranslation(); | ||
const { columns, id, selectedColumns, showNamespaceOverride, type } = columnLayout; | ||
|
||
const defaultColumns = columns.filter((column) => column.id && !column.additional); | ||
const additionalColumns = columns.filter((column) => column.additional); | ||
|
||
const [_, setActiveColumns, loaded, error] = useKubevirtUserSettingsTableColumns({ | ||
columnManagementID: id, | ||
columns, | ||
}); | ||
|
||
const [checkedColumns, setCheckedColumns] = useState<Set<string>>( | ||
selectedColumns && selectedColumns.size !== 0 | ||
? new Set(selectedColumns) | ||
: new Set(defaultColumns.map((col) => col.id)), | ||
); | ||
|
||
const onColumnChange = (checked: boolean, event: SyntheticEvent): void => { | ||
const updatedCheckedColumns = new Set<string>(checkedColumns); | ||
const selectedId = getColumnId(event?.currentTarget?.id); | ||
updatedCheckedColumns.has(selectedId) | ||
? updatedCheckedColumns.delete(selectedId) | ||
: updatedCheckedColumns.add(selectedId); | ||
setCheckedColumns(updatedCheckedColumns); | ||
}; | ||
|
||
const submit: MouseEventHandler<HTMLButtonElement> = async (event) => { | ||
event.preventDefault(); | ||
const orderedCheckedColumns = new Set<string>(); | ||
checkedColumns.forEach((ids) => orderedCheckedColumns.add(ids)); | ||
|
||
await setActiveColumns([...orderedCheckedColumns]); | ||
onClose(); | ||
}; | ||
|
||
const areMaxColumnsDisplayed = checkedColumns.size >= MAX_VIEW_COLS; | ||
|
||
const resetColumns = (event: SyntheticEvent): void => { | ||
event.preventDefault(); | ||
const updatedCheckedColumns = new Set(checkedColumns); | ||
defaultColumns.forEach((col) => col.id && updatedCheckedColumns.add(col.id)); | ||
additionalColumns.forEach((col) => updatedCheckedColumns.delete(col.id)); | ||
setCheckedColumns(updatedCheckedColumns); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
footer={ | ||
<Stack className="kv-tabmodal-footer" hasGutter> | ||
{error && ( | ||
<StackItem> | ||
<Alert isInline title={t('An error occurred')} variant={AlertVariant.danger}> | ||
<Stack hasGutter> | ||
<StackItem>{error.message}</StackItem> | ||
</Stack> | ||
</Alert> | ||
</StackItem> | ||
)} | ||
<StackItem> | ||
<ActionList className="column-management-modal__action-list"> | ||
<ActionListItem> | ||
<Button key="reset" onClick={resetColumns} variant={ButtonVariant.link}> | ||
{t('Restore default columns')} | ||
</Button> | ||
</ActionListItem> | ||
|
||
<ActionListItem> | ||
<Button onClick={onClose} variant={ButtonVariant.secondary}> | ||
{t('Cancel')} | ||
</Button> | ||
</ActionListItem> | ||
<ActionListItem> | ||
<Button | ||
form="modal-with-form-form" | ||
isDisabled={!loaded} | ||
isLoading={!loaded} | ||
key="create" | ||
onClick={submit} | ||
variant={ButtonVariant.primary} | ||
> | ||
{t('Save')} | ||
</Button> | ||
</ActionListItem> | ||
</ActionList> | ||
</StackItem> | ||
</Stack> | ||
} | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
position="top" | ||
title={t('Manage columns')} | ||
variant={ModalVariant.medium} | ||
> | ||
<Form className="modal-content" name="form"> | ||
<div> | ||
<p>{t('Selected columns will appear in the table.')}</p> | ||
</div> | ||
<div> | ||
<Alert | ||
className="co-alert" | ||
isInline | ||
title={t('You can select up to {{MAX_VIEW_COLS}} columns', { MAX_VIEW_COLS })} | ||
variant={AlertVariant.info} | ||
> | ||
{!showNamespaceOverride && | ||
t('The namespace column is only shown when in "All projects"')} | ||
</Alert> | ||
</div> | ||
<div className="row co-m-form-row"> | ||
<div className="col-sm-12"> | ||
<span className="col-sm-6"> | ||
<label className="control-label"> | ||
{t('Default {{resourceKind}} columns', { resourceKind: type })} | ||
</label> | ||
<DataList | ||
aria-label={t('Default column list')} | ||
id="defalt-column-management" | ||
isCompact | ||
> | ||
{defaultColumns.map((defaultColumn) => ( | ||
<DataListRow | ||
checkedColumns={checkedColumns} | ||
column={defaultColumn} | ||
disableUncheckedRow={areMaxColumnsDisplayed} | ||
inputId={createInputId(defaultColumn.id)} | ||
key={defaultColumn.id} | ||
onChange={onColumnChange} | ||
/> | ||
))} | ||
</DataList> | ||
</span> | ||
<span className="col-sm-6"> | ||
<label className="control-label">{t('Additional columns')}</label> | ||
<DataList | ||
aria-label={t('Additional column list')} | ||
id="additional-column-management" | ||
isCompact | ||
> | ||
{additionalColumns.map((additionalColumn) => ( | ||
<DataListRow | ||
checkedColumns={checkedColumns} | ||
column={additionalColumn} | ||
disableUncheckedRow={areMaxColumnsDisplayed} | ||
inputId={createInputId(additionalColumn.id)} | ||
key={additionalColumn.id} | ||
onChange={onColumnChange} | ||
/> | ||
))} | ||
</DataList> | ||
</span> | ||
</div> | ||
</div> | ||
</Form> | ||
</Modal> | ||
); | ||
}; |
Oops, something went wrong.