Skip to content

Commit 135cf3d

Browse files
authored
Merge pull request #4406 from dlabrecq/filter
Refactor `exact:` filter to work with tags
2 parents c0b1878 + e493536 commit 135cf3d

File tree

14 files changed

+131
-54
lines changed

14 files changed

+131
-54
lines changed

src/routes/details/components/breakdown/breakdownHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ class BreakdownHeader extends React.Component<BreakdownHeaderProps, any> {
100100
};
101101

102102
private hasFilterBy = () => {
103-
const { router } = this.props;
103+
const { groupBy, router } = this.props;
104104
const exclude = router.location.state?.details?.exclude;
105105
const filterBy = router.location.state?.details?.filter_by;
106-
return (exclude && Object.keys(exclude).length > 0) || (filterBy && Object.keys(filterBy).length > 0);
106+
return (
107+
(exclude && Object.keys(exclude).filter(key => key !== groupBy).length > 0) ||
108+
(filterBy && Object.keys(filterBy).filter(key => key !== groupBy).length > 0)
109+
);
107110
};
108111

109112
private getFilterChips = () => {

src/routes/details/components/historicalData/historicalDataCostChart.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { injectIntl } from 'react-intl';
1010
import { connect } from 'react-redux';
1111
import { ComputedReportItemValueType, DatumType, transformReport } from 'routes/components/charts/common/chartDatum';
1212
import { HistoricalCostChart } from 'routes/components/charts/historicalCostChart';
13-
import { getGroupById, getGroupByValue } from 'routes/utils/groupBy';
13+
import { getGroupById, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1414
import { getQueryState } from 'routes/utils/queryState';
1515
import { skeletonWidth } from 'routes/utils/skeleton';
1616
import { createMapStateToProps, FetchStatus } from 'store/common';
@@ -154,6 +154,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataCostChartOwnProps, H
154154

155155
const groupBy = getGroupById(queryFromRoute);
156156
const groupByValue = getGroupByValue(queryFromRoute);
157+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
158+
159+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
157160

158161
const baseQuery: Query = {
159162
filter_by: {
@@ -171,7 +174,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataCostChartOwnProps, H
171174
...(queryState?.exclude && queryState.exclude),
172175
},
173176
group_by: {
174-
...(groupBy && { [groupBy]: '*' }),
177+
...(groupBy && { [groupBy]: isFilterByExact ? '*' : groupByValue }),
175178
},
176179
};
177180

@@ -188,8 +191,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataCostChartOwnProps, H
188191
filter_by: {
189192
...baseQuery.filter_by,
190193
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
191-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
192-
...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Required for the "Platform" project
194+
...(isFilterByExact && {
195+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
196+
[`exact:${groupBy}`]: groupByValue,
197+
}),
193198
},
194199
};
195200

@@ -215,8 +220,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataCostChartOwnProps, H
215220
filter_by: {
216221
...baseQuery.filter_by,
217222
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
218-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
219-
...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Used by the "Platform" project
223+
...(isFilterByExact && {
224+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
225+
[`exact:${groupBy}`]: groupByValue,
226+
}),
220227
},
221228
};
222229

src/routes/details/components/historicalData/historicalDataNetworkChart.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { injectIntl } from 'react-intl';
1010
import { connect } from 'react-redux';
1111
import { DatumType, transformReport } from 'routes/components/charts/common/chartDatum';
1212
import { HistoricalUsageChart } from 'routes/components/charts/historicalUsageChart';
13-
import { getGroupById, getGroupByOrgValue, getGroupByValue } from 'routes/utils/groupBy';
13+
import { getGroupById, getGroupByOrgValue, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1414
import { getQueryState } from 'routes/utils/queryState';
1515
import { skeletonWidth } from 'routes/utils/skeleton';
1616
import { createMapStateToProps, FetchStatus } from 'store/common';
@@ -143,6 +143,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataNetworkChartOwnProps
143143
const groupByOrgValue = getGroupByOrgValue(queryFromRoute);
144144
const groupBy = getGroupById(queryFromRoute);
145145
const groupByValue = getGroupByValue(queryFromRoute);
146+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
147+
148+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
146149

147150
// instance-types and storage APIs must filter org units
148151
const useFilter = reportType === ReportType.instanceType || reportType === ReportType.storage;
@@ -167,7 +170,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataNetworkChartOwnProps
167170
},
168171
group_by: {
169172
...(groupByOrgValue && !useFilter && { [orgUnitIdKey]: groupByOrgValue }),
170-
...(groupBy && !groupByOrgValue && { [groupBy]: groupByValue }),
173+
...(groupBy && !groupByOrgValue && { [groupBy]: isFilterByExact ? '*' : groupByValue }),
171174
},
172175
};
173176

