-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gowtham Shanmugasundaram <[email protected]>
- Loading branch information
1 parent
0a38fb8
commit 720c8dc
Showing
22 changed files
with
1,209 additions
and
29 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
23 changes: 23 additions & 0 deletions
23
packages/mco/components/modals/app-manage-data-policy/acm-action-callback.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,23 @@ | ||
import * as React from 'react'; | ||
import { referenceForModel } from '@odf/shared/utils'; | ||
import { ArgoApplicationSetModel } from '../../../models'; | ||
import { ArgoApplicationSetKind, ACMActionCallbackType } from '../../../types'; | ||
import { getGVKFromK8Resource } from '../../../utils'; | ||
import { ApplicationSetModal } from './parsers/application-set-parser'; | ||
|
||
export const AppManageDataPolicy = (props: ACMActionCallbackType) => { | ||
const { resource, close, isOpen } = props; | ||
const gvk = getGVKFromK8Resource(resource); | ||
|
||
return ( | ||
<> | ||
{gvk === referenceForModel(ArgoApplicationSetModel) && ( | ||
<ApplicationSetModal | ||
application={resource as ArgoApplicationSetKind} | ||
isOpen={isOpen} | ||
close={close} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
70 changes: 70 additions & 0 deletions
70
.../mco/components/modals/app-manage-data-policy/components/app-manage-data-policy-modal.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,70 @@ | ||
import * as React from 'react'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { Modal, ModalVariant } from '@patternfly/react-core'; | ||
import { ModalHeader } from './helpers/modal-header'; | ||
import { ModalListView } from './policy-list-view/modal-list-view'; | ||
import { | ||
ModalViewContext, | ||
managePolicyState, | ||
managePolicyStateReducer, | ||
} from './utils/reducer'; | ||
import { ApplicationType, DRPolicyType } from './utils/types'; | ||
|
||
export const AppManageDataPolicyModal: React.FC<AppManageDataPolicyModalType> = | ||
(props) => { | ||
const [state, dispatch] = React.useReducer( | ||
managePolicyStateReducer, | ||
managePolicyState() | ||
); | ||
const { applicaitonInfo, isOpen, close } = props; | ||
const { t } = useCustomTranslation(); | ||
|
||
const modalViewContext = () => { | ||
switch (state.modalViewContext) { | ||
case ModalViewContext.POLICY_LIST_VIEW: | ||
return ( | ||
<> | ||
<ModalHeader | ||
title={t('Manage Policy')} | ||
description={t( | ||
'Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.' | ||
)} | ||
/> | ||
<ModalListView | ||
dataPolicyInfo={applicaitonInfo?.dataPolicies} | ||
state={state} | ||
dispatch={dispatch} | ||
/> | ||
</> | ||
); | ||
case ModalViewContext.ASSIGN_POLICY_VIEW: | ||
return <>ASSIGN_POLICY_VIEW</>; | ||
case ModalViewContext.DISABLE_POLICY_VIEW: | ||
return <>DISABLE_POLICY_VIEW</>; | ||
default: | ||
return <>POLICY_LIST_VIEW</>; | ||
} | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Modal | ||
variant={ModalVariant.large} | ||
isOpen={isOpen} | ||
aria-label="Manage policy modal" | ||
aria-describedby="manage-policy-modal" | ||
onClose={close} | ||
hasNoBodyWrapper | ||
> | ||
{modalViewContext()} | ||
</Modal> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export type AppManageDataPolicyModalType = { | ||
applicaitonInfo: ApplicationType; | ||
matchingDRPolicies: DRPolicyType[]; | ||
isOpen: boolean; | ||
close?: () => void; | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/mco/components/modals/app-manage-data-policy/components/helpers/modal-header.scss
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,19 @@ | ||
.mco-modal-box__header { | ||
display: flex; | ||
flex-direction: column; | ||
flex-shrink: 0; | ||
padding-top: var(--pf-global--spacer--lg); | ||
padding-right: var(--pf-global--spacer--lg); | ||
padding-left: var(--pf-global--spacer--lg); | ||
} | ||
|
||
.mco-modal-box__description { | ||
padding-top: var(--pf-global--spacer--xs); | ||
} | ||
|
||
.mco-modal-box__title { | ||
flex: 0 0 auto; | ||
font-family: var(--pf-global--FontFamily--heading--sans-serif); | ||
font-size: var(--pf-global--FontSize--2xl); | ||
line-height: var(--pf-global--LineHeight--sm); | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/mco/components/modals/app-manage-data-policy/components/helpers/modal-header.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,29 @@ | ||
import * as React from 'react'; | ||
import './modal-header.scss'; | ||
|
||
export const ModalHeader: React.FC<ModalHeaderType> = (props) => { | ||
const { title, description } = props; | ||
|
||
return ( | ||
<div className="mco-modal-box__header"> | ||
<p | ||
className="mco-modal-box__title" | ||
aria-label={title} | ||
id={'manage-policy-title'} | ||
> | ||
{title} | ||
</p> | ||
<p | ||
className="mco-modal-box__description" | ||
id={'manage-policy-description'} | ||
> | ||
{description} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export type ModalHeaderType = { | ||
title: string; | ||
description?: string; | ||
}; |
146 changes: 146 additions & 0 deletions
146
...mco/components/modals/app-manage-data-policy/components/helpers/modal-list-view-table.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,146 @@ | ||
import * as React from 'react'; | ||
import { | ||
RowComponentType, | ||
SelectableTable, | ||
} from '@odf/shared/selectable-table/selectable-table'; | ||
import { TableRowType } from '@odf/shared/selectable-table/selectable-table'; | ||
import { | ||
GreenCheckCircleIcon, | ||
RedExclamationCircleIcon, | ||
} from '@odf/shared/status/icons'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { StatusIconAndText } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { TFunction } from 'i18next'; | ||
import { ActionsColumn, IAction } from '@patternfly/react-table'; | ||
import { Td } from '@patternfly/react-table'; | ||
import { formatDateTime } from '../../../../../utils'; | ||
import { | ||
ManagePolicyState, | ||
ManagePolicyStateAction, | ||
ManagePolicyStateType, | ||
ModalViewContext, | ||
} from '../utils/reducer'; | ||
import { DRPolicyType, DataPolicyType } from '../utils/types'; | ||
|
||
const filterRowBySearchText = ( | ||
rows: TableRowType<DRPolicyType>[], | ||
searchText | ||
) => | ||
!!searchText | ||
? rows?.filter((row) => row?.data?.drPolicyName?.includes(searchText)) | ||
: rows; | ||
|
||
const getRow = (dataPolicyInfo: DataPolicyType): TableRowType<DRPolicyType>[] => | ||
dataPolicyInfo?.drPolicyInfo?.map((policyInfo) => ({ | ||
data: policyInfo, | ||
rowId: policyInfo?.drPolicyName, | ||
isDisabled: false, | ||
})); | ||
|
||
const getColumns = (t: TFunction) => [ | ||
{ columName: t('Policy name'), sortField: 'drPolicyName', sortable: true }, | ||
{ columName: t('Policy type'), sortField: 'policyType', sortable: true }, | ||
{ columName: t('Status'), sortField: 'isValidated', sortable: true }, | ||
{ columName: t('Activity'), sortField: 'activity', sortable: true }, | ||
{ columName: t('Assigned on'), sortField: 'assignedOn', sortable: true }, | ||
{ columName: '' }, | ||
]; | ||
|
||
const getRange = (currentPage: number, perPage: number) => { | ||
const indexOfLastRow = currentPage * perPage; | ||
const indexOfFirstRow = indexOfLastRow - perPage; | ||
return [indexOfFirstRow, indexOfLastRow]; | ||
}; | ||
|
||
const ModalListViewRow: React.FC<RowComponentType<DRPolicyType>> = (props) => { | ||
const { t } = useCustomTranslation(); | ||
const { row, extraProps } = props || {}; | ||
const { data } = row || {}; | ||
const { dispatch }: RowExtraPropType = extraProps; | ||
|
||
const RowActions = (t: TFunction): IAction[] => [ | ||
{ | ||
title: t('View configurations'), | ||
onClick: () => {}, | ||
}, | ||
{ | ||
title: t('Unassign policy'), | ||
onClick: () => { | ||
dispatch({ | ||
type: ManagePolicyStateType.SET_SELECTED_ROW, | ||
payload: row, | ||
}); | ||
dispatch({ | ||
type: ManagePolicyStateType.SET_MODAL_VIEW_CONTEXT, | ||
payload: ModalViewContext.DISABLE_POLICY_VIEW, | ||
}); | ||
}, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<Td translate={null}>{data?.drPolicyName}</Td> | ||
<Td translate={null}>{data?.policyType}</Td> | ||
<Td translate={null}> | ||
{data?.isValidated ? ( | ||
<StatusIconAndText | ||
title={t('Validated')} | ||
icon={<GreenCheckCircleIcon />} | ||
/> | ||
) : ( | ||
<StatusIconAndText | ||
title={t('Not Validated')} | ||
icon={<RedExclamationCircleIcon />} | ||
/> | ||
)} | ||
</Td> | ||
<Td translate={null}>{data?.activity}</Td> | ||
<Td translate={null}>{formatDateTime(data?.assignedOn)}</Td> | ||
<Td translate={null}> | ||
<ActionsColumn items={RowActions(t)} isDisabled={false} /> | ||
</Td> | ||
</> | ||
); | ||
}; | ||
|
||
export const ModalListViewTable: React.FC<ModalListViewTableType> = (props) => { | ||
const { t } = useCustomTranslation(); | ||
const { currentPage, perPage, searchText, dataPolicyInfo, state, dispatch } = | ||
props; | ||
const [start, end] = getRange(currentPage, perPage); | ||
const rows = filterRowBySearchText(getRow(dataPolicyInfo), searchText); | ||
const paginatedRow = rows?.slice(start, end); | ||
|
||
const setSelectedRows = (selectedRows: TableRowType<DRPolicyType>[]) => | ||
dispatch({ | ||
type: ManagePolicyStateType.SET_SELECTED_ROWS, | ||
payload: selectedRows, | ||
}); | ||
|
||
return ( | ||
<SelectableTable<DRPolicyType> | ||
columns={getColumns(t)} | ||
rows={paginatedRow} | ||
RowComponent={ModalListViewRow} | ||
selectedRows={state.selectedRows} | ||
setSelectedRows={setSelectedRows} | ||
extraProps={{ | ||
dispatch: dispatch, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
type RowExtraPropType = { | ||
dispatch: React.Dispatch<ManagePolicyStateAction>; | ||
}; | ||
|
||
type ModalListViewTableType = RowExtraPropType & { | ||
currentPage: number; | ||
perPage: number; | ||
searchText: string; | ||
dataPolicyInfo: DataPolicyType; | ||
state: ManagePolicyState; | ||
dispatch: React.Dispatch<ManagePolicyStateAction>; | ||
}; |
17 changes: 17 additions & 0 deletions
17
...components/modals/app-manage-data-policy/components/policy-list-view/modal-list-view.scss
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,17 @@ | ||
.mco-modal-col-padding { | ||
padding: 0 3rem 0 1rem; | ||
} | ||
|
||
.mco-modal-box__body { | ||
flex: 1 1 auto; | ||
min-height: calc(var(--pf-global--FontSize--md) * var(--pf-global--LineHeight--md)); | ||
padding-top: var(--pf-global--spacer--lg); | ||
padding-right: var(--pf-global--spacer--lg); | ||
padding-left: var(--pf-global--spacer--lg); | ||
padding-bottom: var(--pf-global--spacer--lg); | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
overscroll-behavior: contain; | ||
word-break: break-word; | ||
-webkit-overflow-scrolling: touch; | ||
} |
Oops, something went wrong.