Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit d7e84f5

Browse files
Issue 171 - Rename sorting_settings columnId -> column_id (#183)
* - update sort_settings to use column_id * update tests with column_id * update doc
1 parent 5be420b commit d7e84f5

File tree

13 files changed

+67
-68
lines changed

13 files changed

+67
-68
lines changed

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ Derived properties allow the component to expose complex state that can be usefu
399399

400400
## RC8 - Improve props typing
401401

402-
Issue: https://github.com/plotly/dash-table/issues/143
402+
Issue: https://github.com/plotly/dash-table/issues/143
403403

404404
## RC9 - Sort ascending on first click
405405

@@ -422,4 +422,8 @@ Derived properties allow the component to expose complex state that can be usefu
422422
## RC13 - Allow keyboard navigation on focused input
423423

424424
Issue: https://github.com/plotly/dash-table/issues/141
425-
Issue: https://github.com/plotly/dash-table/issues/143
425+
Issue: https://github.com/plotly/dash-table/issues/143
426+
427+
## RC14 - Rename sorting_settings columnId -> column_id
428+
429+
Issue: https://github.com/plotly/dash-table/issues/171

dash_table/bundle.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_table/demo.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_table/metadata.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@
670670
"value": {
671671
"name": "shape",
672672
"value": {
673-
"columnId": {
673+
"column_id": {
674674
"name": "union",
675675
"value": [
676676
{
@@ -700,7 +700,7 @@
700700
}
701701
},
702702
"required": false,
703-
"description": "`sorting_settings` describes the current state\nof the sorting UI.\nThat is, if the user clicked on the sort arrow\nof a column, then this property will be updated\nwith the column ID and the direction\n(`asc` or `desc`) of the sort.\nFor multi-column sorting, this will be a list of\nsorting parameters, in the order in which they were\nclicked.\n\nNOTE - We may rename `columnId` to `column_id` in\nthe future.\nSubscribe to [https://github.com/plotly/dash-table/issues/171](https://github.com/plotly/dash-table/issues/171)\nfor details.",
703+
"description": "`sorting_settings` describes the current state\nof the sorting UI.\nThat is, if the user clicked on the sort arrow\nof a column, then this property will be updated\nwith the column ID and the direction\n(`asc` or `desc`) of the sort.\nFor multi-column sorting, this will be a list of\nsorting parameters, in the order in which they were\nclicked.",
704704
"defaultValue": {
705705
"value": "[]",
706706
"computed": false

dash_table/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-table",
3-
"version": "3.1.0rc13",
3+
"version": "3.1.0rc14",
44
"description": "Dash table",
55
"main": "build/index.js",
66
"scripts": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-table",
3-
"version": "3.1.0rc13",
3+
"version": "3.1.0rc14",
44
"description": "Dash table",
55
"main": "build/index.js",
66
"scripts": {

src/core/sorting/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as R from 'ramda';
33
import { ColumnId } from 'dash-table/components/Table/props';
44

55
export interface ISortSetting {
6-
columnId: ColumnId;
6+
column_id: ColumnId;
77
direction: SortDirection;
88
}
99

@@ -25,7 +25,7 @@ export default (data: any[], settings: SortSettings, isNully: IsNullyFn = defaul
2525
R.map(setting => {
2626
return setting.direction === SortDirection.Descending ?
2727
R.comparator((d1: any, d2: any) => {
28-
const id = setting.columnId;
28+
const id = setting.column_id;
2929

3030
const prop1 = d1[id];
3131
const prop2 = d2[id];
@@ -39,7 +39,7 @@ export default (data: any[], settings: SortSettings, isNully: IsNullyFn = defaul
3939
return prop1 > prop2;
4040
}) :
4141
R.comparator((d1: any, d2: any) => {
42-
const id = setting.columnId;
42+
const id = setting.column_id;
4343

4444
const prop1 = d1[id];
4545
const prop2 = d2[id];

src/core/sorting/multi.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export default (
1212
settings = R.clone(settings);
1313

1414
if (setting.direction === SortDirection.None) {
15-
const currentIndex = R.findIndex(s => s.columnId === setting.columnId, settings);
15+
const currentIndex = R.findIndex(s => s.column_id === setting.column_id, settings);
1616

1717
if (currentIndex !== -1) {
1818
settings.splice(currentIndex, 1);
1919
}
2020
} else {
21-
const currentSetting = R.find(s => s.columnId === setting.columnId, settings);
21+
const currentSetting = R.find(s => s.column_id === setting.column_id, settings);
2222

2323
if (currentSetting) {
2424
currentSetting.direction = setting.direction;

src/dash-table/Table.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -584,16 +584,11 @@ export const propTypes = {
584584
* For multi-column sorting, this will be a list of
585585
* sorting parameters, in the order in which they were
586586
* clicked.
587-
*
588-
* NOTE - We may rename `columnId` to `column_id` in
589-
* the future.
590-
* Subscribe to [https://github.com/plotly/dash-table/issues/171](https://github.com/plotly/dash-table/issues/171)
591-
* for details.
592587
*/
593588
sorting_settings: PropTypes.arrayOf(
594589
// .exact
595590
PropTypes.shape({
596-
columnId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
591+
column_id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
597592
direction: PropTypes.oneOf(['asc', 'desc']).isRequired
598593
})),
599594

src/dash-table/derived/header/content.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function doSort(columnId: ColumnId, sortSettings: SortSettings, sortType: Sortin
4949
setProps({
5050
sorting_settings: sortingStrategy(
5151
sortSettings,
52-
{ columnId, direction }
52+
{ column_id: columnId, direction }
5353
)
5454
});
5555
};
@@ -62,7 +62,7 @@ function editColumnName(column: IVisibleColumn, columns: VisibleColumns, columnR
6262
}
6363

6464
function getSorting(columnId: ColumnId, settings: SortSettings): SortDirection {
65-
const setting = R.find(s => s.columnId === columnId, settings);
65+
const setting = R.find(s => s.column_id === columnId, settings);
6666

6767
return setting ? setting.direction : SortDirection.None;
6868
}

tests/cypress/dash/v_be_page.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def updateData(pagination_settings, sorting_settings):
8383
sorted_df = df.values
8484
else:
8585
sorted_df = df.sort_index(
86-
axis=sorting_settings[0]['columnId'],
86+
axis=sorting_settings[0]['column_id'],
8787
ascending=(sorting_settings[0]['direction'] == 'asc')
8888
).values
8989

tests/cypress/tests/unit/sorting_test.ts

+38-38
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('sort', () => {
77
const data = [[1], [3], [4], [2]];
88
const sorted = sort(
99
data,
10-
[{ columnId: 0, direction: SortDirection.Descending }]
10+
[{ column_id: 0, direction: SortDirection.Descending }]
1111
);
1212

1313
expect(sorted.length).to.equal(data.length);
@@ -22,7 +22,7 @@ describe('sort', () => {
2222

2323
const sorted = sort(
2424
data,
25-
[{ columnId: 0, direction: SortDirection.Descending }]
25+
[{ column_id: 0, direction: SortDirection.Descending }]
2626
);
2727

2828
expect(sorted.length).to.equal(data.length);
@@ -40,7 +40,7 @@ describe('sort', () => {
4040

4141
const sorted = sort(
4242
data,
43-
[{ columnId: 0, direction: SortDirection.Ascending }]
43+
[{ column_id: 0, direction: SortDirection.Ascending }]
4444
);
4545

4646
expect(sorted.length).to.equal(data.length);
@@ -58,7 +58,7 @@ describe('sort', () => {
5858

5959
const sorted = sort(
6060
data,
61-
[{ columnId: 0, direction: SortDirection.Descending }]
61+
[{ column_id: 0, direction: SortDirection.Descending }]
6262
);
6363

6464
expect(sorted.length).to.equal(data.length);
@@ -76,7 +76,7 @@ describe('sort', () => {
7676

7777
const sorted = sort(
7878
data,
79-
[{ columnId: 0, direction: SortDirection.Ascending }]
79+
[{ column_id: 0, direction: SortDirection.Ascending }]
8080
);
8181

8282
expect(sorted.length).to.equal(data.length);
@@ -105,8 +105,8 @@ describe('sort', () => {
105105
const sorted = sort(
106106
data,
107107
[
108-
{ columnId: 0, direction: SortDirection.Descending },
109-
{ columnId: 1, direction: SortDirection.Descending }
108+
{ column_id: 0, direction: SortDirection.Descending },
109+
{ column_id: 1, direction: SortDirection.Descending }
110110
]
111111
);
112112

@@ -135,8 +135,8 @@ describe('sort', () => {
135135
const sorted = sort(
136136
data,
137137
[
138-
{ columnId: 1, direction: SortDirection.Descending },
139-
{ columnId: 0, direction: SortDirection.Ascending }
138+
{ column_id: 1, direction: SortDirection.Descending },
139+
{ column_id: 0, direction: SortDirection.Ascending }
140140
]
141141
);
142142

@@ -153,48 +153,48 @@ describe('sort', () => {
153153
describe('sorting settings', () => {
154154
describe('single column sorting', () => {
155155
it('new descending', () => {
156-
const settings = singleUpdateSettings([], { columnId: 0, direction: SortDirection.Descending });
156+
const settings = singleUpdateSettings([], { column_id: 0, direction: SortDirection.Descending });
157157

158158
expect(settings.length).to.equal(1);
159-
expect(settings[0].columnId).to.equal(0);
159+
expect(settings[0].column_id).to.equal(0);
160160
expect(settings[0].direction).to.equal(SortDirection.Descending);
161161
});
162162

163163
it('update to descending', () => {
164164
const settings = singleUpdateSettings(
165-
[{ columnId: 0, direction: SortDirection.Ascending }],
166-
{ columnId: 0, direction: SortDirection.Descending }
165+
[{ column_id: 0, direction: SortDirection.Ascending }],
166+
{ column_id: 0, direction: SortDirection.Descending }
167167
);
168168

169169
expect(settings.length).to.equal(1);
170-
expect(settings[0].columnId).to.equal(0);
170+
expect(settings[0].column_id).to.equal(0);
171171
expect(settings[0].direction).to.equal(SortDirection.Descending);
172172
});
173173

174174
it('remove by setting to None', () => {
175175
const settings = singleUpdateSettings(
176-
[{ columnId: 0, direction: SortDirection.Ascending }],
177-
{ columnId: 0, direction: SortDirection.None }
176+
[{ column_id: 0, direction: SortDirection.Ascending }],
177+
{ column_id: 0, direction: SortDirection.None }
178178
);
179179

180180
expect(settings.length).to.equal(0);
181181
});
182182

183183
it('replace with other', () => {
184184
const settings = singleUpdateSettings(
185-
[{ columnId: 0, direction: SortDirection.Ascending }],
186-
{ columnId: 1, direction: SortDirection.Ascending }
185+
[{ column_id: 0, direction: SortDirection.Ascending }],
186+
{ column_id: 1, direction: SortDirection.Ascending }
187187
);
188188

189189
expect(settings.length).to.equal(1);
190-
expect(settings[0].columnId).to.equal(1);
190+
expect(settings[0].column_id).to.equal(1);
191191
expect(settings[0].direction).to.equal(SortDirection.Ascending);
192192
});
193193

194194
it('replace with None', () => {
195195
const settings = singleUpdateSettings(
196-
[{ columnId: 0, direction: SortDirection.Ascending }],
197-
{ columnId: 1, direction: SortDirection.None }
196+
[{ column_id: 0, direction: SortDirection.Ascending }],
197+
{ column_id: 1, direction: SortDirection.None }
198198
);
199199

200200
expect(settings.length).to.equal(0);
@@ -203,65 +203,65 @@ describe('sorting settings', () => {
203203

204204
describe('multi columns sorting', () => {
205205
it('new descending', () => {
206-
const settings = multiUpdateSettings([], { columnId: 0, direction: SortDirection.Descending });
206+
const settings = multiUpdateSettings([], { column_id: 0, direction: SortDirection.Descending });
207207

208208
expect(settings.length).to.equal(1);
209-
expect(settings[0].columnId).to.equal(0);
209+
expect(settings[0].column_id).to.equal(0);
210210
expect(settings[0].direction).to.equal(SortDirection.Descending);
211211
});
212212

213213
it('update to descending', () => {
214214
const settings = multiUpdateSettings(
215-
[{ columnId: 0, direction: SortDirection.Ascending }],
216-
{ columnId: 0, direction: SortDirection.Descending }
215+
[{ column_id: 0, direction: SortDirection.Ascending }],
216+
{ column_id: 0, direction: SortDirection.Descending }
217217
);
218218

219219
expect(settings.length).to.equal(1);
220-
expect(settings[0].columnId).to.equal(0);
220+
expect(settings[0].column_id).to.equal(0);
221221
expect(settings[0].direction).to.equal(SortDirection.Descending);
222222
});
223223

224224
it('remove by setting to None', () => {
225225
const settings = multiUpdateSettings(
226-
[{ columnId: 0, direction: SortDirection.Ascending }],
227-
{ columnId: 0, direction: SortDirection.None }
226+
[{ column_id: 0, direction: SortDirection.Ascending }],
227+
{ column_id: 0, direction: SortDirection.None }
228228
);
229229

230230
expect(settings.length).to.equal(0);
231231
});
232232

233233
it('respects order', () => {
234234
const settings = multiUpdateSettings(
235-
[{ columnId: 0, direction: SortDirection.Ascending }],
236-
{ columnId: 1, direction: SortDirection.Ascending }
235+
[{ column_id: 0, direction: SortDirection.Ascending }],
236+
{ column_id: 1, direction: SortDirection.Ascending }
237237
);
238238

239239
expect(settings.length).to.equal(2);
240-
expect(settings[0].columnId).to.equal(0);
241-
expect(settings[1].columnId).to.equal(1);
240+
expect(settings[0].column_id).to.equal(0);
241+
expect(settings[1].column_id).to.equal(1);
242242
});
243243

244244
it('respects order when removed and added back', () => {
245-
let settings: SortSettings = [{ columnId: 0, direction: SortDirection.Ascending }];
245+
let settings: SortSettings = [{ column_id: 0, direction: SortDirection.Ascending }];
246246

247247
settings = multiUpdateSettings(
248248
settings,
249-
{ columnId: 1, direction: SortDirection.Ascending }
249+
{ column_id: 1, direction: SortDirection.Ascending }
250250
);
251251

252252
settings = multiUpdateSettings(
253253
settings,
254-
{ columnId: 0, direction: SortDirection.None }
254+
{ column_id: 0, direction: SortDirection.None }
255255
);
256256

257257
settings = multiUpdateSettings(
258258
settings,
259-
{ columnId: 0, direction: SortDirection.Ascending }
259+
{ column_id: 0, direction: SortDirection.Ascending }
260260
);
261261

262262
expect(settings.length).to.equal(2);
263-
expect(settings[0].columnId).to.equal(1);
264-
expect(settings[1].columnId).to.equal(0);
263+
expect(settings[0].column_id).to.equal(1);
264+
expect(settings[1].column_id).to.equal(0);
265265
});
266266
});
267267
});

tests/visual/percy-storybook/DashTable.percy.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ storiesOf('DashTable/Sorting', module)
192192
data={sparseData}
193193
columns={mergedColumns}
194194
sorting={true}
195-
sorting_settings={[{ columnId: 'a', direction: 'asc' }]}
195+
sorting_settings={[{ column_id: 'a', direction: 'asc' }]}
196196
style_data_conditional={style_data_conditional}
197197
/>))
198198
.add('"a" descending', () => (<DashTable
@@ -201,7 +201,7 @@ storiesOf('DashTable/Sorting', module)
201201
data={sparseData}
202202
columns={mergedColumns}
203203
sorting={true}
204-
sorting_settings={[{ columnId: 'a', direction: 'desc' }]}
204+
sorting_settings={[{ column_id: 'a', direction: 'desc' }]}
205205
style_data_conditional={style_data_conditional}
206206
/>))
207207
.add('"a" ascending -- empty string override', () => (<DashTable
@@ -210,7 +210,7 @@ storiesOf('DashTable/Sorting', module)
210210
data={sparseData}
211211
columns={mergedColumns}
212212
sorting={true}
213-
sorting_settings={[{ columnId: 'a', direction: 'asc' }]}
213+
sorting_settings={[{ column_id: 'a', direction: 'asc' }]}
214214
sorting_treat_empty_string_as_none={true}
215215
style_data_conditional={style_data_conditional}
216216
/>))
@@ -220,7 +220,7 @@ storiesOf('DashTable/Sorting', module)
220220
data={sparseData}
221221
columns={mergedColumns}
222222
sorting={true}
223-
sorting_settings={[{ columnId: 'a', direction: 'desc' }]}
223+
sorting_settings={[{ column_id: 'a', direction: 'desc' }]}
224224
sorting_treat_empty_string_as_none={true}
225225
style_data_conditional={style_data_conditional}
226226
/>));

0 commit comments

Comments
 (0)