1
1
import { action } from "@ember/object" ;
2
2
import { service } from "@ember/service" ;
3
3
import Component from "@glimmer/component" ;
4
+ import { tracked } from "@glimmer/tracking" ;
4
5
import { restartableTask , timeout , dropTask } from "ember-concurrency" ;
5
6
import { runTask } from "ember-lifeline" ;
6
7
import { trackedTask } from "reactiveweb/ember-concurrency" ;
7
- import { trackedFunction } from "reactiveweb/function" ;
8
- import { resolve } from "rsvp" ;
9
- import { localCopy } from "tracked-toolbox" ;
10
8
11
9
import customerOptionTemplate from "timed/components/optimized-power-select/custom-options/customer-option" ;
12
10
import projectOptionTemplate from "timed/components/optimized-power-select/custom-options/project-option" ;
@@ -30,7 +28,7 @@ export default class TaskSelectionComponent extends Component {
30
28
* @property {Customer } _customer
31
29
* @private
32
30
*/
33
- @localCopy ( "args.initial.customer" )
31
+ @tracked
34
32
_customer ;
35
33
36
34
/**
@@ -39,7 +37,7 @@ export default class TaskSelectionComponent extends Component {
39
37
* @property {Project } _project
40
38
* @private
41
39
*/
42
- @localCopy ( "args.initial.project" )
40
+ @tracked
43
41
_project ;
44
42
45
43
/**
@@ -48,7 +46,7 @@ export default class TaskSelectionComponent extends Component {
48
46
* @property {Task } _task
49
47
* @private
50
48
*/
51
- @localCopy ( "args.initial.task" )
49
+ @tracked
52
50
_task ;
53
51
54
52
constructor ( ...args ) {
@@ -108,12 +106,20 @@ export default class TaskSelectionComponent extends Component {
108
106
initial . task ,
109
107
] ) ;
110
108
111
- if ( task ) {
112
- this . onTaskChange ( task , options ) ;
113
- } else if ( project ) {
114
- this . onProjectChange ( project , options ) ;
115
- } else if ( customer ) {
116
- this . onCustomerChange ( customer , options ) ;
109
+ this . _task = task ?? this . args . task ;
110
+ this . _project = this . _task
111
+ ? await this . _task . customer
112
+ : ( project ?? this . args . project ) ;
113
+ this . _customer = this . _project
114
+ ? await this . _project . customer
115
+ : ( customer ?? this . args . customer ) ;
116
+
117
+ if ( this . _task ) {
118
+ this . onTaskChange ( this . _task , options ) ;
119
+ } else if ( this . _project ) {
120
+ this . onProjectChange ( this . _project , options ) ;
121
+ } else if ( this . _customer ) {
122
+ this . onCustomerChange ( this . _customer , options ) ;
117
123
} else {
118
124
this . tracking . fetchCustomers . perform ( ) ;
119
125
}
@@ -257,24 +263,28 @@ export default class TaskSelectionComponent extends Component {
257
263
return this . _customersAndRecentTasks . value ?? [ ] ;
258
264
}
259
265
260
- #projects = trackedFunction ( this , async ( ) => {
266
+ _projects = dropTask ( this , async ( ) => {
261
267
return ( await this . customer ?. projects )
262
268
?. filter ( this . filterByArchived )
263
269
. toSorted ( ( p ) => p . name ) ;
264
270
} ) ;
265
271
272
+ _projectsTask = trackedTask ( this , this . _projects , ( ) => [ this . _customer ?. id ] ) ;
273
+
266
274
get projects ( ) {
267
- return this . #projects . value ?? [ ] ;
275
+ return this . _projectsTask . value ?? [ ] ;
268
276
}
269
277
270
- #tasks = trackedFunction ( this , async ( ) => {
278
+ _tasks = dropTask ( this , async ( ) => {
271
279
return ( await this . project ?. tasks )
272
280
?. filter ( this . filterByArchived )
273
281
. toSorted ( ( t ) => t . name ) ;
274
282
} ) ;
275
283
284
+ _tasksTask = trackedTask ( this , this . _tasks , ( ) => [ this . _project ?. id ] ) ;
285
+
276
286
get tasks ( ) {
277
- return this . #tasks . value ?? [ ] ;
287
+ return this . _tasksTask . value ?? [ ] ;
278
288
}
279
289
280
290
@action
@@ -351,7 +361,7 @@ export default class TaskSelectionComponent extends Component {
351
361
}
352
362
353
363
if ( ! this . customer && value ?. get ( "customer.id" ) ) {
354
- resolve ( value . get ( "customer" ) ) . then ( ( c ) => {
364
+ Promise . resolve ( value . get ( "customer" ) ) . then ( ( c ) => {
355
365
this . onCustomerChange ( c , {
356
366
preventAction : true ,
357
367
} ) ;
@@ -376,7 +386,7 @@ export default class TaskSelectionComponent extends Component {
376
386
( ! this . project && projectId ) ||
377
387
( projectId && this . project ?. id !== projectId )
378
388
) {
379
- resolve ( value . get ( "project" ) ) . then ( ( p ) => {
389
+ Promise . resolve ( value . get ( "project" ) ) . then ( ( p ) => {
380
390
this . onProjectChange ( p , {
381
391
preventAction : true ,
382
392
} ) ;
0 commit comments