🛠️
Developer docs
Start BuildingGuides
  • ✨Getting Started
  • 🎛️Self Hosted Config
  • ✍️SSO Login
    • Saml Identity Provider (Idp)
    • Oidc Identity Provider (Idp)
  • 🎞️Framework Specific Guide
    • ⚛️Reactjs
    • ⚛️Nextjs
    • ⚛️Vuejs
    • ⚛️Angular
    • ⚛️Svelte
    • ⚛️Solid
    • ⚛️Vanilla JS
  • ℹ️Token
  • ℹ️How to embed?
  • 🏛️Multi-Tenant Access Control
  • Embed using iFrame (Not Recommended approach)
  • 🔑License Key Validation for Self-Hosted App
  • Test
  • 👩‍💻Helpers
    • ✳️Token Body
    • ✅Options
      • Custom Fiscal Year filter setup in DataBrain
    • 🈂️Server Event
    • Embed Functions
    • Override Language
    • ✈️Embedding Architecture
    • ✈️LLM Architecture
    • ✨LLM Connectors
      • Open AI
      • Claude AI
      • Azure Open AI
      • Llama
      • Mixtral
    • 🆔Workspace Name
    • 🆔Dashboard ID
    • 🆔Metric ID
    • 🆔API Token
    • 🆔End User Metric Creation
    • Embedding APIs
      • Sync Datasource
  • Metric App Filter
  • Dashboard App Filter
  • Chat Mode
    • Step 1: Create Datamart and Workspace
    • Step 2: Create Data App and Embed ID
  • ✨Solutions Alchemy
    • Dashboards for Client Groups
    • Dashboard for Multiple Clients
    • Embedding: Role based Dashboard Filtering
    • Localized Currency Symbols
    • Manage Metrics
Powered by GitBook
On this page
  • Step 1:
  • Step 2:
  • Example Use Case:
  • Optimizing Large Filters with SQL Integration
  1. Solutions Alchemy

Embedding: Role based Dashboard Filtering

Dashboard Filtered based on the user role.

PreviousDashboard for Multiple ClientsNextLocalized Currency Symbols

Last updated 4 months ago

Step 1:

Create a Dashboard Filter

  • In your dashboard, create a new ‘Dashboard Filter’.

  • In the "Apply On" section, enable the App Filter option.

Step 2:

Passing from Guest Token

  • You can link a guest token here to pass the filter values dynamically.

Refer the below document to generate a guest token.

{
  "clientId": "id",
  "workspaceName": "workspacename",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          // single string
          "name": "Eric",
          // multi select
          "country": ["USA", "CANADA"] || "USA", // based on filter variant(select or multi select)
          // date-picker
          "timePeriod": { "startDate": "2024-01-01", "endDate": "2024-3-23" },
          // range
          "price": { "min": 1000, "max": 5000 }
        }
        "isShowOnUrl": true, // true/false
      }
    ]
  }
}

Make sure the options and values match the data type of the filter for successful integration.


Example Use Case:

Let’s assume you have three roles:

  • Admin

  • Editor

  • Viewer

And two Dashboard Filters:

  • Country: ["USA","CANADA","MEXICO","CHINA","INDIA"]

  • Company: ["ALPHABET","GOOGLE","APPLE"]

And below is the access level of each role:

Role/Dashboard Filters
Company
Country

Admin

All Companies

All Countries

Editor

All Companies

USA, CANADA, MEXICO

Viewer

Alphabet

USA

Now using the information from the table above, you can input the values to generate a guest token according to the specified role.

Guest token for Admin:

{
  "clientId": "id",
  "workspaceName": "workspacename",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          
          "client": ["ALPHABET","GOOGLE","APPLE"],
          
          "country": ["USA","CANADA","MEXICO","CHINA","INDIA"]  
        }
        "isShowOnUrl": true, // true/false
      }
    ]
  }
}

Guest token for Editor :

{
  "clientId": "id",
  "workspaceName": "workspacename",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          
          "client": ["ALPHABET","GOOGLE","APPLE"],
          
          "country": ["USA","CANADA","MEXICO"]  
        }
        "isShowOnUrl": true, // true/false
      }
    ]
  }
}

Guest token for Viewer:

{
  "clientId": "id",
  "workspaceName": "workspacename",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          
          "client": ["ALPHABET"],
          
          "country": ["USA"]  
        }
        "isShowOnUrl": true, // true/false
      }
    ]
  }
}

Optimizing Large Filters with SQL Integration

For filters involving a large number of options (e.g., over 500), manually passing all values becomes inefficient. By integrating SQL, you can dynamically fetch options from your database, simplifying the process and improving efficiency.

The SQL query specified under the "sql" key dynamically fetches the latest values from the specified database table.

Example Configuration

Let’s modify the earlier example for Admin to demonstrate SQL integration for dynamically fetching filter options:

Guest Token for Admin with SQL Integration

{
  "clientId": "id",
  "workspaceName": "workspacename",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          "client": {
            "sql": "SELECT \"name\" FROM \"public\".\"companies\" WHERE \"role\"='admin' ",
            "columnName": "name"
          },
          "country": {
            "sql": "SELECT \"name\" FROM \"public\".\"countries\" WHERE isEnabled=true",
            "columnName": "name"
          }
        },
        "isShowOnUrl": true
      }
    ]
  }
}

Key Benefits

  1. Dynamic Updates: The SQL query retrieves only the latest relevant options from your database.

    • Example: SELECT "name" FROM "public"."countries" WHERE isEnabled=true fetches active country names.

  2. Efficiency: Eliminates the need to manually manage large datasets in the configuration.

  3. Flexibility: The columnName specifies the field in the query result to use as filter values.

  4. Scalability: Handles thousands of options seamlessly, reducing payload size and improving performance.

Ideal Use Case

This approach ensures that filters remain efficient, scalable, and user-friendly, with minimal manual effort to keep options up to date.

✨
ℹ️Token