Skip to content

Commit 1b384a9

Browse files
kyuan-mongodbzach-carr
authored andcommitted
DOCSP-26608 added filtering embedded dashboards (#580)
* added filtering embedded dashboards
1 parent 381cc38 commit 1b384a9

13 files changed

+285
-28
lines changed

source/chart-type-reference/data-table/sort-resize-columns.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ sorting is applied.
4949
Resize Columns
5050
~~~~~~~~~~~~~~
5151

52-
To resize a column, click the the column divider and drag until the
52+
To resize a column, click the column divider and drag until the
5353
column reaches the desired width.
5454

5555
To return a column to its default width, double-click on the column

source/charts-embedding-sdk.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ You can use the embedding SDK to do the following tasks:
2121
- Add filters dynamically
2222
- Change the size and style of the chart
2323
- Refresh on demand
24+
- Programmatically save charts as an image
2425

2526
To embed a chart with the SDK, you need to:
2627

source/embedded-chart-error-codes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Refer to the following table for more information on each error code.
7676

7777
- When you filter an embedded chart, the fields
7878
used in the filter must be present in the
79-
:ref:`User Specified Filters <specify-filter-fields>` list.
79+
:ref:`Allowed filter fields <specify-filter-fields>` list.
8080
Additionally, filters embedded charts cannot use non-logical
8181
operators before a field name (e.g., :query:`$expr`,
8282
:query:`$where`, or :query:`$text`).

source/embedded-chart-options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ a variety of options. Options are available to charts embedded with the
222222
:ref:`embedded dashboard <embedding-dashboards>`. This
223223
method expects an object that contains valid query
224224
operators. Any fields referenced in this filter must be
225-
added to the :guilabel:`User Specified Filters`
225+
added to the :guilabel:`Allowed filter fields`
226226
list in the ``Embed Chart`` modal window.
227227
An empty document {} is equivalent to no filter.
228228

source/embedding-dashboards-iframe.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Embed Dashboards with an iframe
1212
:depth: 2
1313
:class: singlecol
1414

15-
You can embed a dashboards into a web application with an iframe and
15+
You can embed a dashboard into a web application with an iframe and
1616
specify settings such as height, width, refresh interval, and display
1717
theme.
1818

source/embedding-dashboards.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ To learn more, see :ref:`embedded-dashboard-options`.
3131
/embedding-dashboards-iframe
3232
/dashboards-embedding-sdk
3333
/embedded-dashboard-options
34+
/filter-embedded-dashboards

source/filter-embedded-charts.txt

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To define filterable fields:
4646
#. For the desired chart, click the :icon-fa5:`ellipsis-h` button and
4747
select :guilabel:`Embed Chart` from the dropdown.
4848

49-
#. In the :guilabel:`User Specified Filters` section, use the
49+
#. In the :guilabel:`Allowed filter fields` section, use the
5050
dropdown to select which fields chart viewers can use filter data
5151
in the chart. You can also manually type values to add fields not
5252
listed in the dropdown.
@@ -56,21 +56,28 @@ To define filterable fields:
5656
This option only appears if you already have **Unauthenticated**
5757
or **Authenticated** embedding access enabled.
5858

59+
You can specify on which fields chart viewers can filter data by:
60+
61+
- Using the dropdown to select the fields
62+
- Manually typing values to add fields not listed in the dropdown
63+
- Selecting :guilabel:`Allow all fields in the data source used in
64+
this chart`
65+
5966
#. When you have selected all desired fields, click :guilabel:`Save`
6067
below the dropdown.
6168

6269
Chart :ref:`viewers <dashboard-roles>` and applications which render
6370
the chart can now use filters based on the specified fields to
6471
display subsets of the original chart data. If a viewer attempts to
65-
use a filter for a field not included in the :ref:`User Specified Filters <specify-filter-fields>` list, an
66-
:ref:`error <embedded-errors>` is returned.
72+
use a filter for a field not included in the :ref:`Allowed filter fields
73+
<specify-filter-fields>` list, |charts| returns an :ref:`error <embedded-errors>`.
6774

6875
Filters for Embedded Documents
6976
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7077

71-
When you add a field to the :guilabel:`User Specified Filters` list
78+
When you add a field to the :guilabel:`Allowed filter fields` list
7279
whose value is an embedded document, you must also specify each
73-
individual sub-field you wish to allow.
80+
individual sub-field you want to allow.
7481

7582
.. example::
7683

@@ -88,11 +95,11 @@ individual sub-field you wish to allow.
8895
}
8996
}
9097

91-
If you only add the ``favorites`` field to the list of allowed fields, it does
92-
*not* grant viewers permission to filter upon any of the sub-fields
93-
of ``favorites``. Instead, you may add one or more of the sub-fields
94-
to the list individually by specifying ``favorites.color``,
95-
``favorites.animal``, or ``favorites.season``.
98+
If you only add the ``favorites`` field to the list of allowed fields, it does
99+
*not* grant viewers permission to filter upon any of the sub-fields
100+
of ``favorites``. Instead, you may add one or more of the sub-fields
101+
to the list individually by specifying ``favorites.color``,
102+
``favorites.animal``, or ``favorites.season``.
96103