@@ -182,7 +185,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataNetworkChartOwnProps
182185
filter_by: {
183186
...baseQuery.filter_by,
184187
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
185-
...(groupBy && groupByValue !== '*' && { [groupBy]: undefined }), // Used by the "Platform" project
188+
...(isFilterByExact && {
189+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
190+
[`exact:${groupBy}`]: groupByValue,
191+
}),
186192
},
187193
};
188194

@@ -206,7 +212,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataNetworkChartOwnProps
206212
filter_by: {
207213
...baseQuery.filter_by,
208214
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
209-
...(groupBy && groupByValue !== '*' && { [groupBy]: undefined }), // Used by the "Platform" project
215+
...(isFilterByExact && {
216+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
217+
[`exact:${groupBy}`]: groupByValue,
218+
}),
210219
},
211220
};
212221

src/routes/details/components/historicalData/historicalDataTrendChart.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { injectIntl } from 'react-intl';
1010
import { connect } from 'react-redux';
1111
import { DatumType, transformReport } from 'routes/components/charts/common/chartDatum';
1212
import { HistoricalTrendChart } from 'routes/components/charts/historicalTrendChart';
13-
import { getGroupById, getGroupByOrgValue, getGroupByValue } from 'routes/utils/groupBy';
13+
import { getGroupById, getGroupByOrgValue, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1414
import { getQueryState } from 'routes/utils/queryState';
1515
import { skeletonWidth } from 'routes/utils/skeleton';
1616
import { createMapStateToProps, FetchStatus } from 'store/common';
@@ -160,6 +160,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataTrendChartOwnProps,
160160
const groupByOrgValue = getGroupByOrgValue(queryFromRoute);
161161
const groupBy = groupByOrgValue ? orgUnitIdKey : getGroupById(queryFromRoute);
162162
const groupByValue = groupByOrgValue ? groupByOrgValue : getGroupByValue(queryFromRoute);
163+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
164+
165+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
163166

164167
const baseQuery: Query = {
165168
filter_by: {
@@ -178,7 +181,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataTrendChartOwnProps,
178181
...(queryState?.exclude && queryState.exclude),
179182
},
180183
group_by: {
181-
...(groupBy && { [groupBy]: groupByValue }),
184+
...(groupBy && { [groupBy]: isFilterByExact ? '*' : groupByValue }),
182185
},
183186
};
184187

@@ -195,7 +198,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataTrendChartOwnProps,
195198
filter_by: {
196199
...baseQuery.filter_by,
197200
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
198-
...(groupBy && groupByValue !== '*' && { [groupBy]: undefined }), // Used by the "Platform" project
201+
...(isFilterByExact && {
202+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
203+
[`exact:${groupBy}`]: groupByValue,
204+
}),
199205
},
200206
};
201207

@@ -221,7 +227,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataTrendChartOwnProps,
221227
filter_by: {
222228
...baseQuery.filter_by,
223229
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
224-
...(groupBy && groupByValue !== '*' && { [groupBy]: undefined }), // Used by the "Platform" project
230+
...(isFilterByExact && {
231+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
232+
[`exact:${groupBy}`]: groupByValue,
233+
}),
225234
},
226235
};
227236

