Skip to content

Commit

Permalink
Maintenance: Desktop view - Fixed not visible ticket edit form when t…
Browse files Browse the repository at this point in the history
…icket is used from cache.
  • Loading branch information
dominikklein authored and dvuckovic committed Sep 20, 2024
1 parent 5a82c35 commit 0ee2996
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions app/frontend/shared/entities/ticket/composables/useTicketEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,42 @@ export const useTicketEdit = (
const initialTicketValue = ref<FormValues>()
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')
Expand Down

0 comments on commit 0ee2996

Please sign in to comment.