97104
.. _embed-options-filter:
98105

@@ -229,9 +236,9 @@ with the ``filter`` option. Filtering allows the chart author to only display
229236
data in the embedded chart which matches a specified :abbr:`MQL (MongoDB
230237
Query Language)` filter.
231238

232-
Any fields included in the filter must be specified in the Embed Chart modal.
233-
The Embed Chart modal contains a dropdown menu of fields on
234-
which to allow filtering.
239+
In the :guilabel:`Embed Chart` modal, you must specify any fields
240+
included in the filter. The :guilabel:`Embed Chart` modal contains a
241+
dropdown menu of fields on which to allow filtering.
235242

236243
The following uses the ``filter`` option to represent only documents in
237244
which the ``total`` field is greater than ``100``:
@@ -252,7 +259,7 @@ Inject User-Specific Filters
252259
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253260

254261
When you embed a chart that requires :guilabel:`Authenticated` access,
255-
you can use the :guilabel:`Inject Filter Per User` setting to inject a
262+
you can use the :guilabel:`Injected function` setting to inject a
256263
MongoDB filter document specific to each user who views
257264
the chart. The function has access to your Embedding Authentication
258265
Provider's token via ``context.token``, and can filter the chart data
@@ -273,8 +280,8 @@ sensitive information.
273280
``context.token.custom_data``.
274281

275282
To inject a filter specific to each user, in the
276-
:guilabel:`Authenticated` tab of the the :guilabel:`Embed Chart`
277-
dialog, set the :guilabel:`Inject Filter Per User`
283+
:guilabel:`Authenticated` tab of the :guilabel:`Embed Chart`
284+
dialog, set the :guilabel:`Injected function`
278285
setting to :guilabel:`On`. Specify a function and click
279286
:guilabel:`Save`.
280287

