Skip to content

Commit

Permalink
feat: rename SG editorClass & deprecate internalColumnEditor (#1168)
Browse files Browse the repository at this point in the history
* feat: rename SG `editorClass` & deprecate `internalColumnEditor`
  • Loading branch information
ghiscoding committed Mar 23, 2024
1 parent b54e8e7 commit bb958ff
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 165 deletions.
14 changes: 7 additions & 7 deletions packages/aurelia-slickgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"@aurelia/i18n": "latest",
"@aurelia/runtime": "latest",
"@aurelia/runtime-html": "latest",
"@slickgrid-universal/common": "~4.5.0",
"@slickgrid-universal/custom-footer-component": "~4.5.0",
"@slickgrid-universal/empty-warning-component": "~4.5.0",
"@slickgrid-universal/event-pub-sub": "~4.5.0",
"@slickgrid-universal/pagination-component": "~4.5.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.5.0",
"@slickgrid-universal/utils": "~4.5.0",
"@slickgrid-universal/common": "~4.6.0",
"@slickgrid-universal/custom-footer-component": "~4.6.0",
"@slickgrid-universal/empty-warning-component": "~4.6.0",
"@slickgrid-universal/event-pub-sub": "~4.6.0",
"@slickgrid-universal/pagination-component": "~4.6.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.6.0",
"@slickgrid-universal/utils": "~4.6.0",
"dequal": "^2.0.3",
"isomorphic-dompurify": "^2.4.0",
"moment-mini": "^2.29.4",
Expand Down
91 changes: 47 additions & 44 deletions packages/aurelia-slickgrid/src/custom-elements/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
BackendServiceApi,
BackendServiceOption,
Column,
ColumnEditor,
DataViewOption,
EventSubscription,
ExtensionList,
Expand Down Expand Up @@ -1149,34 +1148,36 @@ export class AureliaSlickgridCustomElement {

/** Load the Editor Collection asynchronously and replace the "collection" property when Promise resolves */
protected loadEditorCollectionAsync(column: Column) {
const collectionAsync = (column?.editor as ColumnEditor).collectionAsync;
(column?.editor as ColumnEditor).disabled = true; // disable the Editor DOM element, we'll re-enable it after receiving the collection with "updateEditorCollection()"

if (collectionAsync instanceof Promise) {
// wait for the "collectionAsync", once resolved we will save it into the "collection"
// the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
collectionAsync.then((response: any | any[]) => {
if (Array.isArray(response)) {
this.updateEditorCollection(column, response); // from Promise
} else if (response instanceof Response && typeof response.json === 'function') {
if (response.bodyUsed) {
console.warn(`[Aurelia-SlickGrid] The response body passed to collectionAsync was already read. `
+ `Either pass the dataset from the Response or clone the response first using response.clone()`);
} else {
// from Fetch
(response as Response).json().then(data => this.updateEditorCollection(column, data));
if (column?.editor) {
const collectionAsync = column.editor.collectionAsync;
column.editor.disabled = true; // disable the Editor DOM element, we'll re-enable it after receiving the collection with "updateEditorCollection()"

if (collectionAsync instanceof Promise) {
// wait for the "collectionAsync", once resolved we will save it into the "collection"
// the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
collectionAsync.then((response: any | any[]) => {
if (Array.isArray(response)) {
this.updateEditorCollection(column, response); // from Promise
} else if (response instanceof Response && typeof response.json === 'function') {
if (response.bodyUsed) {
console.warn(`[Aurelia-SlickGrid] The response body passed to collectionAsync was already read. `
+ `Either pass the dataset from the Response or clone the response first using response.clone()`);
} else {
// from Fetch
(response as Response).json().then(data => this.updateEditorCollection(column, data));
}
} else if (response?.content) {
this.updateEditorCollection(column, response.content); // from http-client
}
} else if (response?.content) {
this.updateEditorCollection(column, response.content); // from http-client
}
});
} else if (this.rxjs?.isObservable(collectionAsync)) {
// wrap this inside a setTimeout to avoid timing issue since updateEditorCollection requires to call SlickGrid getColumns() method
setTimeout(() => {
this.subscriptions.push(
(collectionAsync as Observable<any>).subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection))
);
});
});
} else if (this.rxjs?.isObservable(collectionAsync)) {
// wrap this inside a setTimeout to avoid timing issue since updateEditorCollection requires to call SlickGrid getColumns() method
setTimeout(() => {
this.subscriptions.push(
(collectionAsync as Observable<any>).subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection))
);
});
}
}
}

