-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist dismissed callouts to localStorage
- Loading branch information
Showing
7 changed files
with
171 additions
and
53 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
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/security_solution/public/cases/components/callout/callout.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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiCallOut, EuiButton, EuiDescriptionList } from '@elastic/eui'; | ||
import { isEmpty } from 'lodash/fp'; | ||
import React, { memo, useCallback } from 'react'; | ||
|
||
import { ErrorMessage } from './types'; | ||
import * as i18n from './translations'; | ||
|
||
interface CallOutProps { | ||
id: string; | ||
type: NonNullable<ErrorMessage['errorType']>; | ||
title: string; | ||
messages: ErrorMessage[]; | ||
showCallOut: boolean; | ||
handleDismissCallout: (id: string) => void; | ||
} | ||
|
||
const CallOutComponent = ({ | ||
id, | ||
type, | ||
title, | ||
messages, | ||
showCallOut, | ||
handleDismissCallout, | ||
}: CallOutProps) => { | ||
const handleCallOut = useCallback(() => handleDismissCallout(id), [handleDismissCallout]); | ||
|
||
return showCallOut ? ( | ||
<EuiCallOut title={title} color={type} iconType="gear" data-test-subj={`case-call-out-${type}`}> | ||
{!isEmpty(messages) && ( | ||
<EuiDescriptionList data-test-subj={`callout-messages-${type}`} listItems={messages} /> | ||
)} | ||
<EuiButton | ||
data-test-subj={`callout-dismiss-${type}`} | ||
color={type === 'success' ? 'secondary' : type} | ||
onClick={handleCallOut} | ||
> | ||
{i18n.DISMISS_CALLOUT} | ||
</EuiButton> | ||
</EuiCallOut> | ||
) : null; | ||
}; | ||
|
||
export const CallOut = memo(CallOutComponent); |
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
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/security_solution/public/cases/components/callout/types.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface ErrorMessage { | ||
id: string; | ||
title: string; | ||
description: JSX.Element; | ||
errorType?: 'primary' | 'success' | 'warning' | 'danger'; | ||
} |
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
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/security_solution/public/common/containers/use_local_storage.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,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useCallback } from 'react'; | ||
import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; | ||
|
||
interface UseSecurityLocalStorage { | ||
getCallouts: (plugin: string) => string[]; | ||
persistDismissCallout: (plugin: string, id: string) => void; | ||
} | ||
|
||
export const useSecurityLocalStorage = (): UseSecurityLocalStorage => { | ||
const storage = new Storage(localStorage); | ||
|
||
const getCallouts = useCallback((plugin: string): string[] => { | ||
return storage.get(plugin)?.callouts ?? []; | ||
}, []); | ||
|
||
const persistDismissCallout = useCallback((plugin: string, id: string) => { | ||
const pluginStorage = storage.get(plugin) ?? { callouts: [] }; | ||
storage.set(plugin, { ...pluginStorage, callouts: [...pluginStorage.callouts, id] }); | ||
}, []); | ||
|
||
return { | ||
persistDismissCallout, | ||
getCallouts, | ||
}; | ||
}; |