Skip to content

Commit 1e0f58c

Browse files
authored
(DOCSP-10968) Add Section to Filter Embedded Charts for Filter Injection (#384)
* (DOCSP-10968) Add Section to Filter Embedded Charts for Filter Injection * Updates from copy review * Single source example, use on both pages
1 parent ade7f3b commit 1e0f58c

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

source/filter-embedded-charts.txt

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ with the |charts-short| Embedding SDK.
2323

2424
- :ref:`embedding-charts`
2525

26+
.. _inject-filter-per-user:
27+
28+
Inject User-Specific Filters
29+
----------------------------
30+
31+
When you embed a chart requiring :guilabel:`Authenticated` access, you
32+
can use the :guilabel:`Inject Filter Per User` setting to inject a
33+
MongoDB filter document specific to each user who views
34+
the chart. The function has access to your Embedding Authentication
35+
Provider's token via ``context.token``, and can filter the chart data
36+
based on the token.
37+
38+
This filter ensures that viewers of an embedded chart see only their
39+
own data, which is useful when embedding charts with potentially
40+
sensitive information.
41+
42+
To inject a filter specific to each user, in the
43+
:guilabel:`Authenticated` tab of the the :guilabel:`Embed Chart`
44+
dialog, set the :guilabel:`Inject Filter Per User`
45+
setting to :guilabel:`On`. Specify a function and click
46+
:guilabel:`Save`.
47+
48+
.. include:: /includes/example-user-filter-function.rst
49+
2650
.. _specify-filter-fields:
2751

2852
Specify Filterable Fields
@@ -99,11 +123,12 @@ Use the ``filter`` query parameter to only display data that matches a
99123
specified :abbr:`MQL (MongoDB Query Language)` filter in your
100124
chart embedded in an iframe.
101125

102-
You can use the ``filter`` query parameter on both Unauthenticated
103-
charts and charts which require a Verified Signature. The filtering
126+
You can use the ``filter`` query parameter on both
127+
:guilabel:`Unauthenticated`
128+
and :guilabel:`Verified Signature` charts. The filtering
104129
behavior differs with each authentication setting:
105130

106-
- With Unauthenticated charts, the chart
131+
- With unauthenticated charts, the chart
107132
:ref:`Author <dashboard-roles>` specifies the fields that can be
108133
included in filters set by the embedding application code or added by
109134
chart viewers. To learn how to specify filterable fields, see
@@ -118,7 +143,8 @@ Filter Syntax
118143
~~~~~~~~~~~~~
119144

120145
Select the appropriate tab to see an example of how to filter data in
121-
an Unauthenticated chart and a Verified Signature chart:
146+
an :guilabel:`Unauthenticated` chart and a
147+
:guilabel:`Verified Signature` chart:
122148

123149
.. tabs::
124150

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. example::
2+
3+
The following filter function only renders data where the
4+
``ownerId`` field of a document matches the value of
5+
the Embedding Authentication Provider's token's ``sub`` field:
6+
7+
.. code-block:: javascript
8+
9+
function getFilter(context) {
10+
return { ownerId: context.token.sub };
11+
}

source/includes/steps-embed-chart-authenticated.yaml

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,15 @@ ref:
4141
level: 4
4242
content: |
4343
You can specify a function to inject a MongoDB filter document for
44-
each user who views the chart. The function has access to your
45-
Embedding Authentication Provider's token via ``context.token``, and
46-
can filter the chart data based on the token.
44+
each user who views the chart. This is useful for rendering
45+
user-specific charts.
4746
48-
This filter ensures that viewers of an embedded chart see only their
49-
own data, which is useful when embedding charts with potentially
50-
sensitive information.
47+
.. include:: /includes/example-user-filter-function.rst
5148
52-
.. example::
49+
.. seealso::
5350
54-
The following filter function only renders data where the
55-
``ownerId`` field of a document matches the value of
56-
the Embedding Authentication Provider's token's ``sub`` field:
57-
58-
.. code-block:: javascript
59-
60-
function getFilter(context) {
61-
return { ownerId: context.token.sub };
62-
}
51+
To learn more about injecting filters per user, see
52+
:ref:`inject-filter-per-user`.
6353
---
6454
title: (*Optional*) Specify filterable fields for your chart.
6555
ref: authenticated-filterable-fields
@@ -69,8 +59,10 @@ content: |
6959
default, no fields are whitelisted, meaning the chart cannot be
7060
filtered until you explicitly whitelist at least one field.
7161
72-
To learn more about filterable fields, see
73-
:ref:`specify-filter-fields`.
62+
.. seealso::
63+
64+
To learn more about filterable fields, see
65+
:ref:`specify-filter-fields`.
7466
---
7567
title: Copy the :guilabel:`Chart ID` and :guilabel:`Chart Base URL`
7668
ref: copy-chart-attributes

0 commit comments

Comments
 (0)