({
chart,
dashboardFilters = [],
chartFilters = [],
})
| 124 | } |
| 125 | |
| 126 | export function buildChartRuntimeRequest({ |
| 127 | chart, |
| 128 | dashboardFilters = [], |
| 129 | chartFilters = [], |
| 130 | }) { |
| 131 | const chartId = chart?.id; |
| 132 | const variables = dashboardFilters.reduce((acc, filter) => { |
| 133 | if (filter?.type === "variable" && filter.variable && filter.value !== undefined && filter.value !== null && filter.value !== "") { |
| 134 | acc[filter.variable] = filter.value; |
| 135 | } |
| 136 | return acc; |
| 137 | }, {}); |
| 138 | |
| 139 | const normalizedDashboardFilters = dashboardFilters |
| 140 | .map((filter) => normalizeDashboardFilter(filter, chartId)) |
| 141 | .filter(Boolean); |
| 142 | const normalizedChartFilters = chartFilters |
| 143 | .map((filter) => normalizeChartFilter(filter)) |
| 144 | .filter(Boolean); |
| 145 | |
| 146 | const dedupedFilters = []; |
| 147 | const seen = new Set(); |
| 148 | [...normalizedDashboardFilters, ...normalizedChartFilters].forEach((filter) => { |
| 149 | const key = buildFilterKey(filter); |
| 150 | if (seen.has(key)) return; |
| 151 | seen.add(key); |
| 152 | dedupedFilters.push({ ...filter, __key: key }); |
| 153 | }); |
| 154 | |
| 155 | dedupedFilters.sort((left, right) => left.__key.localeCompare(right.__key)); |
| 156 | |
| 157 | const filters = dedupedFilters.map((filter) => { |
| 158 | const normalizedFilter = { ...filter }; |
| 159 | delete normalizedFilter.__key; |
| 160 | return normalizedFilter; |
| 161 | }); |
| 162 | const variableEntries = normalizeVariableEntries(variables); |
| 163 | const normalizedVariables = variableEntries.reduce((acc, [key, value]) => { |
| 164 | acc[key] = value; |
| 165 | return acc; |
| 166 | }, {}); |
| 167 | |
| 168 | const sourceAffecting = { |
| 169 | filters: filters.filter((filter) => filter.type === "date" && filter.startDate && filter.endDate), |
| 170 | variables: normalizedVariables, |
| 171 | }; |
| 172 | const serverParseAffecting = { |
| 173 | filters: filters.filter((filter) => !filter.clientOnly && !(filter.type === "date" && filter.startDate && filter.endDate)), |
| 174 | variables: {}, |
| 175 | }; |
| 176 | const clientOnly = { |
| 177 | filters: filters.filter((filter) => filter.clientOnly), |
| 178 | variables: {}, |
| 179 | }; |
| 180 | const cacheableChartPayload = { |
| 181 | filters: sourceAffecting.filters.concat(serverParseAffecting.filters), |
| 182 | variables: normalizedVariables, |
| 183 | }; |
no test coverage detected