Skip to content

Commit

Permalink
fix(components): don't instantiate composite editor twice (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored Dec 20, 2020
1 parent 743d984 commit 8548393
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import 'jest-extended';
import {
Column,
CollectionService,
ColumnFilters,
CurrentFilter,
CurrentPagination,
CurrentSorter,
Editor,
Editors,
ExtensionList,
ExtensionName,
ExtensionService,
ExtensionUtility,
Filters,
Expand All @@ -17,21 +20,17 @@ import {
GridState,
GridStateService,
GridStateType,
SlickGroupItemMetadataProvider,
GroupingAndColspanService,
Pagination,
PaginationService,
ServicePagination,
SharedService,
SlickEventHandler,
SlickGrid,
SlickGroupItemMetadataProvider,
SortService,
TreeDataService,
TranslaterService,
ColumnFilters,
Editor,
ExtensionName,
ColumnFilter,
SlickEventHandler,
} from '@slickgrid-universal/common';
import { GraphqlService, GraphqlPaginatedResult, GraphqlServiceApi, GraphqlServiceOption } from '@slickgrid-universal/graphql';
import { SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component';
Expand All @@ -58,7 +57,7 @@ const mockConvertParentChildArray = jest.fn();
(backendUtilities.onBackendError as any) = mockBackendError;

declare const Slick: any;
const slickEventHandler = new MockSlickEventHandler() as SlickEventHandler;
const slickEventHandler = new MockSlickEventHandler() as unknown as SlickEventHandler;

const extensionServiceStub = {
bindDifferentExtensions: jest.fn(),
Expand Down Expand Up @@ -976,7 +975,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', ()
component.gridOptions = {
backendServiceApi: {
onInit: jest.fn(),
service: mockGraphqlService,
service: mockGraphqlService as any,
preProcess: jest.fn(),
postProcess: jest.fn(),
process: jest.fn(),
Expand Down Expand Up @@ -1560,7 +1559,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', ()
const emptySpy = jest.spyOn(component.slickEmptyWarning, 'showEmptyDataMessage');
component.columnDefinitions = mockColDefs;
component.refreshGridData([]);
mockDataView.onRowCountChanged.notify({ first: 'John' });
mockDataView.onRowCountChanged.notify({ current: 0, item: { first: 'John' } });

setTimeout(() => {
expect(component.columnDefinitions).toEqual(mockColDefs);
Expand Down Expand Up @@ -1772,7 +1771,7 @@ describe('Slick-Vanilla-Grid-Bundle Component instantiated via Constructor', ()
it('should call the backend service API to refresh the dataset', (done) => {
component.gridOptions.enablePagination = true;
component.gridOptions.backendServiceApi = {
service: mockGraphqlService,
service: mockGraphqlService as any,
process: jest.fn(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ export class SlickVanillaGridBundle {
}

// dispose the Components
this.slickEmptyWarning?.dispose();
this.slickCompositeEditor?.dispose();
this.slickFooter?.dispose();
this.slickPagination?.dispose();

Expand Down Expand Up @@ -631,10 +629,13 @@ export class SlickVanillaGridBundle {
this.slickEmptyWarning = new SlickEmptyWarningComponent();
this._registeredResources.push(this.slickEmptyWarning);

// also initialize (render) the pagination component
// also initialize (render) the pagination component when using the salesforce default options
// however before adding a new instance, just make sure there isn't one that might have been loaded by calling "registerExternalResources"
if (this.gridOptions.enableCompositeEditor && this.gridOptions.useSalesforceDefaultGridOptions) {
this.slickCompositeEditor = new SlickCompositeEditorComponent();
this._registeredResources.push(this.slickCompositeEditor);
if (!this._registeredResources.some((resource => resource instanceof SlickCompositeEditorComponent))) {
this.slickCompositeEditor = new SlickCompositeEditorComponent();
this._registeredResources.push(this.slickCompositeEditor);
}
}

// bind the Backend Service API callback functions only after the grid is initialized
Expand All @@ -649,9 +650,6 @@ export class SlickVanillaGridBundle {
for (const resource of this._registeredResources) {
if (typeof resource.init === 'function') {
resource.init(this.slickGrid, this.universalContainerService);
if (resource instanceof SlickCompositeEditorComponent) {
this.slickCompositeEditor = resource;
}
}
}
}
Expand Down

0 comments on commit 8548393

Please sign in to comment.