-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- allow to modify scope of controls - allow to modify label if controls - allow to modify label of groups - allow to modify label of labels
- Loading branch information
Showing
12 changed files
with
277 additions
and
20 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
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,95 @@ | ||
/** | ||
* --------------------------------------------------------------------- | ||
* Copyright (c) 2020 EclipseSource Munich | ||
* Licensed under MIT | ||
* https://github.com/eclipsesource/jsonforms-editor/blob/master/LICENSE | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
import { Grid, TextField } from '@material-ui/core'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import React from 'react'; | ||
|
||
import { useDispatch, useSchema } from '../context'; | ||
import { | ||
Actions, | ||
getChildren, | ||
getScope, | ||
isArrayElement, | ||
isObjectElement, | ||
SchemaElement, | ||
} from '../model'; | ||
import { EditorControl } from '../model/uischema'; | ||
|
||
interface EditableControlProps { | ||
uischema: EditorControl; | ||
} | ||
export const EditableControl: React.FC<EditableControlProps> = ({ | ||
uischema, | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const baseSchema = useSchema() as SchemaElement; | ||
const handleLabelChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
dispatch( | ||
Actions.updateUISchemaElement(uischema.uuid, { | ||
label: event.target.value, | ||
}) | ||
); | ||
}; | ||
const handleScopeChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
dispatch( | ||
Actions.changeControlScope( | ||
uischema.uuid, | ||
(event.target.value as any).scope, | ||
(event.target.value as any).uuid | ||
) | ||
); | ||
}; | ||
const scopes = getChildren(baseSchema) | ||
.flatMap((child) => { | ||
// if the child is the only item of an array, use its children instead | ||
if ( | ||
(isObjectElement(child) && | ||
isArrayElement(child.parent) && | ||
child.parent.items === child) || | ||
isObjectElement(child) | ||
) { | ||
return getChildren(child); | ||
} | ||
return [child]; | ||
}) | ||
.map((e) => ({ scope: `#${getScope(e)}`, uuid: e.uuid })); | ||
const scopeValues = scopes.filter((s) => s.scope.endsWith(uischema.scope)); | ||
const scopeValue = | ||
scopeValues && scopeValues.length === 1 ? scopeValues[0] : ''; | ||
return ( | ||
<Grid container direction={'column'}> | ||
<Grid item xs> | ||
<TextField | ||
id='filled-name' | ||
label='Label' | ||
value={uischema.label ?? ''} | ||
onChange={handleLabelChange} | ||
fullWidth | ||
/> | ||
</Grid> | ||
<Grid item xs> | ||
<TextField | ||
id='standard-select-currency' | ||
select | ||
label='Scope' | ||
value={scopeValue} | ||
onChange={handleScopeChange} | ||
fullWidth | ||
helperText='Please select your scope' | ||
> | ||
{scopes.map((scope) => ( | ||
<MenuItem key={scope.scope} value={scope as any}> | ||
{scope.scope} | ||
</MenuItem> | ||
))} | ||
</TextField> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* --------------------------------------------------------------------- | ||
* Copyright (c) 2020 EclipseSource Munich | ||
* Licensed under MIT | ||
* https://github.com/eclipsesource/jsonforms-editor/blob/master/LICENSE | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
import { ControlProps, isControl, rankWith } from '@jsonforms/core'; | ||
import { withJsonFormsControlProps } from '@jsonforms/react'; | ||
import React from 'react'; | ||
|
||
import { EditableControl } from '../components'; | ||
import { EditorControl } from '../model/uischema'; | ||
|
||
interface DroppableControlProps extends ControlProps { | ||
uischema: EditorControl; | ||
} | ||
const DroppableControl: React.FC<DroppableControlProps> = ({ uischema }) => { | ||
return <EditableControl uischema={uischema} />; | ||
}; | ||
|
||
export const DroppableControlRegistration = { | ||
tester: rankWith(40, isControl), // less than DroppableElement | ||
renderer: withJsonFormsControlProps( | ||
DroppableControl as React.FC<ControlProps> | ||
), | ||
}; |
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.