-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): design the layout for role-permission mapping #336
- Loading branch information
Showing
7 changed files
with
578 additions
and
38 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
196 changes: 196 additions & 0 deletions
196
plugins/admin/components/Mapping/JsonPropertyBuilder.js
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,196 @@ | ||
import React, { useState } from 'react' | ||
import { Accordion, FormGroup, Col, Button } from '../../../../app/components' | ||
import GluuInlineInput from '../../../../app/routes/Apps/Gluu/GluuInlineInput' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
function JsonPropertyBuilder({ | ||
propKey, | ||
propValue, | ||
lSize, | ||
path, | ||
handler, | ||
parentIsArray, | ||
}) { | ||
const { t } = useTranslation() | ||
const [show, setShow] = useState(true) | ||
if (!path) { | ||
path = '/' + propKey | ||
} else { | ||
path = path + '/' + propKey | ||
} | ||
function isBoolean(item) { | ||
return typeof item === 'boolean' | ||
} | ||
|
||
function isString(item) { | ||
return typeof item === 'string' | ||
} | ||
|
||
function isNumber(item) { | ||
return typeof item === 'number' || typeof item === 'bigint' | ||
} | ||
const removeHandler = () => { | ||
const patch = {} | ||
patch['path'] = path | ||
patch['value'] = propValue | ||
patch['op'] = 'remove' | ||
handler(patch) | ||
setShow(false) | ||
} | ||
|
||
function isStringArray(item) { | ||
return ( | ||
Array.isArray(item) && item.length >= 1 && typeof item[0] === 'string' | ||
) | ||
} | ||
|
||
function isObjectArray(item) { | ||
return ( | ||
Array.isArray(item) && item.length >= 1 && typeof item[0] === 'object' | ||
) | ||
} | ||
function isObject(item) { | ||
return typeof item === 'object' | ||
} | ||
|
||
function generateLabel(name) { | ||
const result = name.replace(/([A-Z])/g, ' $1') | ||
return result.charAt(0).toUpperCase() + result.slice(1) | ||
} | ||
|
||
if (isBoolean(propValue)) { | ||
return ( | ||
<GluuInlineInput | ||
id={propKey} | ||
name={propKey} | ||
lsize={lSize} | ||
rsize={lSize} | ||
label={generateLabel(propKey)} | ||
isBoolean={true} | ||
handler={handler} | ||
value={propValue} | ||
parentIsArray={parentIsArray} | ||
path={path} | ||
/> | ||
) | ||
} | ||
if (isString(propValue)) { | ||
return ( | ||
<GluuInlineInput | ||
id={propKey} | ||
name={propKey} | ||
lsize={lSize} | ||
rsize={lSize} | ||
label={generateLabel(propKey)} | ||
handler={handler} | ||
value={propValue} | ||
parentIsArray={parentIsArray} | ||
path={path} | ||
/> | ||
) | ||
} | ||
if (isNumber(propValue)) { | ||
return ( | ||
<GluuInlineInput | ||
id={propKey} | ||
name={propKey} | ||
lsize={lSize} | ||
type="number" | ||
rsize={lSize} | ||
label={generateLabel(propKey)} | ||
handler={handler} | ||
value={propValue} | ||
parentIsArray={parentIsArray} | ||
path={path} | ||
/> | ||
) | ||
} | ||
if (isStringArray(propValue)) { | ||
return ( | ||
<GluuInlineInput | ||
id={propKey} | ||
name={propKey} | ||
label={generateLabel(propKey)} | ||
value={propValue} | ||
lsize={lSize} | ||
rsize={lSize} | ||
isArray={true} | ||
handler={handler} | ||
options={propValue} | ||
parentIsArray={parentIsArray} | ||
path={path} | ||
/> | ||
) | ||
} | ||
|
||
if (isObjectArray(propValue)) { | ||
return ( | ||
<Accordion className="mb-2 b-primary" initialOpen> | ||
<Accordion.Header className="text-primary"> | ||
{propKey.toUpperCase()}{' '} | ||
</Accordion.Header> | ||
<Accordion.Body> | ||
{Object.keys(propValue).map((item, idx) => ( | ||
<JsonPropertyBuilder | ||
key={idx} | ||
propKey={item} | ||
propValue={propValue[item]} | ||
handler={handler} | ||
lSize={lSize} | ||
parentIsArray={true} | ||
path={path} | ||
/> | ||
))} | ||
</Accordion.Body> | ||
</Accordion> | ||
) | ||
} | ||
if (isObject(propValue)) { | ||
return ( | ||
<div> | ||
{show && ( | ||
<Accordion className="mb-2 b-primary" initialOpen> | ||
<Accordion.Header className="text-primary"> | ||
{propKey.toUpperCase().length > 10 ? propKey.toUpperCase() : ''} | ||
</Accordion.Header> | ||
<Accordion.Body> | ||
{parentIsArray && ( | ||
<FormGroup row> | ||
<Col sm={11} md={11}></Col> | ||
<Col sm={1} md={1}> | ||
<Button | ||
color="danger" | ||
size="sm" | ||
style={{ float: 'right' }} | ||
onClick={removeHandler} | ||
> | ||
<i className="fa fa-remove mr-2"></i> | ||
{' '} | ||
{t('actions.remove')} | ||
{' '} | ||
</Button> | ||
</Col> | ||
</FormGroup> | ||
)} | ||
{Object.keys(propValue).map((objKey, idx) => ( | ||
<JsonPropertyBuilder | ||
key={idx} | ||
propKey={objKey} | ||
propValue={propValue[objKey]} | ||
handler={handler} | ||
lSize={lSize} | ||
parentIsArray={parentIsArray} | ||
enableRemove={parentIsArray} | ||
path={path} | ||
/> | ||
))} | ||
</Accordion.Body> | ||
</Accordion> | ||
)} | ||
</div> | ||
) | ||
} | ||
return <div></div> | ||
} | ||
|
||
export default JsonPropertyBuilder |
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.