source/filter-embedded-dashboards.txt

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
.. _filter-embedded-dashboards:
2+
3+
==========================
4+
Filter Embedded Dashboards
5+
==========================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 2
13+
:class: singlecol
14+
15+
You can customize your embedded dashboards by appending various
16+
query parameters to their iframe URLs or using the ``filter`` option
17+
with the |charts-short| Embedding SDK.
18+
19+
.. _specify-filter-fields-dashboards:
20+
21+
Specify Filterable Fields
22+
-------------------------
23+
24+
A dashboard :ref:`Author <dashboard-roles>` specifies the fields that can be
25+
included in filters set by the embedding application code or added by
26+
dashboard viewers. A dashboard author can limit access to data by allowing only
27+
certain fields to be filtered. By default, no fields are allowed,
28+
meaning the dashboard cannot be filtered until you explicitly allow at
29+
least one field.
30+
31+
To define filterable fields:
32+
33+
1. For the desired :ref:`dashboard <dashboards>`, click the
34+
:icon-fa5:`ellipsis-h` button and select :guilabel:`Embed` from the
35+
dropdown.
36+
37+
#. In the :guilabel:`Allowed filter fields` section, click the
38+
:icon-fa5:`pen` button.
39+
40+
.. note::
41+
42+
This option only appears if you already have **Unauthenticated**
43+
or **Authenticated** embedding access enabled.
44+
45+
You can specify on which fields dashboard viewers can filter data by:
46+
47+
- Using the dropdown to select the fields
48+
- Manually typing values to add fields not listed in the dropdown
49+
- Selecting :guilabel:`Allow all fields in the data source used in
50+
this dashboard`
51+
52+
#. When you have selected all desired fields, click :guilabel:`Save`
53+
below the dropdown.
54+
55+
Dashboard :ref:`viewers <dashboard-roles>` and applications which render
56+
the dashboard can now use filters based on the specified fields to
57+
display subsets of the original dashboard data. If a viewer attempts to
58+
use a filter for a field not included in the :ref:`Allowed filter fields
59+
<specify-filter-fields-dashboards>` list, |charts| returns an
60+
:ref:`error <embedded-errors>`.
61+
62+
Filters for Embedded Documents
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
When you add a field to the :guilabel:`Allowed filter fields` list
66+
whose value is an embedded document, you must also specify each
67+
individual sub-field you want to allow.
68+
69+
.. example::
70+
71+
Consider the following document:
72+
73+
.. code-block:: json
74+
75+
{
76+
"name": "Alice",
77+
"favorites" :
78+
{
79+
"color": "green",
80+
"animal": "turtle",
81+
"season": "autumn"
82+
}
83+
}
84+
85+
If you only add the ``favorites`` field to the list of allowed fields,
86+
it does *not* grant viewers permission to filter upon any of the
87+
sub-fields of ``favorites``. Instead, you may add one or more of the
88+
sub-fields to the list individually by specifying ``favorites.color``,
89+
``favorites.animal``, or ``favorites.season``.
90+
91+
.. _embed-options-filter-dashboards:
92+
93+
Filter Data on Dashboards Embedded in an iframe
94+
-----------------------------------------------
95+
96+
Use the ``filter`` query parameter to only display data that matches a
97+
specified :abbr:`MQL (MongoDB Query Language)` filter in your
98+
dashboard embedded in an iframe.
99+
100+
You can only use the ``filter`` query parameter on the
101+
:guilabel:`Unauthenticated` dashboard. With unauthenticated dashboards,
102+
the dashboard :ref:`Author <dashboard-roles>` specifies the fields that
103+
can be included in filters set by the embedding application code or
104+
added by dashboard viewers. To learn how to specify filterable fields,
105+
see :ref:`Specify Filterable Fields <specify-filter-fields-dashboards>`.
106+
107+
Filter Syntax
108+
~~~~~~~~~~~~~
109+
110+
You can specify an MQL document as your ``filter`` query
111+
parameter provided that the fields used in your filter are in
112+
the :ref:`list of allowed filterable fields <specify-filter-fields-dashboards>`.
113+
114+
.. include:: /includes/fact-embedded-filter-examples-unauth.rst
115+
116+
.. note::
117+
118+
You must URL-encode special characters of the filter
119+
parameter.
120+
121+
Example
122+
```````
123+
124+
The following iframe ``src`` URL renders a dashboard which only displays
125+
documents with an ``imdb.rating`` greater than or equal to ``8``:
126+
127+
.. code-block:: none
128+
:emphasize-lines: 3
129+
130+
https://charts.mongodb.com/charts-atlasproject1-piocy/embed/dashboards?
131+
id=93584ddb-1115-4a12-afd9-5129e47bbb0d&
132+
filter={"imdb.rating":%20{$gte:%208}}
133+
134+
135+
The URL uses an encoded ``filter`` parameter of
136+
``{"imdb.rating":%20{$gte:%208}}``. Decoded,
137+
this filter is:
138+
139+
.. code-block:: json
140+
141+
{"imdb.rating": {$gte: 8}}
142+
143+
.. _filter-embedded-sdk-dashboards:
144+
145+
Filter Data on Dashboards Embedded with the SDK
146+
-----------------------------------------------
147+
148+
You can add a :ref:`filter <embed-options-filter-dashboards>` to an
149+
embedded dashboard with the ``filter`` option. Filtering allows the
150+
dashboard author to only display data in the embedded dashboard which
151+
matches a specified :abbr:`MQL (MongoDB Query Language)` filter.
152+
153+
In the :guilabel:`Embed` modal, you must specify any fields included in
154+
the filter. The :guilabel:`Embed` modal contains a dropdown menu of
155+
fields on which to allow filtering.
156+
157+
The following uses the ``filter`` option to represent only documents in
158+
which the ``total`` field is greater than ``100``:
159+
160+
.. code-block:: javascript
161+
162+
createDashboard({
163+
baseUrl: '<your-base-url>',
164+
dashboardId: '<your-dashboard-id>',
165+
width: 500,
166+
height: 500,
167+
filter: { "total": { "$gt": 100 } }
168+
})
169+
170+
.. _inject-filter-per-user-dashboard:
171+
172+
Inject User-Specific Filters
173+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174+
175+
When you embed a dashboard that requires :guilabel:`Authenticated`
176+
access, you can use the :guilabel:`Injected function` setting to inject
177+
a MongoDB filter document specific to each user who views the dashboard.
178+
The function has access to your Embedding Authentication Provider's
179+
token via ``context.token``, and can filter the dashboard data based on
180+
the token.
181+
182+
This filter ensures that viewers of an embedded dashboard only see their
183+
own data, which is useful when embedding dashboard with potentially
184+
sensitive information.
185+
186+
.. note::
187+
188+
If you use an {+atlas-app-services+} authentication provider, ``context.token``
189+
contains the {+app-services+}
190+
:atlas:`user object </app-services/authentication/user-objects/>` to
191+
filter. For example, if you enable
192+
:atlas:`Custom User Data </app-services/users/enable-custom-user-data/>`
193+
for {+app-services+} users, the user object is available in
194+
``context.token.custom_data``.
195+
196+
To inject a filter specific to each user, in the
197+
:guilabel:`Authenticated` tab of the :guilabel:`Embed` dialog, set the
198+
:guilabel:`Injected function`setting to :guilabel:`On`. Specify a
199+
function and click :guilabel:`Save`.
200+
201+
.. include:: /includes/example-user-filter-function.rst

source/get-started-embedding.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Use the Getting Started UI
3939

4040
.. step:: Review the embedding features.
4141

42-
Scroll to the the :guilabel:`Embedding features` section to
42+
Scroll to the :guilabel:`Embedding features` section to
4343
review the available features and learn more.
4444

4545
.. step:: Review the available resources.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ content: |
5151
default, no fields are specified, meaning the chart cannot be
5252
filtered until you explicitly allow at least one field.
5353
54+
Alternatively, you can specify all the fields in your chart by
55+
selecting :guilabel:`Allow all fields in the data source used in this
56+
chart`.
57+
5458
To learn more about filterable fields, see
5559
:ref:`specify-filter-fields`.
5660
---

0 commit comments

Comments
 (0)