Dashboard fails to trigger smart action

Hello Forest Admin team :wave:

Feature(s) impacted

I want to trigger a smart action from a dashboard, it works perfectly from a smart view that is attached to a collection.

Observed behavior

I have the following code for my smart action, it get triggered correctly

  @action
  deleteShift(records, values) {
 return triggerSmartAction(
      this,
      this.args.collection, // <--- This seems to be the problem.
      "Delete",
      records,
      () => {},
      values
    );
  }

this.args does not have collection.

Expected behavior

The exact same code works when the smart chart is attached to a collection.

Failure Logs

I have the following error log in the browser console:

TypeError: Cannot read properties of undefined (reading 'customActions')

Context

  • Project name: *******-trial
  • Team name: Operations
  • Environment name: Development

Hey @arms :wave:

Indeed, this.args.collection will definitely cause issue in a Dashboard/smart chart context, since Dashboard are not directly attached to a collection.

Could you eventually try this.args.chart.sourceCollection instead of this.args.collection?

Thanks in advance

@jeffladiray :wave: !

Thank you for the suggestion, I tried the following thing:

     return triggerSmartAction(
          this,
          this.args.chart.sourceCollection,
          "Delete",
          records,
          () => {},
          values
        );

But it still fails, maybe I got you wrong.
I have the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'sourceCollection')

It seems that this.args does not have chart property.

No, that’s my fault, I was thinking the chart may carry this info, but I mis-read the code :sweat_smile:
Could you eventually share here or privately the complete code of your smart chart so I can check if I can find a way to access a collection from there? Thanks :pray:

Otherwise, you could also just use the store service to retrieve the collection from there.

import Component from '@glimmer/component';
import { loadExternalStyle, loadExternalJavascript } from 'client/utils/smart-view-utils';
import { inject as service } from '@ember/service';

export default class extends Component {
  @service store;
  
  
  constructor(...args) {
    super(...args);
    console.log(this.store.peekRecord('collection', 'yourCollectionName'));
  }
}

Nice ! I tried with the retrieved collection from the store service as follow:

     return triggerSmartAction(
          this,
          this.store.peekRecord('collection', 'shift'),
          "Cancel",
          records,
          () => {},
          values
        );

But I run into this error:

Uncaught (in promise) TypeError: r(...).triggerCustomAction is not a function

This is the import line:

import { triggerSmartAction } from 'client/utils/smart-view-utils';

Hi @arms :wave:, i’m afraid it is not possible yet :confused:.
I push your request to our product board. Thanks a lot for your feedback :pray:

Hey !

Thank you @jeffladiray and @Arnaud_Moncel ! Cannot wait to see this feature available :smiley: !

Keep it up guys !
Cheers

2 Likes