arms
December 10, 2021, 3:15pm
1
Hello Forest Admin team
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
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
arms
December 13, 2021, 10:08am
3
@jeffladiray !
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
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
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'));
}
}
arms
December 13, 2021, 12:48pm
6
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';
arms
December 13, 2021, 5:55pm
8
Hey !
Thank you @jeffladiray and @Arnaud_Moncel ! Cannot wait to see this feature available !
Keep it up guys !
Cheers
2 Likes