Skip to content

Commit

Permalink
[Fix] Issue with Changing Task on Running Timer (#8281)
Browse files Browse the repository at this point in the history
* feat: add ITimeTrackerFormState to time-tracker.store

* feat: pass data to ignition restart and store last selector state

* feat: add `data` parameter to concatMap operator and called update selector states with it
  • Loading branch information
adkif authored Sep 29, 2024
1 parent 43e9067 commit 3968519
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { Store, StoreConfig } from '@datorama/akita';
import { ITimeTrackerFormState } from '../../shared/features/time-tracker-form/time-tracker-form.service';

export enum TimerStartMode {
MANUAL = 'manual',
Expand All @@ -19,6 +20,7 @@ export enum IgnitionState {
export interface ITimerIgnition {
mode?: TimerStartMode;
state?: IgnitionState;
data?: ITimeTrackerFormState;
}

export interface ITimeTrackerState {
Expand All @@ -35,7 +37,14 @@ export function createInitialState(): ITimeTrackerState {
isEditing: false,
ignition: {
mode: TimerStartMode.STOP,
state: IgnitionState.STOPPED
state: IgnitionState.STOPPED,
data: {
clientId: null,
teamId: null,
projectId: null,
taskId: null,
note: null
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,9 @@ export class TimeTrackerComponent implements OnInit, AfterViewInit {
this.timeTrackerQuery.ignition$
.pipe(
filter(({ state }) => state === IgnitionState.RESTARTING),
concatMap(async () => {
concatMap(async ({ data }) => {
this.isProcessingEnabled = true;
this.timeTrackerFormService.setState(data);
const session: moment.Moment = this._session?.clone();
const sessionLog = await this.silentRestart();
return { sessionLog, session };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { ClientSelectorService } from '../../shared/features/client-selector/+st
import { ProjectSelectorService } from '../../shared/features/project-selector/+state/project-selector.service';
import { TaskSelectorService } from '../../shared/features/task-selector/+state/task-selector.service';
import { TeamSelectorService } from '../../shared/features/team-selector/+state/team-selector.service';
import { TimeTrackerFormService } from '../../shared/features/time-tracker-form/time-tracker-form.service';
import {
ITimeTrackerFormState,
TimeTrackerFormService
} from '../../shared/features/time-tracker-form/time-tracker-form.service';

@UntilDestroy({ checkProperties: true })
@Component({
Expand All @@ -20,6 +23,7 @@ import { TimeTrackerFormService } from '../../shared/features/time-tracker-form/
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TimerTrackerChangeDialogComponent implements OnInit {
private lastSelectorState: ITimeTrackerFormState;
public form: FormGroup = new FormGroup({
clientId: new FormControl(null),
projectId: new FormControl(null),
Expand Down Expand Up @@ -50,7 +54,7 @@ export class TimerTrackerChangeDialogComponent implements OnInit {
.pipe(
filter(({ state }) => state === IgnitionState.RESTARTED),
tap(() => this.timeTrackerStore.update({ ignition: { state: IgnitionState.STARTED } })),
tap(() => this.dismiss(this.form.value)),
tap(() => this.dismiss(this.lastSelectorState)),
untilDestroyed(this)
)
.subscribe();
Expand Down Expand Up @@ -90,7 +94,8 @@ export class TimerTrackerChangeDialogComponent implements OnInit {
}

public applyChanges() {
this.timeTrackerStore.update({ ignition: { state: IgnitionState.RESTARTING } });
this.lastSelectorState = this.form.value;
this.timeTrackerStore.ignition({ state: IgnitionState.RESTARTING, data: this.form.value });
}

public get isRestarting$(): Observable<boolean> {
Expand Down

0 comments on commit 3968519

Please sign in to comment.