({ show, dialogProps, onCancel, onConfirm, setError })
| 41 | import './APIKeyDialog.css' |
| 42 | |
| 43 | const APIKeyDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) => { |
| 44 | const portalElement = document.getElementById('portal') |
| 45 | |
| 46 | const theme = useTheme() |
| 47 | const dispatch = useDispatch() |
| 48 | const { isOpenSource, isEnterpriseLicensed, isCloud } = useConfig() |
| 49 | |
| 50 | // ==============================|| Snackbar ||============================== // |
| 51 | |
| 52 | useNotifier() |
| 53 | |
| 54 | const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) |
| 55 | const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) |
| 56 | |
| 57 | const [keyName, setKeyName] = useState('') |
| 58 | const [anchorEl, setAnchorEl] = useState(null) |
| 59 | const openPopOver = Boolean(anchorEl) |
| 60 | const [selectedPermissions, setSelectedPermissions] = useState({}) |
| 61 | const [permissions, setPermissions] = useState({}) |
| 62 | |
| 63 | const getAllPermissionsApi = useApi(authApi.getAllPermissions) |
| 64 | |
| 65 | useEffect(() => { |
| 66 | if (dialogProps.type === 'EDIT' && dialogProps.key) { |
| 67 | setKeyName(dialogProps.key.keyName) |
| 68 | } else if (dialogProps.type === 'ADD') { |
| 69 | setKeyName('') |
| 70 | } |
| 71 | getAllPermissionsApi.request('API_KEY') |
| 72 | return () => { |
| 73 | setSelectedPermissions({}) |
| 74 | } |
| 75 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 76 | }, [dialogProps]) |
| 77 | |
| 78 | useEffect(() => { |
| 79 | if (getAllPermissionsApi.error) { |
| 80 | if (setError) setError(getAllPermissionsApi.error) |
| 81 | } |
| 82 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 83 | }, [getAllPermissionsApi.error]) |
| 84 | |
| 85 | useEffect(() => { |
| 86 | if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) |
| 87 | else dispatch({ type: HIDE_CANVAS_DIALOG }) |
| 88 | return () => dispatch({ type: HIDE_CANVAS_DIALOG }) |
| 89 | }, [show, dispatch]) |
| 90 | |
| 91 | useEffect(() => { |
| 92 | if (getAllPermissionsApi.data) { |
| 93 | const permissionsData = getAllPermissionsApi.data |
| 94 | |
| 95 | // Filter permissions based on current platform |
| 96 | Object.keys(permissionsData).forEach((category) => { |
| 97 | permissionsData[category] = permissionsData[category].filter((permission) => { |
| 98 | if (isOpenSource) return permission.isOpenSource |
| 99 | if (isEnterpriseLicensed) return permission.isEnterprise |
| 100 | if (isCloud) return permission.isCloud |
nothing calls this directly
no test coverage detected