thingsboard / thingsboard

Open-source IoT Platform - Device management, data collection, processing and visualization.
https://thingsboard.io
Apache License 2.0
17.4k stars 5.14k forks source link

[Bug] dashboardService.getCustomerDashboards displays wrong parameters for it to work #9590

Open X1folta opened 11 months ago

X1folta commented 11 months ago

Describe the bug

According to the dashboard.service.ts it says its:

public getCustomerDashboards(customerId: string, pageLink: PageLink, config?: RequestConfig): Observable<PageData<DashboardInfo>> {
    return this.http.get<PageData<DashboardInfo>>(`/api/customer/${customerId}/dashboards${pageLink.toQuery()}`,
      defaultHttpOptionsFromConfig(config));
  }

Therefore p1 customerId, p2 pageLink and optional p3 being a config.

But console.logging dashboardService reveals its parameters are:

getCustomerDashboards: function getCustomerDashboards(f, y, C, s)

So a 4th parameter that is missing in the info-window about getCustomerDashboards. That fourth parameter is a boolean for

&includeCustomers=boolean

Our Thingsboardversion:

Thingsboard Version PE 3.6

devaskim commented 11 months ago

You provided link for CE version. Unfortunately there is no public link to PE widget's API. So only console.log() may provide more info about dashboardService object and its methods.

X1folta commented 11 months ago

@devaskim Thanks for the info. I suspected that. Nevertheless the autocompletion inside the PE environment suggests the same amount and description of arguments as described and leads to the function's error.

devaskim commented 11 months ago

Unfortunately autocompletion is incomplete as well both in CE and PE

devaskim commented 11 months ago

Seems like this issue has the lowest priority in TB task tracker, because such topic has been raised several time before. But with no feedback from TB developers

X1folta commented 11 months ago

Thats okay. If one day the mystical "ThingsBoard Marketplace" really should become reality then everything that facilitates the entry into creating widgets must receive a higher priority.

devaskim commented 11 months ago

It would be historical day)))

merrittholmes7 commented 7 months ago

Did anyone resolve this. I am getting errors using the definition supplied (customerId, pageLink obejct). When using this I just get cannot read property of undefined (ready 'toQuery')

devaskim commented 7 months ago

Try to compare API docs and the output of console.log(dashboardService.getCustomerDashboards) in browser DevTools Console

// Wrong parameter order. See next my comment 
const pageObj = self.ctx.pageLink(pageSize, pageNumber /* start from 0 */, searchTextString /* optional, null by default */, sortOrder /* optional, null by default, values: 'ASC' or 'DESC');
const customerId = 'YOUR_CUSTOMER_UUID';
const includeCustomers = true; // or false
dashboardService.getCustomerDashboards(customerId, pageObj, includeCustomers).subscribe(
    response => console.log('Response', response),
    error=> console.log('Error', error)
);

The output of console.log(dashboardService.getCustomerDashboards) Скриншот 08-03-2024 171029

merrittholmes7 commented 7 months ago

Further to my previous message . There is a clear difference between PE and CE versions of the dashboardService.

CE definition (taken from demo.thingsboard.io):

getCustomerDashboards(h, r, p) { return this.http.get(/api/customer/${h}/dashboards${r.toQuery()}, (0, e.T7)(p)) }

PE definition (taken from our PE instance)

getCustomerDashboards(f, y, C, s) { let = /api/customer/${y}/dashboards${C.toQuery()}; return f && ( += "&includeCustomers=true"), this.http.get(_, (0, t.T7)(s)) }

So please advise how to use the PE version. What should ‘f' be. I assume ‘s’ in the PE defintion is the same as 'p’ in the CE one.

merrittholmes7 commented 7 months ago

I should ad that your example above erro

Try to compare API docs and the output of console.log(dashboardService.getCustomerDashboards) in browser DevTools Console

const pageObj = self.ctx.pageLink(pageSize, pageNumber /* start from 0 */, searchTextString /* optional, null by default */, sortOrder /* optional, null by default, values: 'ASC' or 'DESC');
const customerId = 'YOUR_CUSTOMER_UUID';
const includeCustomers = true; // or false
dashboardService.getCustomerDashboards(customerId, pageObj, includeCustomers).subscribe(
    response => console.log('Response', response),
    error=> console.log('Error', error)
);

The output of console.log(dashboardService.getCustomerDashboards) Скриншот 08-03-2024 171029

I should add that your example above errors in my PE environment with Cannot read properties of undefined (reading 'pageLink')

This is because for some reason in the PE environment, the pageLink is the 3rd variable but its unclear what the first is meant to be

devaskim commented 7 months ago

So please advise how to use the PE version

My example code was for PE, because original question is about PE version of the API.

the pageLink is the 3rd variable but its unclear what the first is meant to be

Did you try just swap 1st and 3rd parameters from my code example?

dashboardService.getCustomerDashboards(includeCustomers, customerId, pageObj).subscribe(.......);
merrittholmes7 commented 7 months ago

Your example code was for CE not PE as it failed in my PE environment. I have now worked out the issues here. So here are 2 examples for people who are struggling with this also:

getCustomerDashboards: CE: dashboardService.getCustomerDashboards(CustomerId, pageLink, optional config) PE: dashboardService.getCustomerDashboards(includeCustomers (this is mandatory), CustomerId, pageLink, optional config) getUserDashboards: CE: doesn't exist PE: dashboardService.getUserDashboards(userId,operation (I use null as this is mandatory in PE), pageLink, optional config)

In essence though, the Bug here is that the autocomplete details in PE are not correct as they display the CE APIs and unfortunately we do not have access to the codebase for PE so every user has to dig around trying to find the answer in the code that does not normal variable names.

Please update the PE version to include the PE API automcomplete details.

Thanks

devaskim commented 7 months ago

Please update the PE version to include the PE API automcomplete details.

Sad, but you are just another one who is suffering from autocomplete issues. We have been asking TB team to update autocomplete for 1-3 years - no changes yet.

Your example code was for CE not PE as it failed in my PE environment

Explain me how both my examples might be for CE considering that CE version doesn't have nested customer at all (I mean includeCustomers option in both my examples).

Seems like you didn't read my second anwer Скриншот 08-03-2024 190023

merrittholmes7 commented 7 months ago

Yes you are right, the example was for PE but the includeCustomer boolean was put in the wrong place and I read it like the CE version which has the optional config parameter. Apologies there.

this is the issue though in that we are just having to reverse engineer all of the methods because the autocomplete is the only docs we have to go on and its for the wrong version. I have requested a bug be raised for this too.

Thanks for your support. Its appreciated.

devaskim commented 7 months ago

@merrittholmes7 As you are PE user, (if you didn't yet) open the bug on Thingsboard Portal (Service Desk). Hope you will get more info there or maybe even estimation how long we should wait for the full coverage of autocompletion.