Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEV-10402] Set Default Filter Value #1926

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/components/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const useFilters = props => {
// Overwrite filterItem.values since thats what we map through in the editor panel
filterItem.values = updatedValues
filterItem.orderedValues = updatedValues
filterItem.active = updatedValues[0]
if (!filterItem.active) filterItem.active = updatedValues[0]
filterItem.order = 'cust'

// Update the filters
Expand Down
4 changes: 2 additions & 2 deletions packages/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</head>

<body>
<div class="react-container" data-config="/examples/private/bird-flu-2.json"></div>
<div class="react-container" data-config="/examples/private/bird-flu.json"></div>
<!-- <div class="react-container" data-config="/examples/wastewater.json"></div> -->
<!-- <div class="react-container" data-config="/examples/private/bird-flu.json"></div> -->
<!-- <div class="react-container" data-config="/examples/bump-chart.json"></div> -->
<!-- <div class="react-container" data-config="/examples/full-dashboard.json"></div> -->
<div class="react-container" data-config="/examples/dashboard-gallery.json"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ const FilterEditor: React.FC<FilterEditorProps> = ({ filter, filterIndex, config
</select>
</label>

<Select
value={filter.active}
options={config.dashboard.sharedFilters[filterIndex].values}
updateField={(_section, _subSection, _key, value) => updateFilterProp('active', value)}
label={'Filter Default Value'}
initial={'Select'}
/>

<Select
value={filter.order || 'column'}
options={filterOrderOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const addValuesToDashboardFilters = (
filterCopy.active = active.filter(val => defaultValues.includes(val))
} else {
const defaultLabel = filters.find(filter => filter.resetLabel)
const defaultValue = defaultLabel ? defaultLabel.resetLabel : filterCopy.values?.[0] || filterCopy.active
const defaultValue = defaultLabel ? defaultLabel.resetLabel : filterCopy.active || filterCopy.values[0]
filterCopy.active = defaultValue
}
}
Expand Down