Skip to content

Commit a437a97

Browse files
committed
GridCore: rename some methods for clarity
1 parent e612d24 commit a437a97

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

packages/devextreme/js/__internal/grids/grid_core/header_panel/__tests__/m_header_panel.integration.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ describe('HeaderPanel', () => {
1818
});
1919
afterEach(afterTest);
2020

21-
describe('addToolbarItem', () => {
22-
it('should add a toolbar item and make header panel visible', async () => {
21+
describe('setToolbarItem', () => {
22+
it('should set a toolbar item and make header panel visible', async () => {
2323
const { instance } = await createDataGrid({
2424
dataSource: [{ id: 1 }],
2525
});
2626
const headerPanel = getHeaderPanel(instance);
2727

2828
expect(headerPanel.isVisible()).toBe(false);
2929

30-
headerPanel.addToolbarItem('customButton', {
30+
headerPanel.setToolbarItem('customButton', {
3131
widget: 'dxButton',
3232
options: { text: 'Custom' },
3333
location: 'after',
@@ -41,20 +41,20 @@ describe('HeaderPanel', () => {
4141
expect($toolbar.length).toBe(1);
4242
});
4343

44-
it('should replace an existing item when adding with the same name', async () => {
44+
it('should replace an existing item when setting with the same name', async () => {
4545
const { instance } = await createDataGrid({
4646
dataSource: [{ id: 1 }],
4747
});
4848
const headerPanel = getHeaderPanel(instance);
4949

50-
headerPanel.addToolbarItem('myItem', {
50+
headerPanel.setToolbarItem('myItem', {
5151
text: 'First',
5252
location: 'before',
5353
name: 'myItem',
5454
sortIndex: 10,
5555
});
5656

57-
headerPanel.addToolbarItem('myItem', {
57+
headerPanel.setToolbarItem('myItem', {
5858
text: 'Replaced',
5959
location: 'after',
6060
name: 'myItem',
@@ -67,7 +67,7 @@ describe('HeaderPanel', () => {
6767
expect(items[0].text).toBe('Replaced');
6868
});
6969

70-
it('should call _invalidate when adding item after first render', async () => {
70+
it('should call _invalidate when setting item after first render', async () => {
7171
const { instance } = await createDataGrid({
7272
dataSource: [{ id: 1 }],
7373
searchPanel: { visible: true },
@@ -76,7 +76,7 @@ describe('HeaderPanel', () => {
7676
const headerPanel = getHeaderPanel(instance);
7777
const invalidateSpy = jest.spyOn(headerPanel, '_invalidate');
7878

79-
headerPanel.addToolbarItem('customButton', {
79+
headerPanel.setToolbarItem('customButton', {
8080
text: 'Custom',
8181
location: 'after',
8282
name: 'customButton',
@@ -85,7 +85,7 @@ describe('HeaderPanel', () => {
8585
expect(invalidateSpy).toHaveBeenCalled();
8686
});
8787

88-
it('should not call _invalidate when adding item before first render', async () => {
88+
it('should not call _invalidate when setting item before first render', async () => {
8989
const { instance } = await createDataGrid({
9090
dataSource: [{ id: 1 }],
9191
});
@@ -96,7 +96,7 @@ describe('HeaderPanel', () => {
9696

9797
const invalidateSpy = jest.spyOn(headerPanel, '_invalidate');
9898

99-
headerPanel.addToolbarItem('test', {
99+
headerPanel.setToolbarItem('test', {
100100
text: 'Test',
101101
name: 'test',
102102
});
@@ -108,14 +108,14 @@ describe('HeaderPanel', () => {
108108
});
109109

110110
describe('removeToolbarItem', () => {
111-
it('should remove a previously added item', async () => {
111+
it('should remove a previously set item', async () => {
112112
const { instance } = await createDataGrid({
113113
dataSource: [{ id: 1 }],
114114
});
115115

116116
const headerPanel = getHeaderPanel(instance);
117117

118-
headerPanel.addToolbarItem('toRemove', {
118+
headerPanel.setToolbarItem('toRemove', {
119119
text: 'Remove me',
120120
location: 'after',
121121
name: 'toRemove',
@@ -150,7 +150,7 @@ describe('HeaderPanel', () => {
150150

151151
const headerPanel = getHeaderPanel(instance);
152152

153-
headerPanel.addToolbarItem('temp', {
153+
headerPanel.setToolbarItem('temp', {
154154
text: 'Temp',
155155
name: 'temp',
156156
});
@@ -172,13 +172,13 @@ describe('HeaderPanel', () => {
172172

173173
const headerPanel = getHeaderPanel(instance);
174174

175-
headerPanel.addToolbarItem('c', {
175+
headerPanel.setToolbarItem('c', {
176176
text: 'C', name: 'c', sortIndex: 30, location: 'after',
177177
});
178-
headerPanel.addToolbarItem('a', {
178+
headerPanel.setToolbarItem('a', {
179179
text: 'A', name: 'a', sortIndex: 10, location: 'after',
180180
});
181-
headerPanel.addToolbarItem('b', {
181+
headerPanel.setToolbarItem('b', {
182182
text: 'B', name: 'b', sortIndex: 20, location: 'after',
183183
});
184184

@@ -196,10 +196,10 @@ describe('HeaderPanel', () => {
196196

197197
const headerPanel = getHeaderPanel(instance);
198198

199-
headerPanel.addToolbarItem('withIndex', {
199+
headerPanel.setToolbarItem('withIndex', {
200200
text: 'With', name: 'withIndex', sortIndex: 10, location: 'after',
201201
});
202-
headerPanel.addToolbarItem('noIndex', {
202+
headerPanel.setToolbarItem('noIndex', {
203203
text: 'No', name: 'noIndex', location: 'before',
204204
});
205205

@@ -217,10 +217,10 @@ describe('HeaderPanel', () => {
217217

218218
const headerPanel = getHeaderPanel(instance);
219219

220-
headerPanel.addToolbarItem('b', {
220+
headerPanel.setToolbarItem('b', {
221221
text: 'B', name: 'b', sortIndex: 20, location: 'after',
222222
});
223-
headerPanel.addToolbarItem('a', {
223+
headerPanel.setToolbarItem('a', {
224224
text: 'A', name: 'a', sortIndex: 10, location: 'after',
225225
});
226226

@@ -235,17 +235,17 @@ describe('HeaderPanel', () => {
235235
});
236236

237237
describe('_getToolbarItems', () => {
238-
it('should return items added via addToolbarItem', async () => {
238+
it('should return items set via setToolbarItem', async () => {
239239
const { instance } = await createDataGrid({
240240
dataSource: [{ id: 1 }],
241241
});
242242

243243
const headerPanel = getHeaderPanel(instance);
244244

245-
headerPanel.addToolbarItem('item1', {
245+
headerPanel.setToolbarItem('item1', {
246246
text: 'Item 1', name: 'item1', location: 'before',
247247
});
248-
headerPanel.addToolbarItem('item2', {
248+
headerPanel.setToolbarItem('item2', {
249249
text: 'Item 2', name: 'item2', location: 'after',
250250
});
251251

@@ -268,16 +268,16 @@ describe('HeaderPanel', () => {
268268
});
269269
});
270270

271-
describe('items from extensions and addToolbarItem combined', () => {
272-
it('should include items from both extensions and addToolbarItem', async () => {
271+
describe('items from extensions and setToolbarItem combined', () => {
272+
it('should include items from both extensions and setToolbarItem', async () => {
273273
const { instance } = await createDataGrid({
274274
dataSource: [{ id: 1 }],
275275
columnChooser: { enabled: true },
276276
});
277277

278278
const headerPanel = getHeaderPanel(instance);
279279

280-
headerPanel.addToolbarItem('customItem', {
280+
headerPanel.setToolbarItem('customItem', {
281281
text: 'Custom',
282282
name: 'customItem',
283283
location: 'after',
@@ -300,7 +300,7 @@ describe('HeaderPanel', () => {
300300

301301
const headerPanel = getHeaderPanel(instance);
302302

303-
headerPanel.addToolbarItem('middleItem', {
303+
headerPanel.setToolbarItem('middleItem', {
304304
text: 'Middle',
305305
name: 'middleItem',
306306
location: 'after',
@@ -332,7 +332,7 @@ describe('HeaderPanel', () => {
332332

333333
const headerPanel = getHeaderPanel(instance);
334334

335-
headerPanel.addToolbarItem('toRemove', {
335+
headerPanel.setToolbarItem('toRemove', {
336336
text: 'Remove',
337337
name: 'toRemove',
338338
location: 'after',

packages/devextreme/js/__internal/grids/grid_core/header_panel/m_header_panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class HeaderPanel extends ColumnsView {
4141
this.createAction('onToolbarPreparing', { excludeValidators: ['disabled', 'readOnly'] });
4242
}
4343

44-
public addToolbarItem(name: string, item: ToolbarItem): void {
45-
this._registeredToolbarItems.set(name, item);
44+
public setToolbarItem(name: string, item: ToolbarItem): void {
45+
this._registeredToolbarItems.set(name, { ...item, name });
4646

4747
if (this._$element) {
4848
this._invalidate();

packages/devextreme/js/__internal/grids/grid_core/search/m_search.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class SearchPanelViewController extends modules.ViewController {
145145
this._headerPanel = this.getView('headerPanel');
146146
this._dataController = this.getController('data');
147147

148-
this._updateSearchPanelItem();
148+
this._syncSearchPanelItem();
149149
}
150150

151151
public optionChanged(args: OptionChanged): void {
@@ -155,10 +155,8 @@ export class SearchPanelViewController extends modules.ViewController {
155155
if (editor) {
156156
editor.option('value', args.value);
157157
}
158-
}
159-
160-
if (args.fullName === 'searchPanel.visible') {
161-
this._updateSearchPanelItem();
158+
} else {
159+
this._syncSearchPanelItem();
162160
}
163161

164162
args.handled = true;
@@ -167,7 +165,7 @@ export class SearchPanelViewController extends modules.ViewController {
167165
}
168166
}
169167

170-
private _updateSearchPanelItem(): void {
168+
private _syncSearchPanelItem(): void {
171169
if (!this._headerPanel) {
172170
return;
173171
}
@@ -178,7 +176,7 @@ export class SearchPanelViewController extends modules.ViewController {
178176
const searchPanelToolbarItem = this._getSearchPanelToolbarItem();
179177

180178
if (searchPanelToolbarItem) {
181-
this._headerPanel.addToolbarItem(SEARCH_PANEL_ITEM_NAME, searchPanelToolbarItem);
179+
this._headerPanel.setToolbarItem(SEARCH_PANEL_ITEM_NAME, searchPanelToolbarItem);
182180
}
183181
} else {
184182
this._headerPanel.removeToolbarItem(SEARCH_PANEL_ITEM_NAME);

0 commit comments

Comments
 (0)