diff --git a/src/components/common/TicketEditor/TicketEditor.tsx b/src/components/common/TicketEditor/TicketEditor.tsx index 6e86fbfb..60c21208 100644 --- a/src/components/common/TicketEditor/TicketEditor.tsx +++ b/src/components/common/TicketEditor/TicketEditor.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import { useStores } from 'store'; import { EuiGlobalToastList } from '@elastic/eui'; -import { phasePlannerStore } from '../../../store/phase'; +import { phaseTicketStore } from '../../../store/phase'; import { ActionButton, TicketButtonGroup } from '../../../people/widgetViews/workspace/style'; import { TicketContainer, @@ -87,7 +87,7 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => { if (response === 406 || !response) { throw new Error('Failed to update ticket'); } - phasePlannerStore.updateTicket(ticketData.uuid, updateTicketData); + phaseTicketStore.updateTicket(ticketData.uuid, updateTicketData); addUpdateSuccessToast(); } catch (error) { console.error('Error updating ticket:', error); diff --git a/src/people/widgetViews/PhasePlannerView.tsx b/src/people/widgetViews/PhasePlannerView.tsx index 6e8cfe01..67f1f451 100644 --- a/src/people/widgetViews/PhasePlannerView.tsx +++ b/src/people/widgetViews/PhasePlannerView.tsx @@ -15,7 +15,7 @@ import { } from 'pages/tickets/style'; import { SOCKET_MSG } from 'config/socket'; import { createSocketInstance } from 'config/socket'; -import { phasePlannerStore } from '../../store/phase'; +import { phaseTicketStore } from '../../store/phase'; import { FeatureHeadNameWrap, FeatureHeadWrap, @@ -149,7 +149,7 @@ const PhasePlannerView: React.FC = () => { try { await main.createUpdateTicket(initialTicketData); - phasePlannerStore.addTicket(initialTicketData as Ticket); + phaseTicketStore.addTicket(initialTicketData as Ticket); setTicketData((prevTickets: TicketData[]) => [ ...prevTickets, { diff --git a/src/store/phase.ts b/src/store/phase.ts index 18325d40..be205196 100644 --- a/src/store/phase.ts +++ b/src/store/phase.ts @@ -1,15 +1,23 @@ import { makeAutoObservable } from 'mobx'; import { Ticket } from './interface'; -export interface IPhasePlannerStore { +interface PhaseTickets { + [phase_uuid: string]: Ticket[]; +} + +export interface TicketStore { tickets: Map; + phaseTickets: PhaseTickets; + addTicket: (ticket: Ticket) => void; updateTicket: (uuid: string, ticket: Partial) => void; getTicket: (uuid: string) => Ticket | undefined; + getPhaseTickets: (phase_uuid: string) => Ticket[]; } -export class PhasePlannerStore implements IPhasePlannerStore { +export class PhaseTicketStore implements TicketStore { tickets: Map = new Map(); + phaseTickets: PhaseTickets = {}; constructor() { makeAutoObservable(this); @@ -17,18 +25,32 @@ export class PhasePlannerStore implements IPhasePlannerStore { addTicket(ticket: Ticket) { this.tickets.set(ticket.uuid, ticket); + + const phaseTickets = this.phaseTickets[ticket.phase_uuid] || []; + this.phaseTickets[ticket.phase_uuid] = [...phaseTickets, ticket]; } updateTicket(uuid: string, ticketUpdate: Partial) { const existingTicket = this.tickets.get(uuid); if (existingTicket) { - this.tickets.set(uuid, { ...existingTicket, ...ticketUpdate }); + const updatedTicket = { ...existingTicket, ...ticketUpdate } as Ticket; + + this.tickets.set(uuid, updatedTicket); + + const phaseTickets = this.phaseTickets[existingTicket.phase_uuid] || []; + this.phaseTickets[existingTicket.phase_uuid] = phaseTickets.map((t: Ticket) => + t.uuid === uuid ? updatedTicket : t + ); } } getTicket(uuid: string): Ticket | undefined { return this.tickets.get(uuid); } + + getPhaseTickets(phase_uuid: string): Ticket[] { + return this.phaseTickets[phase_uuid] || []; + } } -export const phasePlannerStore = new PhasePlannerStore(); +export const phaseTicketStore = new PhaseTicketStore();