From fee3e8d6033523c6a5782222602b769141344cfb Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Wed, 4 Dec 2024 10:47:33 +0500 Subject: [PATCH 1/2] refactor(store): enhance phase ticket store with phase grouping --- .../common/TicketEditor/TicketEditor.tsx | 4 +-- src/people/widgetViews/PhasePlannerView.tsx | 4 +-- src/store/phase.ts | 30 ++++++++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) 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..d8e9c396 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 ITicketStore { 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 ITicketStore { 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(); From 8e7ba6bccf5a96deef0911c7f64e8d6de8d08a2b Mon Sep 17 00:00:00 2001 From: Ali Raza <87068339+aliraza556@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:29:08 +0500 Subject: [PATCH 2/2] Update phase.ts --- src/store/phase.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/phase.ts b/src/store/phase.ts index d8e9c396..be205196 100644 --- a/src/store/phase.ts +++ b/src/store/phase.ts @@ -5,7 +5,7 @@ interface PhaseTickets { [phase_uuid: string]: Ticket[]; } -export interface ITicketStore { +export interface TicketStore { tickets: Map; phaseTickets: PhaseTickets; @@ -15,7 +15,7 @@ export interface ITicketStore { getPhaseTickets: (phase_uuid: string) => Ticket[]; } -export class PhaseTicketStore implements ITicketStore { +export class PhaseTicketStore implements TicketStore { tickets: Map = new Map(); phaseTickets: PhaseTickets = {};