Is there any way to hide certain presets from the ...
# gooddata-cloud
s
Is there any way to hide certain presets from the date picker? Day, Minute and Hour doesn’t make sense for our customers.
k
Yes. You can hide specific granularities and also control which presets are available in dashboard date filters. ### 1. Hide granularities (Day, Hour, Minute) Use the
dateFilterConfig
metadata object and limit the granularities in the
relativeForm.granularities
array to only those you want (for example, month, quarter, year). Anything not listed (day, hour, minute) will not appear in the date picker UI. [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)] Example (only months and years):
Copy code
json "relativeForm": {   "granularities": [     "GDC.time.month",     "GDC.time.year"   ],   "localIdentifier": "relativeForm",   "name": "relativeForm",   "visible": true }
You configure this via: -
/api/v1/entities/organizationSettings
or -
/api/v1/entities/workspaces/{workspaceId}/workspaceSettings
. [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)] You can also use
hideGranularities
in
IDashboardDateFilterConfig
to explicitly hide certain granularities in a specific dashboard. [[hideGranularities](https://sdk.gooddata.com/gooddata-ui-apidocs/v11.21.0/docs/sdk-model.idashboarddatefilterconfig.hidegranularities.html#idashboarddatefilterconfighidegranularities-property)] ### 2. Control / hide specific presets Presets are defined in the
relativePresets
section of the same
dateFilterConfig
. You can: - Remove presets you don’t want to offer, or - Add only the presets that make sense for your users (e.g., “Last 7 days”, “Last 30 days”, “Last 12 months”). [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)] Example of defining only a couple of presets:
Copy code
json "relativePresets": [   {     "from": -6,     "to": 0,     "granularity": "GDC.time.date",     "localIdentifier": "relative_last_7_days",     "name": "Last 7 days",     "visible": true   },   {     "from": -29,     "to": 0,     "granularity": "GDC.time.date",     "localIdentifier": "relative_last_30_days",     "name": "Last 30 days",     "visible": true   } ]
By combining: -
relativeForm.granularities
(and optionally
hideGranularities
) and - a curated
relativePresets
list, you can effectively hide Day/Hour/Minute options and any presets based on them from the date picker.
s
@kapa.ai where is this configuration set for relative presets and datefilterconfig?
k
A message from kapa.ai
You set both
dateFilterConfig
and its
relativePresets
via metadata settings, using the GoodData Cloud API. ### 1. Where
dateFilterConfig
lives
dateFilterConfig
is stored as a special setting object and can be created/updated at: - Organization level:
POST /api/v1/entities/organizationSettings
- Workspace level:
POST /api/v1/entities/workspaces/{workspaceId}/workspaceSettings
The object has: - `id`:
dateFilterConfig
- `attributes.type`:
DATE_FILTER_CONFIG
Example payload (org level): [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)]
Copy code
json {   "data": {     "id": "dateFilterConfig",     "type": "organizationSetting",     "attributes": {       "content": {         "config": {           "relativeForm": {             "granularities": [               "GDC.time.month",               "GDC.time.year"             ],             "localIdentifier": "relativeForm",             "name": "relativeForm",             "visible": true           },           "relativePresets": [             {               "from": -6,               "to": 0,               "granularity": "GDC.time.date",               "localIdentifier": "relative_last_7_days",               "name": "Last 7 days",               "visible": true             }           ],           "selectedOption": "relative_last_7_days"         }       },       "type": "DATE_FILTER_CONFIG"     }   } }
(Switch
"type": "organizationSetting"
to
"workspaceSetting"
when calling the workspace endpoint.) [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)] ### 2. Where
relativePresets
are configured
relativePresets
is a field inside that same
dateFilterConfig
content:
Copy code
json "config": {   ...   "relativePresets": [     {       "from": -6,       "to": 0,       "granularity": "GDC.time.date",       "localIdentifier": "relative_last_7_days",       "name": "Last 7 days",       "visible": true     }   ],   "selectedOption": "relative_last_7_days" }
You add/remove presets by editing this array in the
content.config
of the
dateFilterConfig
setting. [[Date filter docs](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#how-to-modify-date-filters-in-dashboards)] ### 3. Deleting the configuration If you need to remove the configuration entirely: - Org level:
DELETE /api/v1/entities/organizationSettings/dateFilterConfig
- Workspace level:
DELETE /api/v1/entities/workspaces/{workspaceId}/workspaceSettings/dateFilterConfig
[[Deleting dateFilterConfig](https://www.gooddata.com/docs/gooddata-ui/latest/references/filters/date_filter/#deleting-datefilterconfig)]
s
@Matt MacGillivray we’ll need to do this to take out the presets that don’t make sense
m
@kapa.ai how do i curl to edit the dateFilterConfig ?
k
A message from kapa.ai
New message text here
m
@kapa.ai what is the default dateFilterConfig
k
A message from kapa.ai
New message text here
m
2 problems I had, for anyone else that tries it: 1. There is no way to get the default value for
dateFilterConfig
via the api. There is no
dateFilterConfig
in the organization settings or workspace settings by default. So you have to build it from scratch. 2. The format required for updating
dateFilterConfig
is different than specified in the documentation - the docs show it from the
config
element, but if you do a
PUT
it requires you start from the
data/attributes/content
element. This was SUPER confusing, which would have been solved by (1). So the docs give examples that look like this:
Copy code
{
    "config": {
        "absoluteForm": {
            "localIdentifier": "absoluteForm",
            "name": "",
            "visible": true
        },
        "allTime": {
            "localIdentifier": "allTime",
            "name": "All time",
            "visible": true
        },
... rest of the elements here ...
}
when it SHOULD BE:
Copy code
{
    "data": {
        "attributes": {
            "content": {
                "config": {
                    "absoluteForm": {
                        "localIdentifier": "absoluteForm",
                        "name": "",
                        "visible": true
                    },
                    "allTime": {
                        "localIdentifier": "allTime",
                        "name": "All time",
                        "visible": true
                    },
... rest of the elements here ...
}
Note the missing data/attributes/content path.
j
@Matt MacGillivray Thank you for this! We will reach out to our Docs team and get this fixed.