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

Fix memory leak issue #2243

Merged
merged 10 commits into from
Mar 25, 2024
3 changes: 2 additions & 1 deletion packages/angular-material/src/library/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { LabelRenderer } from './other/label.renderer';
import { JsonFormsDetailComponent } from './other/master-detail/detail';
import { MasterListComponent } from './other/master-detail/master';
import { ObjectControlRenderer } from './other/object.renderer';
import { TableRenderer } from './other/table.renderer';
import { TableRenderer, GetProps } from './other/table.renderer';
import { CategorizationTabLayoutRenderer } from './layouts/categorization-layout.renderer';
import { GroupLayoutRenderer } from './layouts/group-layout.renderer';
import { HorizontalLayoutRenderer } from './layouts/horizontal-layout.renderer';
Expand Down Expand Up @@ -110,6 +110,7 @@ import { LayoutChildrenRenderPropsPipe } from './layouts';
TableRenderer,
ArrayLayoutRenderer,
LayoutChildrenRenderPropsPipe,
GetProps,
],
exports: [
CommonModule,
Expand Down
24 changes: 14 additions & 10 deletions packages/angular-material/src/library/other/table.renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
THE SOFTWARE.
*/
import startCase from 'lodash/startCase';
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Pipe, PipeTransform } from '@angular/core';
import {
JsonFormsAngularService,
JsonFormsArrayControl,
Expand Down Expand Up @@ -126,7 +126,7 @@ import {
<th mat-header-cell *matHeaderCellDef>{{ item.header }}</th>
<td mat-cell *matCellDef="let index = index">
<jsonforms-outlet
[renderProps]="getProps(index, item.props)"
[renderProps]="index | getProps : item.props"
></jsonforms-outlet>
</td>
</ng-container>
Expand Down Expand Up @@ -162,14 +162,6 @@ export class TableRenderer extends JsonFormsArrayControl implements OnInit {
}
this.translations = props.translations;
}
getProps(index: number, props: OwnPropsOfRenderer): OwnPropsOfRenderer {
const rowPath = Paths.compose(props.path, `${index}`);
return {
schema: props.schema,
uischema: props.uischema,
path: rowPath,
};
}

remove(index: number): void {
this.removeItems(this.propsPath, [index])();
Expand Down Expand Up @@ -265,3 +257,15 @@ export const controlWithoutLabel = (scope: string): ControlElement => ({
scope: scope,
label: false,
});

@Pipe({ name: 'getProps' })
export class GetProps implements PipeTransform {
transform(index: number, props: OwnPropsOfRenderer) {
const rowPath = Paths.compose(props.path, `${index}`);
return {
schema: props.schema,
uischema: props.uischema,
path: rowPath,
};
}
}
3 changes: 2 additions & 1 deletion packages/angular-material/test/table-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { JsonFormsAngularService, JsonFormsModule } from '@jsonforms/angular';
import { ControlElement } from '@jsonforms/core';
import { TextControlRenderer, TextControlRendererTester } from '../src';
import {
GetProps,
TableRenderer,
TableRendererTester,
} from '../src/library/other/table.renderer';
Expand Down Expand Up @@ -139,7 +140,7 @@ describe('Table', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TableRenderer, TextControlRenderer],
declarations: [TableRenderer, TextControlRenderer, GetProps],
imports: [
CommonModule,
JsonFormsModule,
Expand Down
Loading