@grafana/ui
Version:
Grafana Components Library
37 lines (35 loc) • 1.01 kB
JavaScript
;
const cleanValue = (value, options) => {
if (Array.isArray(value)) {
const filtered = value.filter(Boolean);
return (filtered == null ? void 0 : filtered.length) ? filtered : void 0;
}
if (typeof value === "object") {
return [value];
}
if (typeof value === "string" || typeof value === "number") {
const selectedValue = findSelectedValue(value, options);
if (selectedValue) {
return [selectedValue];
}
}
return void 0;
};
const findSelectedValue = (value, options) => {
for (const option of options) {
if ("options" in option) {
let found = findSelectedValue(value, option.options);
if (found) {
return found;
}
} else if ("value" in option && option.value === value) {
return option;
}
}
return null;
};
const omitDescriptions = (options) => {
return options.map(({ description, ...rest }) => rest);
};
export { cleanValue, findSelectedValue, omitDescriptions };
//# sourceMappingURL=utils.mjs.map