-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dispaly-warning-policy-apiserver-workloads-res
- Loading branch information
1 parent
a7a48f3
commit 7e80de2
Showing
13 changed files
with
167 additions
and
89 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...le-app/src/components/admission-webhook-warnings/AdmissionWebhookWarningNotifications.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,55 @@ | ||
import * as React from 'react'; | ||
import { AlertVariant } from '@patternfly/react-core'; | ||
import { useTranslation } from 'react-i18next'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore-next-line | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { | ||
AdmissionWebhookWarning, | ||
CoreState, | ||
getAdmissionWebhookWarnings, | ||
removeAdmissionWebhookWarning, | ||
} from '@console/dynamic-plugin-sdk/src'; | ||
import { documentationURLs, getDocumentationURL } from '@console/internal/components/utils'; | ||
import { useToast } from '@console/shared/src'; | ||
|
||
type UseAdmissionWebhookWarnings = () => Map<string, AdmissionWebhookWarning>; | ||
const useAdmissionWebhookWarnings: UseAdmissionWebhookWarnings = () => | ||
useSelector<CoreState, Map<string, AdmissionWebhookWarning>>(getAdmissionWebhookWarnings); | ||
|
||
export const AdmissionWebhookWarningNotifications = () => { | ||
const { t } = useTranslation(); | ||
const toastContext = useToast(); | ||
const dispatch = useDispatch(); | ||
const admissionWebhookWarnings = useAdmissionWebhookWarnings(); | ||
React.useEffect(() => { | ||
const docURL = getDocumentationURL(documentationURLs.admissionWebhookWarning); | ||
admissionWebhookWarnings.forEach((warning, id) => { | ||
toastContext.addToast({ | ||
variant: AlertVariant.warning, | ||
title: t('public~Admission Webhook Warning'), | ||
content: t(`{{kind}} {{name}} violates policy {{warning}}`, { | ||
kind: warning.kind, | ||
name: warning.name, | ||
warning: warning.warning, | ||
}), | ||
actions: [ | ||
{ | ||
dismiss: true, | ||
label: t('public~Learn more'), | ||
callback: () => { | ||
window.open(docURL, '_blank'); | ||
}, | ||
component: 'a', | ||
dataTest: 'admission-webhook-warning-learn-more', | ||
}, | ||
], | ||
timeout: true, | ||
dismissible: true, | ||
}); | ||
dispatch(removeAdmissionWebhookWarning(id)); | ||
}); | ||
}, [dispatch, admissionWebhookWarnings, t, toastContext]); | ||
|
||
return null; | ||
}; |
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
10 changes: 9 additions & 1 deletion
10
frontend/packages/console-dynamic-plugin-sdk/src/app/core/actions/core.ts
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,22 +1,30 @@ | ||
import { action, ActionType as Action } from 'typesafe-actions'; | ||
import { UserInfo } from '../../../extensions'; | ||
import { AdmissionWebhookWarning } from '../../redux-types'; | ||
|
||
export enum ActionType { | ||
SetUser = 'setUser', | ||
BeginImpersonate = 'beginImpersonate', | ||
EndImpersonate = 'endImpersonate', | ||
SetActiveCluster = 'setActiveCluster', | ||
SetAdmissionWebhookWarning = 'setAdmissionWebhookWarning', | ||
RemoveAdmissionWebhookWarning = 'removeAdmissionWebhookWarning', | ||
} | ||
|
||
export const setUser = (userInfo: UserInfo) => action(ActionType.SetUser, { userInfo }); | ||
export const beginImpersonate = (kind: string, name: string, subprotocols: string[]) => | ||
action(ActionType.BeginImpersonate, { kind, name, subprotocols }); | ||
export const endImpersonate = () => action(ActionType.EndImpersonate); | ||
|
||
export const setAdmissionWebhookWarning = (id: string, warning: AdmissionWebhookWarning) => | ||
action(ActionType.SetAdmissionWebhookWarning, { id, warning }); | ||
export const removeAdmissionWebhookWarning = (id) => | ||
action(ActionType.RemoveAdmissionWebhookWarning, { id }); | ||
const coreActions = { | ||
setUser, | ||
beginImpersonate, | ||
endImpersonate, | ||
setAdmissionWebhookWarning, | ||
removeAdmissionWebhookWarning, | ||
}; | ||
|
||
export type CoreAction = Action<typeof coreActions>; |
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
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
Oops, something went wrong.