src/routes/details/components/historicalData/historicalDataUsageChart.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { injectIntl } from 'react-intl';
1010
import { connect } from 'react-redux';
1111
import { DatumType, transformReport } from 'routes/components/charts/common/chartDatum';
1212
import { HistoricalUsageChart } from 'routes/components/charts/historicalUsageChart';
13-
import { getGroupById, getGroupByOrgValue, getGroupByValue } from 'routes/utils/groupBy';
13+
import { getGroupById, getGroupByOrgValue, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1414
import { getQueryState } from 'routes/utils/queryState';
1515
import { skeletonWidth } from 'routes/utils/skeleton';
1616
import { createMapStateToProps, FetchStatus } from 'store/common';
@@ -128,6 +128,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataUsageChartOwnProps,
128128
const groupByOrgValue = getGroupByOrgValue(queryFromRoute);
129129
const groupBy = getGroupById(queryFromRoute);
130130
const groupByValue = getGroupByValue(queryFromRoute);
131+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
132+
133+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
131134

132135
// instance-types and storage APIs must filter org units
133136
const useFilter = reportType === ReportType.instanceType || reportType === ReportType.storage;
@@ -151,7 +154,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataUsageChartOwnProps,
151154
},
152155
group_by: {
153156
...(groupByOrgValue && !useFilter && { [orgUnitIdKey]: groupByOrgValue }),
154-
...(groupBy && !groupByOrgValue && { [groupBy]: '*' }),
157+
...(groupBy && !groupByOrgValue && { [groupBy]: isFilterByExact ? '*' : groupByValue }),
155158
},
156159
};
157160

@@ -166,8 +169,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataUsageChartOwnProps,
166169
filter_by: {
167170
...baseQuery.filter_by,
168171
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
169-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
170-
...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Required for the "Platform" project
172+
...(isFilterByExact && {
173+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
174+
[`exact:${groupBy}`]: groupByValue,
175+
}),
171176
},
172177
};
173178

@@ -191,8 +196,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataUsageChartOwnProps,
191196
filter_by: {
192197
...baseQuery.filter_by,
193198
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
194-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
195-
...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Used by the "Platform" project
199+
...(isFilterByExact && {
200+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
201+
[`exact:${groupBy}`]: groupByValue,
202+
}),
196203
},
197204
};
198205

src/routes/details/components/historicalData/historicalDataVolumeChart.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { injectIntl } from 'react-intl';
1010
import { connect } from 'react-redux';
1111
import { DatumType, transformReport } from 'routes/components/charts/common/chartDatum';
1212
import { HistoricalUsageChart } from 'routes/components/charts/historicalUsageChart';
13-
import { getGroupById, getGroupByOrgValue, getGroupByValue } from 'routes/utils/groupBy';
13+
import { getGroupById, getGroupByOrgValue, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1414
import { getQueryState } from 'routes/utils/queryState';
1515
import { skeletonWidth } from 'routes/utils/skeleton';
1616
import { createMapStateToProps, FetchStatus } from 'store/common';
@@ -125,6 +125,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataVolumeChartOwnProps,
125125
const groupByOrgValue = getGroupByOrgValue(queryFromRoute);
126126
const groupBy = getGroupById(queryFromRoute);
127127
const groupByValue = getGroupByValue(queryFromRoute);
128+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
129+
130+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
128131

129132
// instance-types and storage APIs must filter org units
130133
const useFilter = reportType === ReportType.instanceType || reportType === ReportType.storage;
@@ -148,7 +151,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataVolumeChartOwnProps,
148151
},
149152
group_by: {
150153
...(groupByOrgValue && !useFilter && { [orgUnitIdKey]: groupByOrgValue }),
151-
...(groupBy && !groupByOrgValue && { [groupBy]: groupByValue }),
154+
...(groupBy && !groupByOrgValue && { [groupBy]: isFilterByExact ? '*' : groupByValue }),
152155
},
153156
};
154157

@@ -163,8 +166,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataVolumeChartOwnProps,
163166
filter_by: {
164167
...baseQuery.filter_by,
165168
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
166-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
167-
...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Required for the "Platform" project
169+
...(isFilterByExact && {
170+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
171+
[`exact:${groupBy}`]: groupByValue,
172+
}),
168173
},
169174
};
170175

@@ -188,8 +193,10 @@ const mapStateToProps = createMapStateToProps<HistoricalDataVolumeChartOwnProps,
188193
filter_by: {
189194
...baseQuery.filter_by,
190195
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
191-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
192-
// ...(groupBy && groupByValue !== '*' && groupByValue === 'Platform' && { [groupBy]: undefined }), // Used by the "Platform" project
196+
...(isFilterByExact && {
197+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
198+
[`exact:${groupBy}`]: groupByValue,
199+
}),
193200
},
194201
};
195202