Expand Down Expand Up @@ -1493,7 +1494,7 @@ export class AureliaSlickgridCustomElement {

return {
...column,
editor: column.editor && this.container.getFactory(column.editor.model).Type,
editorClass: column.editor && this.container.getFactory(column.editor.model).Type,
internalColumnEditor: { ...column.editor }
};
});
Expand All @@ -1505,23 +1506,25 @@ export class AureliaSlickgridCustomElement {
* Once we found the new pointer, we will reassign the "editor" and "collection" to the "internalColumnEditor" so it has newest collection
*/
protected updateEditorCollection<T = any>(column: Column<T>, newCollection: T[]) {
(column.editor as ColumnEditor).collection = newCollection;
(column.editor as ColumnEditor).disabled = false;

// find the new column reference pointer & re-assign the new editor to the internalColumnEditor
if (Array.isArray(this._columnDefinitions)) {
const columnRef = this._columnDefinitions.find((col: Column) => col.id === column.id);
if (columnRef) {
columnRef.internalColumnEditor = column.editor as ColumnEditor;
if (this.grid && column.editor) {
column.editor.collection = newCollection;
column.editor.disabled = false;

// find the new column reference pointer & re-assign the new editor to the internalColumnEditor
if (Array.isArray(this._columnDefinitions)) {
const columnRef = this._columnDefinitions.find((col: Column) => col.id === column.id);
if (columnRef) {
columnRef.internalColumnEditor = column.editor;
}
}
}

// get current Editor, remove it from the DOM then re-enable it and re-render it with the new collection.
const currentEditor = this.grid.getCellEditor() as AutocompleterEditor | SelectEditor;
if (currentEditor?.disable && currentEditor?.renderDomElement) {
currentEditor.destroy();
currentEditor.disable(false);
currentEditor.renderDomElement(newCollection);
// get current Editor, remove it from the DOM then re-enable it and re-render it with the new collection.
const currentEditor = this.grid.getCellEditor() as AutocompleterEditor | SelectEditor;
if (currentEditor?.disable && currentEditor?.renderDomElement) {
currentEditor.destroy();
currentEditor.disable(false);
currentEditor.renderDomElement(newCollection);
}
}
}
}
18 changes: 9 additions & 9 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
"@faker-js/faker": "^8.4.1",
"@fnando/sparkline": "^0.3.10",
"@popperjs/core": "^2.11.8",
"@slickgrid-universal/common": "^4.5.0",
"@slickgrid-universal/composite-editor-component": "^4.5.0",
"@slickgrid-universal/custom-tooltip-plugin": "^4.5.0",
"@slickgrid-universal/excel-export": "^4.5.0",
"@slickgrid-universal/graphql": "^4.5.0",
"@slickgrid-universal/odata": "^4.5.0",
"@slickgrid-universal/row-detail-view-plugin": "^4.5.0",
"@slickgrid-universal/rxjs-observable": "^4.5.0",
"@slickgrid-universal/text-export": "^4.5.0",
"@slickgrid-universal/common": "^4.6.0",
"@slickgrid-universal/composite-editor-component": "^4.6.0",
"@slickgrid-universal/custom-tooltip-plugin": "^4.6.0",
"@slickgrid-universal/excel-export": "^4.6.0",
"@slickgrid-universal/graphql": "^4.6.0",
"@slickgrid-universal/odata": "^4.6.0",
"@slickgrid-universal/row-detail-view-plugin": "^4.6.0",
"@slickgrid-universal/rxjs-observable": "^4.6.0",
"@slickgrid-universal/text-export": "^4.6.0",
"aurelia": "latest",
"aurelia-slickgrid": "workspace:*",
"bootstrap": "^5.3.3",
Expand Down

0 comments on commit bb958ff

Please sign in to comment.