Embedding: Role based Dashboard Filtering

Dashboard Filtered based on the user role.

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.

â„šī¸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.

Last updated