Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve label handling in MasterListComponent #1786

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/angular-material/src/other/master-detail/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ControlElement,
createDefaultValue,
findUISchema,
getFirstPrimitiveProp,
JsonFormsState,
mapDispatchToArrayControlProps,
mapStateToArrayControlProps,
Expand Down Expand Up @@ -169,22 +170,22 @@ export class MasterListComponent extends JsonFormsArrayControl {
const { data, path, schema, uischema } = props;
const controlElement = uischema as ControlElement;
this.propsPath = props.path;
const detailUISchema =
controlElement.options.detail ||
findUISchema(
const detailUISchema = findUISchema(
props.uischemas,
schema,
`${controlElement.scope}/items`,
props.path,
'VerticalLayout'
'VerticalLayout',
controlElement
);

const masterItems = (data || []).map((d: any, index: number) => {
const labelRefInstancePath = removeSchemaKeywords(
const labelRefInstancePath = controlElement.options?.labelRef && removeSchemaKeywords(
controlElement.options.labelRef
);
const isPrimitive = d && typeof d !== 'object';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is false for 0 and empty strings ''

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, JS and auto conversion of types ...

const masterItem = {
label: get(d, labelRefInstancePath),
label: isPrimitive ? d.toString() : get(d, labelRefInstancePath ?? getFirstPrimitiveProp(schema)),
data: d,
path: `${path}.${index}`,
schema,
Expand Down
83 changes: 83 additions & 0 deletions packages/examples/src/1779.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
The MIT License

Copyright (c) 2017-2021 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { registerExamples } from './register';

const data = {
'an-array-of-strings': ['foo', 'bar', 'foobar']
};
const schema = {
type: 'object',
properties: {
'an-array-of-strings': {
type: 'array',
items: {
type: 'string'
}
}
}
};
const uischema = {
"type": "ListWithDetail",
"scope": "#/properties/an-array-of-strings"
};

registerExamples([
{
name: '1779',
label: 'List With Detail primitive (string)',
data,
schema,
uischema
}
]);

const data_number = {
'an-array-of-numbers': [1, 2, 3]
};
const schema_number = {
type: 'object',
properties: {
'an-array-of-numbers': {
type: 'array',
items: {
type: 'number'
}
}
}
};
const uischema_number = {
"type": "ListWithDetail",
"scope": "#/properties/an-array-of-numbers"
};

registerExamples([
{
name: '1779',
label: 'List With Detail primitive (string)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label: 'List With Detail primitive (string)',
label: 'List With Detail primitive (number)',

data: data_number,
schema: schema_number,
uischema: uischema_number
}
]);
4 changes: 3 additions & 1 deletion packages/examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import * as booleanToggle from './booleanToggle';
import * as multiEnum from './multi-enum';
import * as enumInArray from './enumInArray';
import * as readonly from './readonly';
import * as bug_1779 from './1779';
export * from './register';
export * from './example';

Expand Down Expand Up @@ -132,5 +133,6 @@ export {
booleanToggle,
multiEnum,
enumInArray,
readonly
readonly,
bug_1779
};
99 changes: 99 additions & 0 deletions packages/examples/src/list-with-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,95 @@ const uischema = {
}
};

const uischemaNoLabelRef = {
type: 'ListWithDetail',
scope: '#/properties/orders',
options: {
detail: {
type: 'VerticalLayout',
elements: [
{
type: 'HorizontalLayout',
elements: [
{
type: 'Control',
scope: '#/properties/title'
},
{
type: 'Control',
scope: '#/properties/processId'
}
]
},
{
type: 'Group',
label: 'Customer',
elements: [
{
type: 'Control',
label: 'ID',
scope: '#/properties/customer/properties/id'
},
{
type: 'Control',
label: 'Name',
scope: '#/properties/customer/properties/name'
},
{
type: 'Control',
label: 'Department',
scope: '#/properties/customer/properties/department'
}
]
},
{
type: 'VerticalLayout',
elements: [
{
type: 'VerticalLayout',
elements: [
{
type: 'HorizontalLayout',
elements: [
{
type: 'Control',
scope: '#/properties/ordered',
options: {
toggle: true
}
},
{
type: 'Control',
scope: '#/properties/assignee'
}
]
},
{
type: 'HorizontalLayout',
elements: [
{
type: 'Control',
scope: '#/properties/startDate'
},
{
type: 'Control',
scope: '#/properties/endDate'
}
]
},
{
type: 'Control',
scope: '#/properties/status'
}
]
}
]
}
]
}
}
};

registerExamples([
{
name: 'list-with-detail',
Expand All @@ -204,3 +293,13 @@ registerExamples([
uischema
}
]);

registerExamples([
{
name: 'list-with-detail-no-labelref',
label: 'List With Detail (No Label Ref)',
data,
schema,
uischema:uischemaNoLabelRef
}
]);