Skip to content

Commit

Permalink
Update AutoRefresh.js
Browse files Browse the repository at this point in the history
  • Loading branch information
difemaro committed Oct 30, 2024
1 parent 648a413 commit 33e2c34
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Extensiones/Samples/AutoRefresh_seconds/AutoRefresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,26 @@
// Function to collect unique data sources only once
function collectUniqueDataSources() {
let dashboard = tableau.extensions.dashboardContent.dashboard;
let collectedDataSources = new Set();
let collectedDataSourceIds = new Set();
let uniqueDataSources = [];

// Collect promises for retrieving data sources from each worksheet
let dataSourcePromises = dashboard.worksheets.map((worksheet) =>
worksheet.getDataSourcesAsync().then((datasources) => {
datasources.forEach((datasource) => {
if (activeDatasourceIdList.includes(datasource.id)) {
collectedDataSources.add(datasource); // Add each unique datasource to the Set
// Check if the data source is in the active list and hasn't been added yet
if (activeDatasourceIdList.includes(datasource.id) && !collectedDataSourceIds.has(datasource.id)) {
collectedDataSourceIds.add(datasource.id); // Track unique data source IDs
uniqueDataSources.push(datasource); // Add the datasource object once
}
});
})
);

// Wait for all worksheet data source retrievals to complete
return Promise.all(dataSourcePromises).then(() => {
uniqueDataSources = Array.from(collectedDataSources); // Convert Set to Array for future use
console.log(`Collected ${uniqueDataSources.length} unique data sources.`);
return uniqueDataSources; // Return the unique data sources array
});
}

Expand Down

0 comments on commit 33e2c34

Please sign in to comment.