forked from p15670423/monkey
ui: sort checkbox options alphabetically
Alphabetically sort options in AdvancedMultiSelect to improve usability. Float "unsafe" options to the bottom so they are grouped together.
This commit is contained in:
parent
08926d778b
commit
e77868b656
|
@ -33,10 +33,10 @@ class AdvancedMultiSelect extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.enumOptions = props.options.enumOptions;
|
|
||||||
this.defaultValues = props.schema.default;
|
this.defaultValues = props.schema.default;
|
||||||
this.infoPaneRefString = props.schema.items.$ref;
|
this.infoPaneRefString = props.schema.items.$ref;
|
||||||
this.registry = props.registry;
|
this.registry = props.registry;
|
||||||
|
this.enumOptions = props.options.enumOptions.sort(this.compareOptions);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
masterCheckboxState: this.getMasterCheckboxState(props.value),
|
masterCheckboxState: this.getMasterCheckboxState(props.value),
|
||||||
|
@ -49,6 +49,27 @@ class AdvancedMultiSelect extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort options alphabetically. "Unsafe" options float to the bottom"
|
||||||
|
compareOptions = (a, b) => {
|
||||||
|
if (!this.isSafe(a.value) && this.isSafe(b.value)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isSafe(a.value) && !this.isSafe(b.value)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.value < b.value) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.value > b.value) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
onMasterCheckboxClick = () => {
|
onMasterCheckboxClick = () => {
|
||||||
if (this.state.masterCheckboxState === MasterCheckboxState.ALL) {
|
if (this.state.masterCheckboxState === MasterCheckboxState.ALL) {
|
||||||
var newValues = [];
|
var newValues = [];
|
||||||
|
|
Loading…
Reference in New Issue