From f83dd893db7a8504801255ad7bf0761c9c4fa5f4 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Tue, 20 May 2025 22:20:55 -0700 Subject: [PATCH 1/2] fix(UI): ensure project consistency in tag validation and fetching I updated the `TagPicker.vue` component to use a `ref` for the current project, ensuring that tag validation and fetching operations are consistent with the selected project. This change prevents unnecessary data fetching and validation when the project remains unchanged. --- .../static/dispatch/src/tag/TagPicker.vue | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/dispatch/static/dispatch/src/tag/TagPicker.vue b/src/dispatch/static/dispatch/src/tag/TagPicker.vue index 305717a824a6..caaa9878620f 100644 --- a/src/dispatch/static/dispatch/src/tag/TagPicker.vue +++ b/src/dispatch/static/dispatch/src/tag/TagPicker.vue @@ -182,10 +182,15 @@ const props = defineProps({ default: false, }, }) +const currentProject = ref(props.project) watch( () => props.project, - () => { + (newVal) => { + if (newVal === currentProject.value) { + return + } + currentProject.value = newVal fetchData() validateTags(selectedItems.value) } @@ -208,6 +213,9 @@ function are_required_tags_selected(sel) { } const fetchData = () => { + if (!currentProject.value) { + return + } loading.value = true let filterOptions = { @@ -219,16 +227,9 @@ const fetchData = () => { let filters = {} - if (props.project) { - if (Array.isArray(props.project)) { - if (props.project.length > 0) { - filters["project"] = props.project - } - } else { - filters["project"] = [props.project] - } - validateTags(selectedItems.value) - } + filters["project"] = [ + { model: "Project", field: "name", op: "==", value: currentProject.value.name }, + ] // add a filter to only return discoverable tags filters["tagFilter"] = [{ model: "Tag", field: "discoverable", op: "==", value: "true" }] @@ -285,18 +286,18 @@ onMounted(fetchData) const emit = defineEmits(["update:modelValue"]) function validateTags(value) { - const project_id = props.project?.id || 0 + const project_id = currentProject.value?.id || 0 var all_tags_in_project = false if (project_id) { - all_tags_in_project = value.every((tag) => tag.project?.id == project_id) + all_tags_in_project = value.every((tag) => tag.currentProject?.id == project_id) } else { - const project_name = props.project?.name + const project_name = currentProject.value?.name if (!project_name) { error.value = true dummyText.value += " " return } - all_tags_in_project = value.every((tag) => tag.project?.name == project_name) + all_tags_in_project = value.every((tag) => tag.currentProject?.name == project_name) } if (all_tags_in_project) { if (are_required_tags_selected(value)) { From 4a2f109401c38a609ce97eb1957ee984f3793573 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Tue, 20 May 2025 22:25:21 -0700 Subject: [PATCH 2/2] correct property access for project validation I updated the property access from `currentProject` to `project` in the `validateTags` function to ensure proper validation of tags against the current project. --- src/dispatch/static/dispatch/src/tag/TagPicker.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dispatch/static/dispatch/src/tag/TagPicker.vue b/src/dispatch/static/dispatch/src/tag/TagPicker.vue index caaa9878620f..42bf093406a1 100644 --- a/src/dispatch/static/dispatch/src/tag/TagPicker.vue +++ b/src/dispatch/static/dispatch/src/tag/TagPicker.vue @@ -289,7 +289,7 @@ function validateTags(value) { const project_id = currentProject.value?.id || 0 var all_tags_in_project = false if (project_id) { - all_tags_in_project = value.every((tag) => tag.currentProject?.id == project_id) + all_tags_in_project = value.every((tag) => tag.project?.id == project_id) } else { const project_name = currentProject.value?.name if (!project_name) { @@ -297,7 +297,7 @@ function validateTags(value) { dummyText.value += " " return } - all_tags_in_project = value.every((tag) => tag.currentProject?.name == project_name) + all_tags_in_project = value.every((tag) => tag.project?.name == project_name) } if (all_tags_in_project) { if (are_required_tags_selected(value)) {