|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import { FormControlLabel, Switch } from '@mui/material'; |
| 18 | +import React from 'react'; |
17 | 19 | import { useTranslation } from 'react-i18next'; |
18 | 20 | import Secret from '../../lib/k8s/secret'; |
| 21 | +import { useNamespaces } from '../../redux/filterSlice'; |
| 22 | +import { CreateResourceButton } from '../common'; |
19 | 23 | import ResourceListView from '../common/Resource/ResourceListView'; |
20 | 24 |
|
21 | 25 | export default function SecretList() { |
| 26 | + const SECRET_LIST_HELM_SECRET_HIDE_STORAGE_KEY = 'SECRET_LIST_HELM_SECRET_HIDE_STORAGE_KEY'; |
| 27 | + const SECRET_LIST_HELM_SECRET_HIDE_DEFAULT = true; |
22 | 28 | const { t } = useTranslation(['glossary', 'translation']); |
| 29 | + const storedHideHelm = localStorage.getItem(SECRET_LIST_HELM_SECRET_HIDE_STORAGE_KEY); |
| 30 | + const [hideHelm, setHideHelm] = React.useState<boolean>( |
| 31 | + JSON.parse(storedHideHelm || SECRET_LIST_HELM_SECRET_HIDE_DEFAULT.toString()) |
| 32 | + ); |
| 33 | + |
| 34 | + const [secrets, error] = Secret.useList({ namespace: useNamespaces() }); |
| 35 | + |
| 36 | + const filteredSecrets = React.useMemo(() => { |
| 37 | + if (!secrets) { |
| 38 | + return null; |
| 39 | + } |
| 40 | + return hideHelm ? secrets.filter(secret => secret.type !== 'helm.sh/release.v1') : secrets; |
| 41 | + }, [secrets, hideHelm]); |
23 | 42 |
|
24 | 43 | return ( |
25 | 44 | <ResourceListView |
| 45 | + id="headlamp-secrets" |
26 | 46 | title={t('Secrets')} |
27 | | - resourceClass={Secret} |
| 47 | + data={filteredSecrets} |
| 48 | + errorMessage={Secret.getErrorMessage(error)} |
| 49 | + headerProps={{ |
| 50 | + noNamespaceFilter: false, |
| 51 | + titleSideActions: [ |
| 52 | + <CreateResourceButton key="create-button" resourceClass={Secret} />, |
| 53 | + <FormControlLabel |
| 54 | + key="helm-switch" |
| 55 | + checked={hideHelm} |
| 56 | + control={ |
| 57 | + <Switch |
| 58 | + checked={hideHelm} |
| 59 | + onChange={(e, checked) => { |
| 60 | + localStorage.setItem( |
| 61 | + SECRET_LIST_HELM_SECRET_HIDE_STORAGE_KEY, |
| 62 | + checked.toString() |
| 63 | + ); |
| 64 | + setHideHelm(checked); |
| 65 | + }} |
| 66 | + color="primary" |
| 67 | + /> |
| 68 | + } |
| 69 | + label={t('translation|Hide Helm Secrets')} |
| 70 | + sx={{ marginLeft: '0.5rem' }} |
| 71 | + />, |
| 72 | + ], |
| 73 | + }} |
28 | 74 | columns={[ |
29 | 75 | 'name', |
30 | 76 | 'namespace', |
|
0 commit comments