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

chore: remove deprecated options #1198

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
29 changes: 8 additions & 21 deletions packages/common/src/editors/__tests__/sliderEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ describe('SliderEditor', () => {
expect(editorNumberElm.textContent).toBe('4');
});

it('should create the input editor with min/max slider values being set by editor "sliderStartValue" through the editor params', () => {
mockColumn.internalColumnEditor = { params: { sliderStartValue: 4 } };
it('should create the input editor with min/max slider values being set by editor "sliderStartValue" through the editor editorOptions', () => {
mockColumn.internalColumnEditor = { editorOptions: { sliderStartValue: 4 } };
mockItemData = { id: 1, price: null, isActive: true };

editor = new SliderEditor(editorArguments);
Expand All @@ -169,8 +169,8 @@ describe('SliderEditor', () => {
expect(editorNumberElm.textContent).toBe('4');
});

it('should create the input editor with default search terms range but without showing side numbers when "hideSliderNumber" is set in params', () => {
(mockColumn.internalColumnEditor as ColumnEditor).params = { hideSliderNumber: true };
it('should create the input editor with default search terms range but without showing side numbers when "hideSliderNumber" is set in editorOptions', () => {
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { hideSliderNumber: true };
mockItemData = { id: 1, price: null, isActive: true };

editor = new SliderEditor(editorArguments);
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('SliderEditor', () => {

it('should update slider number every time a change event happens on the input slider', () => {
const cellMouseEnterSpy = jest.spyOn(gridStub.onMouseEnter, 'notify');
(mockColumn.internalColumnEditor as ColumnEditor).params = { hideSliderNumber: false };
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { hideSliderNumber: false };
mockItemData = { id: 1, price: 32, isActive: true };
editor = new SliderEditor(editorArguments);
editor.loadValue(mockItemData);
Expand All @@ -237,7 +237,7 @@ describe('SliderEditor', () => {

describe('isValueChanged method', () => {
it('should return True when previously dispatched change event is a different slider input number', () => {
(mockColumn.internalColumnEditor as ColumnEditor).params = { sliderStartValue: 5 };
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { sliderStartValue: 5 };
mockItemData = { id: 1, price: 32, isActive: true };
editor = new SliderEditor(editorArguments);
editor.loadValue(mockItemData);
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('SliderEditor', () => {
});

it('should return False when previously dispatched change event is the same input number as "sliderStartValue" provided by the user', () => {
(mockColumn.internalColumnEditor as ColumnEditor).params = { sliderStartValue: 5 };
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { sliderStartValue: 5 };
mockItemData = { id: 1, price: 5, isActive: true };
editor = new SliderEditor(editorArguments);
editor.loadValue(mockItemData);
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('SliderEditor', () => {
});

it('should return serialized value as the custom "sliderStartValue" number when item value is null', () => {
(mockColumn.internalColumnEditor as ColumnEditor).params = { sliderStartValue: 5 };
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { sliderStartValue: 5 };
mockItemData = { id: 1, price: null, isActive: true };

editor = new SliderEditor(editorArguments);
Expand Down Expand Up @@ -469,19 +469,6 @@ describe('SliderEditor', () => {
});
});

it('should create the input editor with option defined in editor params and expect deprecated console warning', () => {
(mockColumn.internalColumnEditor as ColumnEditor).params = { sliderStartValue: 5, enableSliderTrackColoring: true };
mockItemData = { id: 1, price: 80, isActive: true };
editor = new SliderEditor(editorArguments);
editor.loadValue(mockItemData);
editor.setValue(45);

const editorElm = divContainer.querySelector('.slider-editor input.editor-price') as HTMLInputElement;
editorElm.dispatchEvent(new Event('change'));

expect(consoleSpy).toHaveBeenCalledWith('[Slickgrid-Universal] All editor.params from Slider Editor are moving to "editorOptions" for better typing support and "params" will be deprecated in future release.');
});

it('should enableSliderTrackColoring and trigger a change event and expect slider track to have background color', () => {
(mockColumn.internalColumnEditor as ColumnEditor).editorOptions = { sliderStartValue: 5, enableSliderTrackColoring: true };
mockItemData = { id: 1, price: 80, isActive: true };
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/editors/autocompleterEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import type {
} from '../interfaces/index';
import { textValidator } from '../editorValidators/textValidator';
import { addAutocompleteLoadingByOverridingFetch } from '../commonEditorFilter';
import { getEditorOptionByName } from './editorUtilities';
import { createDomElement, sanitizeTextByAvailableSanitizer, } from '../services/domUtilities';
import { findOrDefault, getDescendantProperty, } from '../services/utilities';
import type { TranslaterService } from '../services/translater.service';
Expand Down Expand Up @@ -549,7 +548,7 @@ export class AutocompleterEditor<T extends AutocompleteItem = any> implements Ed
this._editorInputGroupElm.appendChild(document.createElement('span'));

// show clear date button (unless user specifically doesn't want it)
if (!getEditorOptionByName<AutocompleterOption, 'hideClearButton'>(this.columnEditor, 'hideClearButton', undefined, 'autocomplete')) {
if (!(this.columnEditor.editorOptions as AutocompleterOption)?.hideClearButton) {
closeButtonGroupElm.appendChild(this._clearButtonElm);
this._editorInputGroupElm.appendChild(closeButtonGroupElm);
this._bindEventService.bind(this._clearButtonElm, 'click', () => this.clear());
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
FlatpickrOption,
GridOption,
} from './../interfaces/index';
import { getEditorOptionByName } from './editorUtilities';
import { createDomElement, destroyObjectDomElementProps, emptyElement, } from '../services/domUtilities';
import { getDescendantProperty, mapFlatpickrDateFormatWithFieldType, mapMomentDateFormatWithFieldType, } from './../services/utilities';
import type { TranslaterService } from '../services/translater.service';
Expand Down Expand Up @@ -161,7 +160,7 @@ export class DateEditor implements Editor {
);

// show clear date button (unless user specifically doesn't want it)
if (!getEditorOptionByName<FlatpickrOption, 'hideClearButton'>(this.columnEditor, 'hideClearButton', undefined, 'date')) {
if (!(this.columnEditor.editorOptions as FlatpickrOption)?.hideClearButton) {
closeButtonGroupElm.appendChild(this._clearButtonElm);
this._editorInputGroupElm.appendChild(closeButtonGroupElm);
this._bindEventService.bind(this._clearButtonElm, 'click', () => this._lastTriggeredByClearDate = true);
Expand Down
18 changes: 0 additions & 18 deletions packages/common/src/editors/editorUtilities.ts

This file was deleted.

27 changes: 13 additions & 14 deletions packages/common/src/editors/sliderEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
GridOption,
SliderOption,
} from '../interfaces/index';
import { getEditorOptionByName } from './editorUtilities';
import { getDescendantProperty } from '../services/utilities';
import { sliderValidator } from '../editorValidators/sliderValidator';
import { createDomElement } from '../services/domUtilities';
Expand Down Expand Up @@ -91,7 +90,7 @@ export class SliderEditor implements Editor {

/** Get the Validator function, can be passed in Editor property or Column Definition */
get validator(): EditorValidator | undefined {
return this.columnEditor?.validator ?? this.columnDef?.validator;
return this.columnEditor.validator ?? this.columnDef?.validator;
}

init(): void {
Expand Down Expand Up @@ -201,7 +200,7 @@ export class SliderEditor implements Editor {
if (isComplexObject) {
// when it's a complex object, user could override the object path (where the editable object is located)
// else we use the path provided in the Field Column Definition
const objectPath = this.columnEditor?.complexObjectPath ?? fieldName ?? '';
const objectPath = this.columnEditor.complexObjectPath ?? fieldName ?? '';
setDeepValue(item, objectPath, newValue);
} else if (item) {
item[fieldName] = newValue;
Expand Down Expand Up @@ -311,19 +310,19 @@ export class SliderEditor implements Editor {
*/
protected buildDomElement(): HTMLDivElement {
const columnId = this.columnDef?.id ?? '';
const title = this.columnEditor?.title ?? '';
const minValue = +(this.columnEditor?.minValue ?? Constants.SLIDER_DEFAULT_MIN_VALUE);
const maxValue = +(this.columnEditor?.maxValue ?? Constants.SLIDER_DEFAULT_MAX_VALUE);
const step = +(this.columnEditor?.valueStep ?? Constants.SLIDER_DEFAULT_STEP);
const defaultValue = getEditorOptionByName<SliderOption, 'sliderStartValue'>(this.columnEditor, 'sliderStartValue') ?? minValue;
const title = this.columnEditor.title ?? '';
const minValue = +(this.columnEditor.minValue ?? Constants.SLIDER_DEFAULT_MIN_VALUE);
const maxValue = +(this.columnEditor.maxValue ?? Constants.SLIDER_DEFAULT_MAX_VALUE);
const step = +(this.columnEditor.valueStep ?? Constants.SLIDER_DEFAULT_STEP);
const defaultValue = (this.columnEditor.editorOptions as SliderOption)?.sliderStartValue ?? minValue;
this._defaultValue = +defaultValue;

this._sliderTrackElm = createDomElement('div', { className: 'slider-track' });
this._inputElm = createDomElement('input', {
type: 'range', title,
defaultValue: `${defaultValue}`, value: `${defaultValue}`, min: `${minValue}`, max: `${maxValue}`,
step: `${this.columnEditor?.valueStep ?? Constants.SLIDER_DEFAULT_STEP}`,
ariaLabel: this.columnEditor?.ariaLabel ?? `${toSentenceCase(columnId + '')} Slider Editor`,
step: `${this.columnEditor.valueStep ?? Constants.SLIDER_DEFAULT_STEP}`,
ariaLabel: this.columnEditor.ariaLabel ?? `${toSentenceCase(columnId + '')} Slider Editor`,
className: `slider-editor-input editor-${columnId}`,
});

Expand All @@ -333,7 +332,7 @@ export class SliderEditor implements Editor {
sliderInputContainerElm.appendChild(this._inputElm);
divContainerElm.appendChild(sliderInputContainerElm);

if (!getEditorOptionByName<SliderOption, 'hideSliderNumber'>(this.columnEditor, 'hideSliderNumber')) {
if (!(this.columnEditor.editorOptions as SliderOption)?.hideSliderNumber) {
divContainerElm.classList.add('input-group');

const divGroupAddonElm = createDomElement('div', { className: 'input-group-addon input-group-append slider-value' });
Expand Down Expand Up @@ -371,7 +370,7 @@ export class SliderEditor implements Editor {
protected handleChangeSliderNumber(event: Event) {
const value = (<HTMLInputElement>event.target)?.value ?? '';
if (value !== '') {
if (!getEditorOptionByName<SliderOption, 'hideSliderNumber'>(this.columnEditor, 'hideSliderNumber') && this._sliderNumberElm) {
if (!(this.columnEditor.editorOptions as SliderOption)?.hideSliderNumber && this._sliderNumberElm) {
this._sliderNumberElm.textContent = value;
}
this._inputElm.title = value;
Expand Down Expand Up @@ -426,12 +425,12 @@ export class SliderEditor implements Editor {
}

protected updateTrackFilledColorWhenEnabled() {
if (getEditorOptionByName<SliderOption, 'enableSliderTrackColoring'>(this.columnEditor, 'enableSliderTrackColoring') && this._inputElm) {
if ((this.columnEditor.editorOptions as SliderOption)?.enableSliderTrackColoring && this._inputElm) {
const percent1 = 0;
const percent2 = ((+this.getValue() - +this._inputElm.min) / (this.sliderOptions?.maxValue ?? 0 - +this._inputElm.min)) * 100;
const bg = 'linear-gradient(to right, %b %p1, %c %p1, %c %p2, %b %p2)'
.replace(/%b/g, '#eee')
.replace(/%c/g, (getEditorOptionByName<SliderOption, 'sliderTrackFilledColor'>(this.columnEditor, 'sliderTrackFilledColor') ?? 'var(--slick-slider-filter-thumb-color, #86bff8)') as string)
.replace(/%c/g, ((this.columnEditor.editorOptions as SliderOption)?.sliderTrackFilledColor ?? 'var(--slick-slider-filter-thumb-color, #86bff8)') as string)
.replace(/%p1/g, `${percent1}%`)
.replace(/%p2/g, `${percent2}%`);

Expand Down
11 changes: 0 additions & 11 deletions packages/common/src/extensions/__tests__/slickHeaderMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,6 @@ describe('HeaderMenu Plugin', () => {
plugin.dispose();
});

it('should display a console warning when using deprecated "items" instead of "commandItems"', () => {
plugin.dispose();
plugin.init({ buttonCssClass: 'mdi mdi-chevron-down' });
columnsMock[0].header!.menu!.items = columnsMock[0].header!.menu!.commandItems;

const eventData = { ...new SlickEventData(), preventDefault: jest.fn() };
gridStub.onHeaderCellRendered.notify({ column: columnsMock[0], node: headerDiv, grid: gridStub }, eventData as any, gridStub);

expect(consoleWarnSpy).toHaveBeenCalledWith('[Slickgrid-Universal] Header Menu "items" property was deprecated in favor of "commandItems" to align with all other Menu plugins.');
});

it('should populate a Header Menu button with extra button css classes when header menu option "buttonCssClass" and cell is being rendered', () => {
plugin.dispose();
plugin.init({ buttonCssClass: 'mdi mdi-chevron-down' });
Expand Down
5 changes: 2 additions & 3 deletions packages/common/src/extensions/menuBaseClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
HeaderButton,
HeaderButtonItem,
HeaderMenu,
HeaderMenuCommandItem,
MenuCommandItem,
MenuOptionItem,
} from '../interfaces/index';
Expand Down Expand Up @@ -257,7 +256,7 @@ export class MenuBaseClass<M extends CellMenu | ContextMenu | GridMenu | HeaderM

if ((item as MenuCommandItem | MenuOptionItem).iconCssClass) {
iconElm.classList.add(...(item as MenuCommandItem | MenuOptionItem).iconCssClass!.split(' '));
} else if (!(item as MenuCommandItem).commandItems && !(item as MenuOptionItem).optionItems && !(item as HeaderMenuCommandItem).items) {
} else if (!(item as MenuCommandItem).commandItems && !(item as MenuOptionItem).optionItems) {
iconElm.textContent = '◦';
}

Expand Down Expand Up @@ -297,7 +296,7 @@ export class MenuBaseClass<M extends CellMenu | ContextMenu | GridMenu | HeaderM
}

// the option/command item could be a sub-menu if it has another list of commands/options
if ((item as MenuCommandItem).commandItems || (item as MenuOptionItem).optionItems || (item as HeaderMenuCommandItem).items) {
if ((item as MenuCommandItem).commandItems || (item as MenuOptionItem).optionItems) {
const chevronElm = document.createElement('span');
chevronElm.className = 'sub-item-chevron';
if ((this._addonOptions as any).subItemChevronClass) {
Expand Down
3 changes: 1 addition & 2 deletions packages/common/src/extensions/menuFromCellBaseClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
CellMenu,
ContextMenu,
DOMMouseOrTouchEvent,
HeaderMenuCommandItem,
MenuCallbackArgs,
MenuCommandItem,
MenuCommandItemCallbackArgs,
Expand Down Expand Up @@ -264,7 +263,7 @@ export class MenuFromCellBaseClass<M extends CellMenu | ContextMenu> extends Men

protected handleMenuItemMouseOver(e: DOMMouseOrTouchEvent<HTMLElement>, type: MenuType, item: ExtractMenuType<ExtendableItemTypes, MenuType>, level = 0) {
if ((item as never)?.[type] !== undefined && item !== 'divider' && !item.disabled && !(item as MenuCommandItem | MenuOptionItem).divider) {
if ((item as MenuCommandItem).commandItems || (item as MenuOptionItem).optionItems || (item as HeaderMenuCommandItem).items) {
if ((item as MenuCommandItem).commandItems || (item as MenuOptionItem).optionItems) {
this.repositionSubMenu(item, type, level, e);
this._lastMenuTypeClicked = type;
} else if (level === 0) {
Expand Down
Loading