Skip to content

WIP: Path to array #1831

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 3 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export class ArrayLayoutRenderer
removeTooltip: string;
removeAriaLabel: string;
noData: boolean;
addItem: (path: string, value: any) => () => void;
removeItems: (path: string, toDelete: number[]) => () => void;
addItem: (path: string[], value: any) => () => void;
removeItems: (path: string[], toDelete: number[]) => () => void;
uischemas: {
tester: UISchemaTester;
uischema: UISchemaElement;
Expand Down Expand Up @@ -181,7 +181,7 @@ export class ArrayLayoutRenderer
}
return {
schema: this.scopedSchema,
path: Paths.compose(this.propsPath, `${index}`),
path: Paths.compose(this.propsPath, [`${index}`]),
uischema
};
}
Expand Down
22 changes: 11 additions & 11 deletions packages/angular-material/src/other/master-detail/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import some from 'lodash/some';
//import some from 'lodash/some';
import get from 'lodash/get';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
import {
Expand All @@ -31,6 +31,7 @@ import {
} from '@jsonforms/angular';
import {
ArrayControlProps,
composePaths,
ControlElement,
createDefaultValue,
findUISchema,
Expand All @@ -44,15 +45,15 @@ import {
uiTypeIs
} from '@jsonforms/core';

const keywords = ['#', 'properties', 'items'];
//const keywords = ['#', 'properties', 'items'];

export const removeSchemaKeywords = (path: string) => {
/*export const removeSchemaKeywords = (path: string[]) => {
return path
.split('/')
.filter(s => !some(keywords, key => key === s))
.join('.');
};

*/
@Component({
selector: 'jsonforms-list-with-detail-master',
template: `
Expand Down Expand Up @@ -141,9 +142,9 @@ export class MasterListComponent extends JsonFormsArrayControl {
masterItems: any[];
selectedItem: any;
selectedItemIdx: number;
addItem: (path: string, value: any) => () => void;
removeItems: (path: string, toDelete: number[]) => () => void;
propsPath: string;
addItem: (path: string[], value: any) => () => void;
removeItems: (path: string[], toDelete: number[]) => () => void;
propsPath: string[];
highlightedIdx: number;

constructor(jsonformsService: JsonFormsAngularService, private changeDetectorRef: ChangeDetectorRef) {
Expand Down Expand Up @@ -180,14 +181,13 @@ export class MasterListComponent extends JsonFormsArrayControl {
);

const masterItems = (data || []).map((d: any, index: number) => {
const labelRefInstancePath = controlElement.options?.labelRef && removeSchemaKeywords(
controlElement.options.labelRef
);
const labelRefInstancePath = controlElement.options?.labelRef &&
controlElement.options.labelRef;
const isPrimitive = d !== undefined && typeof d !== 'object';
const masterItem = {
label: isPrimitive ? d.toString() : get(d, labelRefInstancePath ?? getFirstPrimitiveProp(schema)),
data: d,
path: `${path}.${index}`,
path: composePaths(path, [`${index}`]),
schema,
uischema: detailUISchema
};
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-material/src/other/object.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ObjectControlRenderer extends JsonFormsControlWithDetail {
if (isEmpty(props.path)) {
this.detailUiSchema.type = 'VerticalLayout';
} else {
(this.detailUiSchema as GroupLayout).label = startCase(props.path);
(this.detailUiSchema as GroupLayout).label = props.path.map(element=>startCase(element)).toString();
}
if (!this.isEnabled()) {
setReadonly(this.detailUiSchema);
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-material/src/other/table.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class TableRenderer extends JsonFormsArrayControl {
this.displayedColumns = this.items.map(item => item.property);
}
getProps(index: number, props: OwnPropsOfRenderer): OwnPropsOfRenderer {
const rowPath = Paths.compose(props.path, `${index}`);
const rowPath = Paths.compose(props.path, [`${index}`]);
return {
schema: props.schema,
uischema: props.uischema,
Expand All @@ -97,7 +97,7 @@ export class TableRenderer extends JsonFormsArrayControl {
}
generateCells = (
schema: JsonSchema,
rowPath: string
rowPath: string[]
): ColumnDescription[] => {
if (schema.type === 'object') {
return this.getValidColumnProps(schema).map(prop => {
Expand Down
10 changes: 5 additions & 5 deletions packages/angular-test/src/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const booleanBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => false)
Actions.update(['foo'], () => false)
);
fixture.detectChanges();
expect(component.data).toBe(false);
Expand All @@ -130,7 +130,7 @@ export const booleanBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => undefined)
Actions.update(['foo'], () => undefined)
);
fixture.detectChanges();
expect(component.data).toBe(undefined);
Expand All @@ -146,7 +146,7 @@ export const booleanBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => null)
Actions.update(['foo'], () => null)
);
fixture.detectChanges();
expect(component.data).toBe(null);
Expand All @@ -162,10 +162,10 @@ export const booleanBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => true)
Actions.update(['foo'], () => true)
);
getJsonFormsService(component).updateCore(
Actions.update('bar', () => false)
Actions.update(['bar'], () => false)
);
fixture.detectChanges();
expect(component.data).toBe(true);
Expand Down
8 changes: 4 additions & 4 deletions packages/angular-test/src/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const numberBaseTest = <C extends JsonFormsControl>(
component.ngOnInit();
fixture.detectChanges();
getJsonFormsService(fixture.componentInstance).updateCore(
Actions.update('foo', () => 456.456)
Actions.update(['foo'], () => 456.456)
);
fixture.detectChanges();
expect(component.data).toBe(456.456);
Expand All @@ -191,7 +191,7 @@ export const numberBaseTest = <C extends JsonFormsControl>(
component.ngOnInit();
fixture.detectChanges();
getJsonFormsService(fixture.componentInstance).updateCore(
Actions.update('foo', () => undefined)
Actions.update(['foo'], () => undefined)
);
fixture.detectChanges();

Expand All @@ -208,7 +208,7 @@ export const numberBaseTest = <C extends JsonFormsControl>(
component.ngOnInit();
fixture.detectChanges();
getJsonFormsService(fixture.componentInstance).updateCore(
Actions.update('foo', () => null)
Actions.update(['foo'], () => null)
);
fixture.detectChanges();
expect(component.data).toBe(null);
Expand All @@ -224,7 +224,7 @@ export const numberBaseTest = <C extends JsonFormsControl>(
component.ngOnInit();
fixture.detectChanges();
getJsonFormsService(fixture.componentInstance).updateCore(
Actions.update('bar', () => 456.456)
Actions.update(['bar'], () => 456.456)
);
fixture.detectChanges();
expect(component.data).toBe(123.123);
Expand Down
10 changes: 5 additions & 5 deletions packages/angular-test/src/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const rangeBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => 4.56)
Actions.update(['foo'], () => 4.56)
);
fixture.detectChanges();
expect(component.data).toBe(4.56);
Expand All @@ -169,7 +169,7 @@ export const rangeBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => undefined)
Actions.update(['foo'], () => undefined)
);
fixture.detectChanges();
expect(component.data).toBe(undefined);
Expand All @@ -186,7 +186,7 @@ export const rangeBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => null)
Actions.update(['foo'], () => null)
);
fixture.detectChanges();
expect(component.data).toBe(null);
Expand All @@ -203,10 +203,10 @@ export const rangeBaseTest = <C extends JsonFormsControl, I>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => 1.234)
Actions.update(['foo'], () => 1.234)
);
getJsonFormsService(component).updateCore(
Actions.update('bar', () => 456.456)
Actions.update(['bar'], () => 456.456)
);

fixture.detectChanges();
Expand Down
10 changes: 5 additions & 5 deletions packages/angular-test/src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const textBaseTest = <C extends JsonFormsControl>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => 'bar')
Actions.update(['foo'], () => 'bar')
);
fixture.detectChanges();
expect(component.data).toBe('bar');
Expand All @@ -144,7 +144,7 @@ export const textBaseTest = <C extends JsonFormsControl>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => undefined)
Actions.update(['foo'], () => undefined)
);
fixture.detectChanges();
expect(component.data).toBe(undefined);
Expand All @@ -160,7 +160,7 @@ export const textBaseTest = <C extends JsonFormsControl>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => null)
Actions.update(['foo'], () => null)
);
fixture.detectChanges();
expect(component.data).toBe(null);
Expand All @@ -176,10 +176,10 @@ export const textBaseTest = <C extends JsonFormsControl>(
fixture.detectChanges();

getJsonFormsService(component).updateCore(
Actions.update('foo', () => 'foo')
Actions.update(['foo'], () => 'foo')
);
getJsonFormsService(component).updateCore(
Actions.update('bar', () => 'bar')
Actions.update(['bar'], () => 'bar')
);
fixture.detectChanges();
expect(component.data).toBe('foo');
Expand Down
Loading