Skip to content

Commit

Permalink
feat(ui-concerto): add textOnly mode-accordproject#13 (accordproject#365
Browse files Browse the repository at this point in the history
)

Signed-off-by: TC5022 <[email protected]>
Signed-off-by: Abhijith Ganesh <[email protected]>
  • Loading branch information
TC5022 authored and Abhijith Ganesh committed Feb 8, 2022
1 parent 72c2300 commit 46e0b26
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
4 changes: 4 additions & 0 deletions packages/storybook/src/stories/3-ConcertoForm.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {

export const SimpleExample = () => {
const readOnly = boolean('Read-only', false);
const textOnly = boolean('Text-only', false);
const type = text('Type', 'test.Person');
const options = object('Options', {
includeOptionalFields: true,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const SimpleExample = () => {
<div style={{ padding: '10px' }}>
<ConcertoForm
readOnly={readOnly}
textOnly={textOnly}
models={[model]}
options={options}
type={type}
Expand All @@ -91,6 +93,7 @@ export const SimpleExample = () => {

export const ModelBuilder = () => {
const readOnly = boolean('Read-only', false);
const textOnly = boolean('Text-only', false);
const type = text('Type', 'concerto.metamodel.ModelFile');
const options = object('Options', {
includeOptionalFields: false,
Expand Down Expand Up @@ -130,6 +133,7 @@ export const ModelBuilder = () => {
<div style={{ padding: '10px' }}>
<ConcertoModelBuilder
readOnly={readOnly}
textOnly={textOnly}
options={options}
type={type}
json={json}
Expand Down
6 changes: 6 additions & 0 deletions packages/ui-concerto/src/components/concertoForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
margin-bottom: 0;
}

.textOnly > label{
font-weight: 300;
color: #2f4f4f;
font-size: small;
}

/** CSS Classes for use by the ModelBuilderVisitor */
.mbFieldDeclaration {
display: grid;
Expand Down
5 changes: 4 additions & 1 deletion packages/ui-concerto/src/components/concertoForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const ConcertoForm = (props) => {
includeOptionalFields: true,
includeSampleData: 'sample',
disabled: props.readOnly,
textOnly: props.textOnly,
visitor: new ReactFormVisitor(),
onFieldValueChange: (e, key) => {
onFieldValueChange(e, key);
Expand All @@ -81,7 +82,7 @@ const ConcertoForm = (props) => {
removeElement(e, key, index);
},
...options,
}), [addElement, onFieldValueChange, removeElement, options, props.readOnly]);
}), [addElement, onFieldValueChange, removeElement, options, props.readOnly, props.textOnly]);

const generator = React.useMemo(() => {
if (modelManager) {
Expand Down Expand Up @@ -184,6 +185,7 @@ ConcertoForm.defaultProps = {
onValueChange: () => true,
options: {},
readOnly: false,
textOnly: false,
style: {}
};

Expand All @@ -194,6 +196,7 @@ ConcertoForm.propTypes = {
onValueChange: PropTypes.func.isRequired,
options: PropTypes.object,
readOnly: PropTypes.bool,
textOnly: PropTypes.bool,
style: PropTypes.object
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ConcertoModelBuilder.propTypes = {
onValueChange: PropTypes.func.isRequired,
options: PropTypes.shape(),
readOnly: PropTypes.bool,
textOnly: PropTypes.bool,
};

export default ConcertoModelBuilder;
63 changes: 51 additions & 12 deletions packages/ui-concerto/src/components/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ConcertoCheckbox = ({
id,
field,
readOnly,
textOnly,
required,
value,
onFieldValueChange,
Expand All @@ -38,6 +39,7 @@ export const ConcertoCheckbox = ({
fitted
id={id}
readOnly={readOnly}
disabled={textOnly}
checked={value}
onChange={(e, data) => onFieldValueChange(data, id)}
key={`checkbox-${id}`}
Expand All @@ -49,6 +51,7 @@ export const ConcertoInput = ({
id,
field,
readOnly,
textOnly,
required,
value,
onFieldValueChange,
Expand All @@ -67,6 +70,7 @@ export const ConcertoInput = ({
}
return <Form.Field key={`field-${id}`} required={required} error={error}>
<ConcertoLabel key={`label-${id}`} skip={skipLabel} name={applyDecoratorTitle(field)} htmlFor={id} />
{!textOnly ? (
<Input
id={id}
type={type}
Expand All @@ -79,13 +83,21 @@ export const ConcertoInput = ({
}
key={`input-${id}`}
/>
) : (
<div className='textOnly'>
<label value={value} key={`input-${id}`} >
{value}
</label>
</div>
)}
</Form.Field>;
};

export const ConcertoRelationship = ({
id,
field,
readOnly,
textOnly,
required,
value,
onFieldValueChange,
Expand All @@ -105,6 +117,7 @@ export const ConcertoRelationship = ({
id,
field,
readOnly,
textOnly,
required,
value,
onFieldValueChange,
Expand All @@ -119,6 +132,8 @@ export const ConcertoRelationship = ({
? <ConcertoDropdown
id={id}
value={value}
displayText={value}
textOnly={textOnly}
readOnly={readOnly}
onFieldValueChange={onFieldValueChange}
options={relationshipOptions}
Expand All @@ -129,6 +144,7 @@ export const ConcertoRelationship = ({
label={<Label basic>{normalizeLabel(relationship.getType())}</Label>}
labelPosition='right'
readOnly={readOnly}
textOnly={textOnly}
value={relationship.getIdentifier()}
onChange={(e, data) => {
relationship.setIdentifier(data.value || 'resource1');
Expand Down Expand Up @@ -173,13 +189,15 @@ export const ConcertoArray = ({
id,
field,
readOnly,
textOnly,
required,
children,
addElement,
}) => (
<Form.Field key={`field-${id}`} required={required}>
<ConcertoLabel name={applyDecoratorTitle(field)} />
{children}
{!textOnly ? (
<div className="arrayElement grid">
<div />
<Button
Expand All @@ -198,18 +216,21 @@ export const ConcertoArray = ({
}}
/>
</div>
) : null}
</Form.Field>
);

export const ConcertoArrayElement = ({
id,
readOnly,
textOnly,
children,
index,
removeElement,
}) => (
<div className="arrayElement grid" key={`array-${id}`}>
<div key={`array-children-${id}`}>{children}</div>
{!textOnly ? (
<Button
icon={<Popup
content='Remove this element'
Expand All @@ -226,28 +247,46 @@ export const ConcertoArrayElement = ({
}}
key={`array-btn-${id}`}
/>
) : null}
</div>
);

export const ConcertoDropdown = ({
id,
readOnly,
textOnly,
displayText,
value,
text,
onFieldValueChange,
options,
}) => !readOnly ? (
<Select
clearable
fluid
value={value}
onChange={(e, data) => onFieldValueChange(data, id)}
key={`select-${id}`}
options={options}
/>
) : (
<Input type="text" readOnly value={text} key={`input-${id}`} />
);
}) => {
if (readOnly) {
return (
<Input type="text" readOnly value={displayText} key={`input-${id}`} />
);
} else if (textOnly) {
return (
<div className="textOnly">
<label value={displayText} key={`input-${id}`}>
{" "}
{displayText}{" "}
</label>
</div>
);
} else {
return (
<Select
clearable
fluid
value={value}
onChange={(e, data) => onFieldValueChange(data, id)}
key={`select-${id}`}
options={options}
/>
);
}
}

const BinaryField = ({ className, children }) => (
<div className={className}>
Expand Down
1 change: 1 addition & 0 deletions packages/ui-concerto/src/formgenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FormGenerator {
* 'sample' uses random well-typed values
* 'empty' provides sensible empty values
* @param {object} options.disabled - if true, all form fields will be disabled
* @param {object} options.textOnly - if true, all form fields will appear as labels
* @param {object} options.visitor - a class that extends HTMLFormVisitor
* that generates HTML, defaults to HTMLFormVisitor
* @param {object} options.customClasses - a custom CSS classes that can be
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-concerto/src/modelBuilderVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class ModelBuilderVisitor extends ReactFormVisitor {
key={key}
value={value.$class}
text={altText ? altText.text : value.$class}
displayText={altText ? altText.text : value.$class}
textOnly={parameters.textOnly}
readOnly={parameters.disabled}
onFieldValueChange={onFieldValueChange}
options={declarationTypes.map(({ value, text }) => ({
Expand Down
8 changes: 8 additions & 0 deletions packages/ui-concerto/src/reactformvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ class ReactFormVisitor {
id={key}
key={`enum-${key}`}
value={value}
displayText={value}
field={enumDeclaration}
readOnly={parameters.disabled}
textOnly={parameters.textOnly}
onFieldValueChange={parameters.onFieldValueChange}
options={enumDeclaration.getProperties().map(property => ({
key: `option-${property.getName()}`,
Expand All @@ -219,6 +221,7 @@ class ReactFormVisitor {
const {
skipLabel,
disabled,
textOnly,
addElement,
removeElement,
onFieldValueChange,
Expand All @@ -242,6 +245,7 @@ class ReactFormVisitor {
type: toFieldType(field.getType()),
required: !field.isOptional(),
readOnly: disabled,
textOnly: textOnly,
addElement,
removeElement,
onFieldValueChange,
Expand Down Expand Up @@ -315,6 +319,8 @@ class ReactFormVisitor {
id={key}
key={`select-${key}`}
value={value}
displayText={value}
textOnly={parameters.textOnly}
readOnly={parameters.disabled}
onFieldValueChange={parameters.onFieldValueChange}
options={options.map(({ value, text }) => ({
Expand Down Expand Up @@ -357,6 +363,7 @@ class ReactFormVisitor {
const {
skipLabel,
disabled,
textOnly,
addElement,
removeElement,
onFieldValueChange,
Expand All @@ -380,6 +387,7 @@ class ReactFormVisitor {
type: 'text',
required: !relationship.isOptional(),
readOnly: disabled,
textOnly: textOnly,
addElement,
removeElement,
onFieldValueChange,
Expand Down

0 comments on commit 46e0b26

Please sign in to comment.