Skip to content

Commit

Permalink
Fixes #227: Make sure entity selection works if service contains only…
Browse files Browse the repository at this point in the history
… a single entity instead of a list of entities.
  • Loading branch information
cgiesche committed Jan 28, 2024
1 parent d444b09 commit 76f7ba9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/ServiceCallConfiguration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ const domainEntities = computed(() => {
return [];
}
let selectedService = props.availableServices.filter(service => service.serviceId === props.modelValue.serviceId)[0]
if (selectedService && selectedService.target && Array.isArray(selectedService.target.entity)) {
let targetDomains = selectedService.target.entity.filter(entity => entity.domain).flatMap(entity => entity.domain);
if (selectedService && selectedService.target && selectedService.target.entity) {
// target.entity may contain a single or an array of entities. Make sure we always work with array.
let targetEntities = ensureArray(selectedService.target.entity);
let targetDomains = targetEntities.filter(entity => entity.domain).flatMap(entity => ensureArray(entity.domain));
if (targetDomains.length > 0) {
return props.availableEntities.filter(entity => targetDomains.includes(entity.domain)).sort(titleSort);
} else {
Expand All @@ -173,7 +175,11 @@ const serviceDataInvalidFeedback = computed(() => {
return "";
}
try {
const renderedServiceData = nunjucks.renderString(serviceDataString, {ticks: 5, rotationPercent: 100, rotationAbsolute: 100});
const renderedServiceData = nunjucks.renderString(serviceDataString, {
ticks: 5,
rotationPercent: 100,
rotationAbsolute: 100
});
const json = JSON.parse(renderedServiceData);
return (typeof json === "object") ? "" : "Service data must be an JSON object."
Expand All @@ -199,4 +205,8 @@ const dataProperties = computed(() => {
})
function ensureArray(input) {
return Array.isArray(input) ? input : [input];
}
</script>

0 comments on commit 76f7ba9

Please sign in to comment.