VolkovLabs / business-text

The Business Text panel plugin allows you to construct a text visualization template from the values of a dataset returned by a data source query.
https://docs.volkovlabs.io
Apache License 2.0
83 stars 13 forks source link

Need help on Date time picker with start and end date #372

Closed vanimesh closed 1 week ago

vanimesh commented 1 week ago

Hi everyone,

I need help, where i am trying to build a date time picker with the help of this link. But somehow i am not able to follow complete steps. My requirement is to notify a user with message if the user selects the time in past like yesterday . So below are my questions

` - Or can i simply write a javascript to validate the variable value using the events and display message? Waiting for the response and guidence, thank you
vanimesh commented 1 week ago

hi @mikhail-vl , how are you doing? I wanted to display a alert to the user if the start date is selected with old date. So i am trying to use the panel with "Javascript code aftrer content Ready" and passing the below script just to test the event "time-range-updated" it works but strangely it produces multiple alerts. Can you please help ? Below is the code

const subscription = context.grafana.eventBus.subscribe(
  { type: "time-range-updated" },
  () => {
    console.log("time-range-updated");
    alert("Start datetime cannot be older than Present-5Minutes panel 1");
  }
);
mikhail-vl commented 1 week ago

@vanimesh You need to add unsubscribe as described in documentation after to avoid multiple subscriptions:

https://volkovlabs.io/plugins/business-text/eventbus/

vanimesh commented 1 week ago

Hi @mikhail-vl , i tried to unsubscribe but still it doesnt seem to work. Below is the code `const subscription = context.grafana.eventBus.subscribe( { type: "time-range-updated" }, () => { console.log("React to Data Hover"); alert("popup") } );

return () => { subscription.unsubscribe(); console.log("Unsubscribed"); };`