orc-shared 5.8.0-dev.16 → 5.8.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/MaterialUI/Inputs/Select.js +14 -1
- package/dist/components/MaterialUI/Inputs/SelectProps.js +2 -1
- package/package.json +1 -1
- package/src/components/MaterialUI/Inputs/Select.js +13 -1
- package/src/components/MaterialUI/Inputs/Select.test.js +37 -0
- package/src/components/MaterialUI/Inputs/SelectProps.js +1 -0
|
@@ -185,6 +185,7 @@ __signature__(SelectIconButton, "useStyles{classes}", function () {
|
|
|
185
185
|
__signature__(SelectIconButton, "useStyles{classes}", function () {
|
|
186
186
|
return [useStyles];
|
|
187
187
|
});
|
|
188
|
+
var selectEmptyValue = "~~#~~";
|
|
188
189
|
var Select = function Select(_ref) {
|
|
189
190
|
var _selectProps$get;
|
|
190
191
|
var options = _ref.options,
|
|
@@ -222,6 +223,16 @@ var Select = function Select(_ref) {
|
|
|
222
223
|
options.sort(function (a, b) {
|
|
223
224
|
return a.sortOrder > b.sortOrder ? 1 : -1;
|
|
224
225
|
});
|
|
226
|
+
} else if (sortType === _SelectProps.sortTypeEnum.alphabetical) {
|
|
227
|
+
options.sort(function (a, b) {
|
|
228
|
+
if (a.value === selectEmptyValue) {
|
|
229
|
+
return -1;
|
|
230
|
+
}
|
|
231
|
+
if (b.value === selectEmptyValue) {
|
|
232
|
+
return 1;
|
|
233
|
+
}
|
|
234
|
+
return a.label.localeCompare(b.label);
|
|
235
|
+
});
|
|
225
236
|
}
|
|
226
237
|
if (showAllValue && showAllLabel) {
|
|
227
238
|
options.unshift({
|
|
@@ -245,7 +256,7 @@ var Select = function Select(_ref) {
|
|
|
245
256
|
var items = options == null ? void 0 : options.map(function (option) {
|
|
246
257
|
var clss = option != null && option.level ? classes["level" + option.level] : "";
|
|
247
258
|
var appliedClasses = (0, _classnames.default)(classes.baseItem, clss);
|
|
248
|
-
var labelClss = (0, _classnames.default)(_defineProperty(_defineProperty({}, classes.label, true), classes.emptyLabel, option.value === "" || option.value ===
|
|
259
|
+
var labelClss = (0, _classnames.default)(_defineProperty(_defineProperty({}, classes.label, true), classes.emptyLabel, option.value === "" || option.value === selectEmptyValue));
|
|
249
260
|
var disabled = !!option.disabled;
|
|
250
261
|
var groupHeader = !!option.isGroupHeader;
|
|
251
262
|
if (groupHeader) {
|
|
@@ -332,6 +343,7 @@ var _default3 = exports.default = _default2;
|
|
|
332
343
|
reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
333
344
|
reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
334
345
|
reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
346
|
+
reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
335
347
|
reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
336
348
|
reactHotLoader.register(_default, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
337
349
|
})();
|
|
@@ -351,6 +363,7 @@ var _default3 = exports.default = _default2;
|
|
|
351
363
|
reactHotLoader.register(getIconButtonMenuProps, "getIconButtonMenuProps", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
352
364
|
reactHotLoader.register(SelectIcon, "SelectIcon", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
353
365
|
reactHotLoader.register(SelectIconButton, "SelectIconButton", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
366
|
+
reactHotLoader.register(selectEmptyValue, "selectEmptyValue", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
354
367
|
reactHotLoader.register(Select, "Select", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
355
368
|
reactHotLoader.register(_default2, "default", "/home/vsts/work/1/s/src/components/MaterialUI/Inputs/Select.js");
|
|
356
369
|
})();
|
|
@@ -26,7 +26,8 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
|
|
|
26
26
|
var sortTypeEnum = exports.sortTypeEnum = {
|
|
27
27
|
none: 0,
|
|
28
28
|
default: 1,
|
|
29
|
-
numeric: 2
|
|
29
|
+
numeric: 2,
|
|
30
|
+
alphabetical: 3
|
|
30
31
|
};
|
|
31
32
|
var SelectProps = /*#__PURE__*/function (_ComponentProps) {
|
|
32
33
|
function SelectProps() {
|
package/package.json
CHANGED
|
@@ -145,6 +145,8 @@ export const SelectIconButton = props => {
|
|
|
145
145
|
);
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
+
const selectEmptyValue = "~~#~~";
|
|
149
|
+
|
|
148
150
|
const Select = ({ options, selectProps, children }) => {
|
|
149
151
|
if (isSelectProps(selectProps) === false) {
|
|
150
152
|
throw new TypeError("selectProps property is not of type SelectProps");
|
|
@@ -177,6 +179,16 @@ const Select = ({ options, selectProps, children }) => {
|
|
|
177
179
|
);
|
|
178
180
|
} else if (sortType === sortTypeEnum.default) {
|
|
179
181
|
options.sort((a, b) => (a.sortOrder > b.sortOrder ? 1 : -1));
|
|
182
|
+
} else if (sortType === sortTypeEnum.alphabetical) {
|
|
183
|
+
options.sort((a, b) => {
|
|
184
|
+
if (a.value === selectEmptyValue) {
|
|
185
|
+
return -1;
|
|
186
|
+
}
|
|
187
|
+
if (b.value === selectEmptyValue) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
return a.label.localeCompare(b.label);
|
|
191
|
+
});
|
|
180
192
|
}
|
|
181
193
|
|
|
182
194
|
if (showAllValue && showAllLabel) {
|
|
@@ -207,7 +219,7 @@ const Select = ({ options, selectProps, children }) => {
|
|
|
207
219
|
const appliedClasses = classNames(classes.baseItem, clss);
|
|
208
220
|
const labelClss = classNames({
|
|
209
221
|
[classes.label]: true,
|
|
210
|
-
[classes.emptyLabel]: option.value === "" || option.value ===
|
|
222
|
+
[classes.emptyLabel]: option.value === "" || option.value === selectEmptyValue,
|
|
211
223
|
});
|
|
212
224
|
|
|
213
225
|
const disabled = !!option.disabled;
|
|
@@ -496,6 +496,43 @@ describe("Select Component", () => {
|
|
|
496
496
|
expect(optionsKeys, "to equal", ["#All#", "a", "b", "c"]);
|
|
497
497
|
});
|
|
498
498
|
|
|
499
|
+
it("Sorts select options correctly with alphabetical sorting", () => {
|
|
500
|
+
const emptyValue = "~~#~~";
|
|
501
|
+
|
|
502
|
+
const options = [
|
|
503
|
+
{ value: "c", label: "c" },
|
|
504
|
+
{ value: "a", label: "a" },
|
|
505
|
+
{ value: "b", label: "b" },
|
|
506
|
+
{ value: "f", label: "f" },
|
|
507
|
+
{ value: emptyValue, label: "empty" },
|
|
508
|
+
{ value: "h", label: "h" },
|
|
509
|
+
{ value: "g", label: "g" },
|
|
510
|
+
{ value: "e", label: "e" },
|
|
511
|
+
{ value: "d", label: "[d]" },
|
|
512
|
+
];
|
|
513
|
+
|
|
514
|
+
const selectProps = new SelectProps();
|
|
515
|
+
|
|
516
|
+
selectProps.set(SelectProps.propNames.sortType, sortTypeEnum.alphabetical);
|
|
517
|
+
selectProps.set(SelectProps.propNames.value, "b");
|
|
518
|
+
|
|
519
|
+
const component = (
|
|
520
|
+
<TestWrapper stylesProvider muiThemeProvider={{ theme }}>
|
|
521
|
+
<Select options={options} selectProps={selectProps} />
|
|
522
|
+
</TestWrapper>
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
const mountedComponent = mount(component);
|
|
526
|
+
|
|
527
|
+
const test = mountedComponent.find(SelectMUI);
|
|
528
|
+
|
|
529
|
+
const mountedOptions = test.props().children;
|
|
530
|
+
|
|
531
|
+
const optionsKeys = mountedOptions.map(option => option.key);
|
|
532
|
+
|
|
533
|
+
expect(optionsKeys, "to equal", [emptyValue, "d", "a", "b", "c", "e", "f", "g", "h"]);
|
|
534
|
+
});
|
|
535
|
+
|
|
499
536
|
it("Sorts select options correctly with numeric sorting", () => {
|
|
500
537
|
const options = [
|
|
501
538
|
{ value: "BRC-409 - BRC-PROMENADES", label: "BRC-409 - BRC-PROMENADES", sortOrder: "BRC-409 - BRC-PROMENADES" },
|