src/routes/details/components/pvcChart/modal/pvcContent.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { AnyAction } from 'redux';
1515
import type { ThunkDispatch } from 'redux-thunk';
1616
import { NotAvailable } from 'routes/components/page/notAvailable';
1717
import { LoadingState } from 'routes/components/state/loadingState';
18-
import { getGroupById, getGroupByValue } from 'routes/utils/groupBy';
18+
import { getGroupById, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
1919
import * as queryUtils from 'routes/utils/query';
2020
import { getQueryState } from 'routes/utils/queryState';
2121
import { getTimeScopeValue } from 'routes/utils/timeScope';
@@ -178,6 +178,9 @@ const useMapToProps = ({ query }: PvcContentMapProps): PvcContentStateProps => {
178178

179179
const groupBy = getGroupById(queryFromRoute);
180180
const groupByValue = getGroupByValue(queryFromRoute);
181+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
182+
183+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
181184
const timeScopeValue = getTimeScopeValue(queryState);
182185

183186
const reportQuery: Query = {
@@ -194,8 +197,11 @@ const useMapToProps = ({ query }: PvcContentMapProps): PvcContentStateProps => {
194197
...(queryState?.filter_by && queryState.filter_by),
195198
...(queryFromRoute?.isPlatformCosts && { category: platformCategoryKey }),
196199
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
197-
// Add exact: filter -- see https://issues.redhat.com/browse/COST-6659
198-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Note: We're not inserting PVC information for the 'Platform' project
200+
// Note: We're not inserting PVC information for the 'Platform' project
201+
...(isFilterByExact && {
202+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
203+
[`exact:${groupBy}`]: groupByValue,
204+
}),
199205
...query.filter_by,
200206
},
201207
exclude: {

src/routes/details/components/pvcChart/pvcChart.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { injectIntl } from 'react-intl';
1717
import { connect } from 'react-redux';
1818
import { getResizeObserver } from 'routes/components/charts/common/chartUtils';
1919
import { getUnsortedComputedReportItems } from 'routes/utils/computedReport/getComputedReportItems';
20-
import { getGroupById, getGroupByValue } from 'routes/utils/groupBy';
20+
import { getGroupById, getGroupByTagKey, getGroupByValue } from 'routes/utils/groupBy';
2121
import { noop } from 'routes/utils/noop';
2222
import { getQueryState } from 'routes/utils/queryState';
2323
import { skeletonWidth } from 'routes/utils/skeleton';
@@ -369,6 +369,9 @@ const mapStateToProps = createMapStateToProps<PvcChartOwnProps, PvcChartStatePro
369369

370370
const groupBy = getGroupById(queryFromRoute);
371371
const groupByValue = getGroupByValue(queryFromRoute);
372+
const groupByTagKey = getGroupByTagKey(queryFromRoute);
373+
374+
const isFilterByExact = groupBy && groupByValue !== '*' && !groupByTagKey;
372375
const timeScopeValue = getTimeScopeValue(queryState);
373376

374377
const query = { ...queryFromRoute };
@@ -384,7 +387,11 @@ const mapStateToProps = createMapStateToProps<PvcChartOwnProps, PvcChartStatePro
384387
...(queryState?.filter_by && queryState.filter_by),
385388
...(queryFromRoute?.isPlatformCosts && { category: platformCategoryKey }),
386389
// Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131 and https://issues.redhat.com/browse/COST-3642
387-
...(groupBy && groupByValue !== '*' && { [`exact:${groupBy}`]: groupByValue }), // Note: We're not inserting PVC information for the 'Platform' project
390+
// Note: We're not inserting PVC information for the 'Platform' project
391+
...(isFilterByExact && {
392+
[groupBy]: undefined, // Replace with "exact:" filter below -- see https://issues.redhat.com/browse/COST-6659
393+
[`exact:${groupBy}`]: groupByValue,
394+
}),
388395
},
389396
exclude: {
390397
...(queryState?.exclude && queryState.exclude),

0 commit comments

Comments
 (0)