|
|
@ -1,10 +1,12 @@ |
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */ |
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */ |
|
|
|
import React, { Fragment, useCallback, useEffect, useState } from 'react' |
|
|
|
import React, { Fragment, useCallback, useEffect, useState } from 'react' |
|
|
|
import { PluginManagerSettings, PluginPermissions } from '../../../types/types' |
|
|
|
/* eslint-disable-line */ |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
|
|
|
|
import { useLocalStorage } from '../custom-hooks/useLocalStorage' |
|
|
|
|
|
|
|
// import { PluginManagerSettings, PluginPermissions } from '../../types'
|
|
|
|
|
|
|
|
|
|
|
|
interface PermissionSettingsProps { |
|
|
|
interface PermissionSettingsProps { |
|
|
|
pluginSettings: PluginManagerSettings |
|
|
|
pluginSettings: any |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
@ -12,28 +14,20 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
* Declare component local state |
|
|
|
* Declare component local state |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const [modalVisibility, setModalVisibility] = useState<boolean>(true) |
|
|
|
const [modalVisibility, setModalVisibility] = useState<boolean>(true) |
|
|
|
const [permissions] = useState<PluginPermissions | null>( |
|
|
|
// const [permissions] = useState<any | null>(
|
|
|
|
JSON.parse(localStorage.getItem('plugins/permissions') || '{}')) |
|
|
|
// JSON.parse(localStorage.getItem('plugins/permissions') || '{}'))
|
|
|
|
const [verifyPermission, setVerifyPermission] = useState(false) |
|
|
|
const [permissions, setPermissions] = useLocalStorage('plugins/permissions', '{}') |
|
|
|
const closeModal = () => setModalVisibility(true) |
|
|
|
const closeModal = () => setModalVisibility(true) |
|
|
|
|
|
|
|
|
|
|
|
const displayPermissions = useCallback(() => { |
|
|
|
|
|
|
|
if (permissions && Object.keys(permissions).length > 0) { |
|
|
|
|
|
|
|
setVerifyPermission(true) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [permissions]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
displayPermissions() |
|
|
|
|
|
|
|
}, [displayPermissions, permissions]) |
|
|
|
|
|
|
|
// console.log('fetched permissions', permissions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function ShowPluginHeading ({ headingName }) { |
|
|
|
function ShowPluginHeading ({ headingName }) { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="pb-2 remixui_permissionKey"> |
|
|
|
<div className="pb-2 remixui_permissionKey"> |
|
|
|
<h3>{headingName} permissions:</h3> |
|
|
|
<h3>{headingName} permissions:</h3> |
|
|
|
<i |
|
|
|
<i |
|
|
|
onClick={() => pluginSettings.clearAllPersmission('topLevelPluginNameP')} |
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
console.log(`${headingName}`) |
|
|
|
|
|
|
|
clearPersmission(headingName) |
|
|
|
|
|
|
|
}} |
|
|
|
className="far fa-trash-alt" |
|
|
|
className="far fa-trash-alt" |
|
|
|
data-id={`pluginManagerSettingsClearAllPermission-${headingName}`}> |
|
|
|
data-id={`pluginManagerSettingsClearAllPermission-${headingName}`}> |
|
|
|
|
|
|
|
|
|
|
@ -55,7 +49,10 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
}, [checkBoxState]) |
|
|
|
}, [checkBoxState]) |
|
|
|
|
|
|
|
|
|
|
|
const handleCheckboxClick = () => { |
|
|
|
const handleCheckboxClick = () => { |
|
|
|
|
|
|
|
const copyPermissions = permissions |
|
|
|
|
|
|
|
copyPermissions[pluginName][functionName][topLevelPluginName].allow = !checkBoxState |
|
|
|
setCheckBoxState(!checkBoxState) |
|
|
|
setCheckBoxState(!checkBoxState) |
|
|
|
|
|
|
|
setPermissions(copyPermissions) |
|
|
|
} |
|
|
|
} |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="form-group remixui_permissionKey"> |
|
|
|
<div className="form-group remixui_permissionKey"> |
|
|
@ -78,7 +75,10 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
</span> |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<i |
|
|
|
<i |
|
|
|
onClick={() => pluginSettings.clearPersmission(pluginName, topLevelPluginName, functionName)} |
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
console.log(`${pluginName}'s trash icon was clicked!`) |
|
|
|
|
|
|
|
clearAllPersmissions(pluginName, topLevelPluginName, functionName) |
|
|
|
|
|
|
|
}} |
|
|
|
className="fa fa-trash-alt" |
|
|
|
className="fa fa-trash-alt" |
|
|
|
data-id={`pluginManagerSettingsRemovePermission-${topLevelPluginName}-${functionName}-${topLevelPluginName}`} |
|
|
|
data-id={`pluginManagerSettingsRemovePermission-${topLevelPluginName}-${functionName}-${topLevelPluginName}`} |
|
|
|
/> |
|
|
|
/> |
|
|
@ -86,6 +86,30 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clearAllPersmissions (pluginName: string, topLevelPluginName: string, funcName: string) { |
|
|
|
|
|
|
|
const permissionsCopy = permissions // don't mutate state
|
|
|
|
|
|
|
|
if (permissionsCopy[topLevelPluginName] && permissionsCopy[topLevelPluginName][funcName]) { |
|
|
|
|
|
|
|
delete permissionsCopy[topLevelPluginName][funcName][pluginName] |
|
|
|
|
|
|
|
if (Object.keys(permissionsCopy[topLevelPluginName][funcName]).length === 0) { |
|
|
|
|
|
|
|
delete permissionsCopy[topLevelPluginName][funcName] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (Object.keys(permissionsCopy[topLevelPluginName]).length === 0) { |
|
|
|
|
|
|
|
delete permissionsCopy[topLevelPluginName] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line no-debugger
|
|
|
|
|
|
|
|
debugger |
|
|
|
|
|
|
|
setPermissions({ ...permissionsCopy }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clearPersmission (topLevelPluginName: string) { |
|
|
|
|
|
|
|
const permissionsCopy = permissions |
|
|
|
|
|
|
|
if (permissionsCopy[topLevelPluginName]) { |
|
|
|
|
|
|
|
delete permissionsCopy[topLevelPluginName] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setPermissions({}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Fragment> |
|
|
|
<Fragment> |
|
|
|
<ModalDialog |
|
|
|
<ModalDialog |
|
|
@ -95,20 +119,23 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) { |
|
|
|
okLabel="OK" |
|
|
|
okLabel="OK" |
|
|
|
cancelLabel="Cancel" |
|
|
|
cancelLabel="Cancel" |
|
|
|
> |
|
|
|
> |
|
|
|
{verifyPermission ? (<h4 className="text-center">Current Permission Settings</h4>) : (<h4 className="text-center">No Permission requested yet.</h4>)} |
|
|
|
{JSON.parse(localStorage.getItem('plugins/permissions')) && Object.keys(JSON.parse(localStorage.getItem('plugins/permissions'))).length > 0 |
|
|
|
|
|
|
|
? (<h4 className="text-center">Current Permission Settings</h4>) |
|
|
|
|
|
|
|
: (<h4 className="text-center">No Permission requested yet.</h4>) |
|
|
|
|
|
|
|
} |
|
|
|
<form className="remixui_permissionForm" data-id="pluginManagerSettingsPermissionForm"> |
|
|
|
<form className="remixui_permissionForm" data-id="pluginManagerSettingsPermissionForm"> |
|
|
|
<div className="p-2"> |
|
|
|
<div className="p-2"> |
|
|
|
{ |
|
|
|
{ |
|
|
|
Object.keys(permissions).map(toplevelName => ( |
|
|
|
Object.keys(JSON.parse(localStorage.getItem('plugins/permissions'))).map(toplevelName => ( |
|
|
|
<ShowPluginHeading key={toplevelName} headingName={toplevelName} /> |
|
|
|
<ShowPluginHeading key={toplevelName} headingName={toplevelName} /> |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
Object.keys(permissions).map(topName => { |
|
|
|
Object.keys(JSON.parse(localStorage.getItem('plugins/permissions'))).map(topName => { |
|
|
|
return Object.keys(permissions[topName]).map(funcName => { |
|
|
|
return Object.keys(JSON.parse(localStorage.getItem('plugins/permissions'))[topName]).map(funcName => { |
|
|
|
return Object.keys(permissions[topName][funcName]).map(pluginName => ( |
|
|
|
return Object.keys(JSON.parse(localStorage.getItem('plugins/permissions'))[topName][funcName]).map(pluginName => ( |
|
|
|
<ShowCheckBox |
|
|
|
<ShowCheckBox |
|
|
|
allow={permissions[topName][funcName][pluginName].allow} |
|
|
|
allow={JSON.parse(localStorage.getItem('plugins/permissions'))[topName][funcName][pluginName].allow} |
|
|
|
functionName={funcName} |
|
|
|
functionName={funcName} |
|
|
|
pluginName={pluginName} |
|
|
|
pluginName={pluginName} |
|
|
|
topLevelPluginName={topName} |
|
|
|
topLevelPluginName={topName} |