From 0ee299610ea210765a2e7f852006a2cc2ac08a47 Mon Sep 17 00:00:00 2001 From: Dominik Klein Date: Thu, 19 Sep 2024 22:26:59 +0200 Subject: [PATCH] Maintenance: Desktop view - Fixed not visible ticket edit form when ticket is used from cache. --- .../ticket/composables/useTicketEdit.ts | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/app/frontend/shared/entities/ticket/composables/useTicketEdit.ts b/app/frontend/shared/entities/ticket/composables/useTicketEdit.ts index ef96a4a89245..ab4d151fb079 100644 --- a/app/frontend/shared/entities/ticket/composables/useTicketEdit.ts +++ b/app/frontend/shared/entities/ticket/composables/useTicketEdit.ts @@ -39,37 +39,42 @@ export const useTicketEdit = ( const initialTicketValue = ref() const mutationUpdate = new MutationHandler(useTicketUpdateMutation({})) - watch(ticket, (newTicket, oldTicket) => { - if (!newTicket) { - return - } - - // We need only to reset the form, when really something was changed (updatedAt is not relevant for the form). - if ( - isEqualWith(newTicket, oldTicket, (value1, value2, key) => { - if (key === 'updatedAt') return true + watch( + ticket, + (newTicket, oldTicket) => { + if (!newTicket) { + return + } + + const ticketId = initialTicketValue.value?.id || newTicket.id + const { internalId: ownerInternalId } = newTicket.owner + + initialTicketValue.value = { + id: newTicket.id, + owner_id: ownerInternalId === 1 ? null : ownerInternalId, + } + + // We need only to reset the form, when really something was changed (updatedAt is not relevant for the form). + if ( + !oldTicket || + isEqualWith(newTicket, oldTicket, (value1, value2, key) => { + if (key === 'updatedAt') return true + }) + ) { + return + } + + // TODO: check why article type was changed back to initial?! + form.value?.resetForm(initialTicketValue.value, newTicket, { + // don't reset to new values, if user changes something + // if ticket is different, it's probably navigation to another ticket, + // so we can safely reset the form + // TODO: navigation to another ticket is currently always a re-render of the form, because of the component key(=newTicket.id) or? + resetDirty: ticketId !== newTicket.id, }) - ) { - return - } - - const ticketId = initialTicketValue.value?.id || newTicket.id - const { internalId: ownerInternalId } = newTicket.owner - - initialTicketValue.value = { - id: newTicket.id, - owner_id: ownerInternalId === 1 ? null : ownerInternalId, - } - - // TODO: check why article type was changed back to initial?! - form.value?.resetForm(initialTicketValue.value, newTicket, { - // don't reset to new values, if user changes something - // if ticket is different, it's probably navigation to another ticket, - // so we can safely reset the form - // TODO: navigation to another ticket is currently always a re-render of the form, because of the component key(=newTicket.id) or? - resetDirty: ticketId !== newTicket.id, - }) - }) + }, + { immediate: true }, + ) const isTicketFormGroupValid = computed(() => { const ticketGroup = form.value?.formNode?.at('ticket')