Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Sort asset types in alphabetical order for child asset select field (#1882)

Pawan Bhattarai3e02f7a98826
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index 57df72d4f..179d7cc7c 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -17,7 +17,8 @@ import {
WellknownMetaItems,
WellknownValueTypes,
AssetModelUtil,
- ClientRole
+ ClientRole,
+ ValueConstraintAllowedValues
} from "@openremote/model";
import manager, {subscribe, Util} from "@openremote/core";
import "@openremote/or-mwc-components/or-mwc-input";
@@ -550,6 +551,18 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
}
}
+ // Sort asset type options in alphabetical order
+ if(this._valueDescriptor && this._valueDescriptor.name == WellknownValueTypes.ASSETTYPE) {
+ const allowedValuesConstraint = this._valueDescriptor.constraints?.find(
+ (constraint): constraint is ValueConstraintAllowedValues =>
+ (constraint as ValueConstraintAllowedValues).type === "allowedValues"
+ );
+
+ if (allowedValuesConstraint && allowedValuesConstraint.allowedValues) {
+ allowedValuesConstraint.allowedValues.sort((a, b) => a.localeCompare(b));
+ }
+ }
+
this._updateTemplate();
}