11import { action } from "@ember/object" ;
22import { service } from "@ember/service" ;
33import Component from "@glimmer/component" ;
4+ import { tracked } from "@glimmer/tracking" ;
45import { restartableTask , timeout , dropTask } from "ember-concurrency" ;
56import { runTask } from "ember-lifeline" ;
67import { trackedTask } from "reactiveweb/ember-concurrency" ;
7- import { trackedFunction } from "reactiveweb/function" ;
8- import { resolve } from "rsvp" ;
9- import { localCopy } from "tracked-toolbox" ;
108
119import customerOptionTemplate from "timed/components/optimized-power-select/custom-options/customer-option" ;
1210import projectOptionTemplate from "timed/components/optimized-power-select/custom-options/project-option" ;
@@ -30,7 +28,7 @@ export default class TaskSelectionComponent extends Component {
3028 * @property {Customer } _customer
3129 * @private
3230 */
33- @localCopy ( "args.initial.customer" )
31+ @tracked
3432 _customer ;
3533
3634 /**
@@ -39,7 +37,7 @@ export default class TaskSelectionComponent extends Component {
3937 * @property {Project } _project
4038 * @private
4139 */
42- @localCopy ( "args.initial.project" )
40+ @tracked
4341 _project ;
4442
4543 /**
@@ -48,7 +46,7 @@ export default class TaskSelectionComponent extends Component {
4846 * @property {Task } _task
4947 * @private
5048 */
51- @localCopy ( "args.initial.task" )
49+ @tracked
5250 _task ;
5351
5452 constructor ( ...args ) {
@@ -108,12 +106,20 @@ export default class TaskSelectionComponent extends Component {
108106 initial . task ,
109107 ] ) ;
110108
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 ) ;
117123 } else {
118124 this . tracking . fetchCustomers . perform ( ) ;
119125 }
@@ -257,24 +263,28 @@ export default class TaskSelectionComponent extends Component {
257263 return this . _customersAndRecentTasks . value ?? [ ] ;
258264 }
259265
260- #projects = trackedFunction ( this , async ( ) => {
266+ _projects = dropTask ( this , async ( ) => {
261267 return ( await this . customer ?. projects )
262268 ?. filter ( this . filterByArchived )
263269 . toSorted ( ( p ) => p . name ) ;
264270 } ) ;
265271
272+ _projectsTask = trackedTask ( this , this . _projects , ( ) => [ this . _customer ?. id ] ) ;
273+
266274 get projects ( ) {
267- return this . #projects . value ?? [ ] ;
275+ return this . _projectsTask . value ?? [ ] ;
268276 }
269277
270- #tasks = trackedFunction ( this , async ( ) => {
278+ _tasks = dropTask ( this , async ( ) => {
271279 return ( await this . project ?. tasks )
272280 ?. filter ( this . filterByArchived )
273281 . toSorted ( ( t ) => t . name ) ;
274282 } ) ;
275283
284+ _tasksTask = trackedTask ( this , this . _tasks , ( ) => [ this . _project ?. id ] ) ;
285+
276286 get tasks ( ) {
277- return this . #tasks . value ?? [ ] ;
287+ return this . _tasksTask . value ?? [ ] ;
278288 }
279289
280290 @action
@@ -351,7 +361,7 @@ export default class TaskSelectionComponent extends Component {
351361 }
352362
353363 if ( ! this . customer && value ?. get ( "customer.id" ) ) {
354- resolve ( value . get ( "customer" ) ) . then ( ( c ) => {
364+ Promise . resolve ( value . get ( "customer" ) ) . then ( ( c ) => {
355365 this . onCustomerChange ( c , {
356366 preventAction : true ,
357367 } ) ;
@@ -376,7 +386,7 @@ export default class TaskSelectionComponent extends Component {
376386 ( ! this . project && projectId ) ||
377387 ( projectId && this . project ?. id !== projectId )
378388 ) {
379- resolve ( value . get ( "project" ) ) . then ( ( p ) => {
389+ Promise . resolve ( value . get ( "project" ) ) . then ( ( p ) => {
380390 this . onProjectChange ( p , {
381391 preventAction : true ,
382392 } ) ;
0 commit comments