From 1e4f0afa679182b9e5ef767ea3f1a3367701aa70 Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Mon, 15 Jul 2024 18:19:04 +0200 Subject: [PATCH] use prop function createTag instead of event to make sure it is handled by the parent --- e2e/time.spec.ts | 4 ++-- .../Components/Common/Tag/TagCreateModal.vue | 9 +++++---- .../js/Components/Common/Tag/TagDropdown.vue | 19 +++++++++--------- .../js/Components/Common/Tag/TagTable.vue | 13 ++++++++---- .../TimeEntry/TimeEntryAggregateRow.vue | 6 +++--- .../Common/TimeEntry/TimeEntryCreateModal.vue | 10 +++------- .../TimeEntry/TimeEntryGroupedTable.vue | 6 +++--- .../Common/TimeEntry/TimeEntryRow.vue | 4 ++-- .../TimeEntry/TimeEntryRowTagDropdown.vue | 4 ++-- .../TimeTracker/TimeTrackerTagDropdown.vue | 4 ++-- resources/js/Components/TimeTracker.vue | 10 +++------- resources/js/Pages/Reporting.vue | 11 ++++------ resources/js/Pages/Tags.vue | 20 +++++++++---------- resources/js/Pages/Time.vue | 11 ++++------ 14 files changed, 60 insertions(+), 71 deletions(-) diff --git a/e2e/time.spec.ts b/e2e/time.spec.ts index faf06737..661d3d70 100644 --- a/e2e/time.spec.ts +++ b/e2e/time.spec.ts @@ -304,7 +304,7 @@ test('test that deleting a time entry from the overview works', async ({ await goToTimeOverview(page); const timeEntryRows = page.locator('[data-testid="time_entry_row"]'); await createEmptyTimeEntry(page); - const timeEntryCount = await timeEntryRows.count(); + await expect(timeEntryRows).toHaveCount(1); const newTimeEntry = timeEntryRows.first(); const actionsDropdown = newTimeEntry @@ -313,7 +313,7 @@ test('test that deleting a time entry from the overview works', async ({ await actionsDropdown.click(); const deleteButton = page.getByText('Delete'); await deleteButton.click(); - await expect(timeEntryRows).toHaveCount(timeEntryCount - 1); + await expect(timeEntryRows).toHaveCount(0); }); test.skip('test that load more works when the end of page is reached', async ({ diff --git a/resources/js/Components/Common/Tag/TagCreateModal.vue b/resources/js/Components/Common/Tag/TagCreateModal.vue index 689659e2..f3bd8fe0 100644 --- a/resources/js/Components/Common/Tag/TagCreateModal.vue +++ b/resources/js/Components/Common/Tag/TagCreateModal.vue @@ -13,14 +13,15 @@ const tag = ref({ name: '', }); -const emit = defineEmits<{ - createTag: [name: string, callback: (tag: Tag) => void]; +const props = defineProps<{ + createTag: (name: string) => Promise; }>(); async function submit() { - emit('createTag', tag.value.name, () => { + const newTag = props.createTag(tag.value.name); + if (newTag !== undefined) { show.value = false; - }); + } } const tagNameInput = ref(null); diff --git a/resources/js/Components/Common/Tag/TagDropdown.vue b/resources/js/Components/Common/Tag/TagDropdown.vue index 2afaa8bb..47d923c3 100644 --- a/resources/js/Components/Common/Tag/TagDropdown.vue +++ b/resources/js/Components/Common/Tag/TagDropdown.vue @@ -8,6 +8,7 @@ import type { Tag } from '@/utils/api'; const props = defineProps<{ tags: Tag[]; + createTag: (name: string) => Promise; }>(); const model = defineModel({ @@ -66,14 +67,13 @@ const filteredTags = computed(() => { }); }); -function createTag(name: string, callback: (tag: Tag) => void) { - emit('createTag', name, (newTag: Tag) => { - if (newTag) { - addOrRemoveTagFromSelection(newTag.id); - } - searchValue.value = ''; - callback(newTag); - }); +async function createAndAddTag(name: string) { + const newTag = await props.createTag(name); + if (newTag) { + addOrRemoveTagFromSelection(newTag.id); + } + searchValue.value = ''; + return newTag; } async function addTagIfNoneExists() { @@ -109,7 +109,6 @@ function updateSearchValue(event: Event) { const emit = defineEmits<{ changed: []; submit: []; - createTag: [name: string, callback: (tag: Tag) => void]; }>(); function toggleTag(newValue: string) { @@ -160,7 +159,7 @@ const showCreateTagModal = ref(false);