Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
Issue imixs#196
  • Loading branch information
rsoika committed Feb 28, 2023
1 parent 76773fe commit 1fa5671
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 24 deletions.
99 changes: 99 additions & 0 deletions open-bpmn.glsp-client/open-bpmn-properties/src/ImixsRadioGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/********************************************************************************
* Copyright (c) 2022 Imixs Software Solutions GmbH and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {
computeLabel,
ControlProps,
isDescriptionHidden,
OwnPropsOfEnum
} from '@jsonforms/core';
import { VanillaRendererProps } from '@jsonforms/vanilla-renderers';
import merge from 'lodash/merge';
import React, { useState } from 'react';

export const ImixsRadioGroup = ({
classNames,
id,
label,
options,
required,
description,
errors,
data,
uischema,
visible,
config,
enabled,
path,
handleChange
}: ControlProps & VanillaRendererProps & OwnPropsOfEnum) => {
const [isFocused, setFocus] = useState(false);
const isValid = errors.length === 0;
const appliedUiSchemaOptions = merge({}, config, uischema.options);
const showDescription = !isDescriptionHidden(
visible,
description,
isFocused,
appliedUiSchemaOptions.showUnfocusedDescription
);

let groupStyle: { [x: string]: any } = {};
// compute flexDirection based on the optional option 'orientation=vertical|horizontal'
groupStyle = {
display: 'flex',
flexDirection: ('vertical' === uischema!.options!.orientation) ? 'column' : 'row'
};

return (
<div
className={'control imixs-radio-group'}
hidden={!visible}
onFocus={() => setFocus(true)}
onBlur={() => setFocus(false)}
>
<label htmlFor={id} className={'imixs'}>
{computeLabel(
label,
false,
appliedUiSchemaOptions.hideRequiredAsterisk
)}
</label>
<div style={groupStyle}>
{options!.map(option => (
<div key={option.label}>
<input
type='radio'
value={option.value}
id={option.value}
name={id}
checked={data === option.value}
onChange={ev => handleChange(path, ev.currentTarget.value)}
disabled={!enabled}
/>
<label
htmlFor={option.value}
>
{option.label}
</label>
</div>
))}
</div>
<div className={'input-description'}>
{!isValid ? errors : showDescription ? description : undefined}
</div>
</div>
);
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/********************************************************************************
* Copyright (c) 2022 Imixs Software Solutions GmbH and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import {
and,
ControlProps,
isEnumControl,
optionIs, RankedTester, rankWith
} from '@jsonforms/core';
import { withJsonFormsEnumProps } from '@jsonforms/react';
import { VanillaRendererProps, withVanillaControlProps } from '@jsonforms/vanilla-renderers';
import React from 'react';
import { ImixsRadioGroup } from './ImixsRadioGroup';

/***********************
* This is a custom radiobutton renderer that allows vertical and horizontal orientation
* <p>
* In addition the renderer support label|value pairs separated by a | char.
*
*/
/* eslint-disable arrow-body-style */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const ImixsRadioGroupControl = (props: ControlProps & VanillaRendererProps) => {
return <ImixsRadioGroup {...props} />;
};

export const imixsRadioGroupControlTester: RankedTester = rankWith(
3,
and(isEnumControl, optionIs('format', 'radio-imixs'))
);
export default withVanillaControlProps(withJsonFormsEnumProps(ImixsRadioGroupControl));
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import { vanillaCells, vanillaRenderers } from '@jsonforms/vanilla-renderers';
import { isBoundaryEvent } from '@open-bpmn/open-bpmn-model';
import * as React from 'react';
import { createRoot } from 'react-dom/client';

import ImixsRadioGroupControl, { imixsRadioGroupControlTester } from './ImixsRadioGroupControl';
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
@injectable()
export class BPMNPropertyPanel extends AbstractUIExtension implements SelectionListener, IActionHandler { // IActionHandler EditModeListener

Expand Down Expand Up @@ -298,8 +299,9 @@ export class BPMNPropertyPanel extends AbstractUIExtension implements SelectionL
if (bpmnPropertiesUISchema) {
// list of renderers declared outside the App component
const bpmnRenderers = [
...vanillaRenderers
...vanillaRenderers,
// optional register custom renderers...
{ tester: imixsRadioGroupControlTester, renderer: ImixsRadioGroupControl }
];

// render JSONForm // vanillaRenderers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public enum Layout {
public UISchemaBuilder(final Layout layoutType) {

switch (layoutType) {
case HORIZONTAL:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "HorizontalLayout");
layoutContext = rootLayoutBuilder;
break;
case CATEGORIZATION:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "Categorization");
this.groupArrayBuilder = Json.createArrayBuilder();

break;
default:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "VerticalLayout");
layoutContext = rootLayoutBuilder;
case HORIZONTAL:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "HorizontalLayout");
layoutContext = rootLayoutBuilder;
break;
case CATEGORIZATION:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "Categorization");
this.groupArrayBuilder = Json.createArrayBuilder();

break;
default:
rootLayoutBuilder = Json.createObjectBuilder() //
.add("type", "VerticalLayout");
layoutContext = rootLayoutBuilder;
}
}

Expand Down Expand Up @@ -130,13 +130,13 @@ public UISchemaBuilder addLayout(final Layout layoutType) {

// layout context
switch (layoutType) {
case HORIZONTAL:
layoutContext = Json.createObjectBuilder() //
.add("type", "HorizontalLayout");
break;
default:
layoutContext = Json.createObjectBuilder() //
.add("type", "VerticalLayout");
case HORIZONTAL:
layoutContext = Json.createObjectBuilder() //
.add("type", "HorizontalLayout");
break;
default:
layoutContext = Json.createObjectBuilder() //
.add("type", "VerticalLayout");
}
return this;
}
Expand Down Expand Up @@ -197,6 +197,8 @@ public UISchemaBuilder addElement(final String item, final String label, final M
// add optional description?
if (label != null && !label.isBlank()) {
controlBuilder.add("label", label);

controlBuilder.add("classNames", "test-abc");
}

// add optional options?
Expand Down

0 comments on commit 1fa5671

Please sign in to comment.