forked from stakwork/sphinx-tribes-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request stakwork#705 from aliraza556/refactor-phase-store-…
…implementation Refactor Phase Store to Support Phase-Based Ticket Grouping
- Loading branch information
Showing
3 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,56 @@ | ||
import { makeAutoObservable } from 'mobx'; | ||
import { Ticket } from './interface'; | ||
|
||
export interface IPhasePlannerStore { | ||
interface PhaseTickets { | ||
[phase_uuid: string]: Ticket[]; | ||
} | ||
|
||
export interface TicketStore { | ||
tickets: Map<string, Ticket>; | ||
phaseTickets: PhaseTickets; | ||
|
||
addTicket: (ticket: Ticket) => void; | ||
updateTicket: (uuid: string, ticket: Partial<Ticket>) => void; | ||
getTicket: (uuid: string) => Ticket | undefined; | ||
getPhaseTickets: (phase_uuid: string) => Ticket[]; | ||
} | ||
|
||
export class PhasePlannerStore implements IPhasePlannerStore { | ||
export class PhaseTicketStore implements TicketStore { | ||
tickets: Map<string, Ticket> = new Map(); | ||
phaseTickets: PhaseTickets = {}; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
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<Ticket>) { | ||
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(); |