Skip to content

Commit

Permalink
Merge branch 'feature/#5531/default-filter-for-chart-widgets' into 'd…
Browse files Browse the repository at this point in the history
…evelop'

[Issue #5531] Default filter for chart widgets

See merge request canopsis/canopsis-pro!4017
  • Loading branch information
mmourcia committed Jul 31, 2024
2 parents 911705b + fa96afe commit 1471cf3
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<field-sampling v-field="form.parameters.default_sampling" />
<field-filters
v-if="withFilters"
v-field="form.parameters.mainFilter"
:filters="form.filters"
addable
editable
with-entity
hide-selector
@update:filters="updateFilters"
/>
<field-switcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
<field-sampling v-field="form.parameters.default_sampling" />
<field-filters
v-if="withFilters"
v-field="form.parameters.mainFilter"
:filters="form.filters"
addable
editable
with-entity
hide-selector
@update:filters="updateFilters"
/>
<field-switcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<field-sampling v-field="form.parameters.default_sampling" />
<field-filters
v-if="withFilters"
v-field="form.parameters.mainFilter"
:filters="form.filters"
addable
editable
with-entity
hide-selector
@update:filters="updateFilters"
/>
<field-switcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
<field-alarm-metric-aggregate-function v-field="form.parameters.aggregate_func" />
<field-filters
v-if="withFilters"
v-field="form.parameters.mainFilter"
:filters="form.filters"
addable
editable
with-entity
hide-selector
@update:filters="updateFilters"
/>
</widget-settings-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:widget-id="widget._id"
:user-filters="userPreference.filters"
:widget-filters="widget.filters"
:locked-value="query.lockedFilter"
:locked-filters="query.lockedFilter"
:filters="query.filter"
:interval="query.interval"
:min-interval-date="minAvailableDate"
Expand Down Expand Up @@ -51,7 +51,7 @@ import { createNamespacedHelpers } from 'vuex';
import { pick } from 'lodash';
import { convertDateToStartOfDayTimestampByTimezone } from '@/helpers/date/date';
import { convertFilterToQuery } from '@/helpers/entities/shared/query';
import { convertFiltersToQuery } from '@/helpers/entities/shared/query';
import { convertMetricsToTimezone } from '@/helpers/entities/metric/list';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
Expand Down Expand Up @@ -157,7 +157,7 @@ export default {
return {
...this.getIntervalQuery(),
...pick(this.query, ['parameters', 'sampling', 'with_history']),
widget_filters: convertFilterToQuery(this.query.filter),
widget_filters: convertFiltersToQuery(this.query.filter, this.query.lockedFilter),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:widget-id="widget._id"
:user-filters="userPreference.filters"
:widget-filters="widget.filters"
:locked-value="query.lockedFilter"
:locked-filters="query.lockedFilter"
:filters="query.filter"
:interval="query.interval"
:min-interval-date="minAvailableDate"
Expand Down Expand Up @@ -50,7 +50,7 @@ import { createNamespacedHelpers } from 'vuex';
import { pick } from 'lodash';
import { convertDateToStartOfDayTimestampByTimezone } from '@/helpers/date/date';
import { convertFilterToQuery } from '@/helpers/entities/shared/query';
import { convertFiltersToQuery } from '@/helpers/entities/shared/query';
import { convertMetricsToTimezone } from '@/helpers/entities/metric/list';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
Expand Down Expand Up @@ -156,7 +156,7 @@ export default {
return {
...this.getIntervalQuery(),
...pick(this.query, ['parameters', 'sampling', 'with_history']),
widget_filters: convertFilterToQuery(this.query.filter),
widget_filters: convertFiltersToQuery(this.query.filter, this.query.lockedFilter),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:widget-id="widget._id"
:user-filters="userPreference.filters"
:widget-filters="widget.filters"
:locked-filter="query.lockedFilter"
:locked-filters="query.lockedFilter"
:filters="query.filter"
:interval="query.interval"
:sampling="query.sampling"
Expand Down Expand Up @@ -54,7 +54,7 @@ import {
NUMBERS_CHART_MIN_AUTO_FONT_SIZE,
} from '@/constants';
import { convertFilterToQuery } from '@/helpers/entities/shared/query';
import { convertFiltersToQuery } from '@/helpers/entities/shared/query';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import { widgetFilterSelectMixin } from '@/mixins/widget/filter-select';
Expand Down Expand Up @@ -177,7 +177,7 @@ export default {
return {
...this.getIntervalQuery(),
...pick(this.query, ['parameters', 'sampling', 'with_history']),
widget_filters: convertFilterToQuery(this.query.filter),
widget_filters: convertFiltersToQuery(this.query.filter, this.query.lockedFilter),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:widget-id="widget._id"
:user-filters="userPreference.filters"
:widget-filters="widget.filters"
:locked-value="query.lockedFilter"
:locked-filters="query.lockedFilter"
:filters="query.filter"
:interval="query.interval"
:sampling="query.sampling"
Expand Down Expand Up @@ -48,7 +48,7 @@
import { createNamespacedHelpers } from 'vuex';
import { pick } from 'lodash';
import { convertFilterToQuery } from '@/helpers/entities/shared/query';
import { convertFiltersToQuery } from '@/helpers/entities/shared/query';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import { widgetFilterSelectMixin } from '@/mixins/widget/filter-select';
Expand Down Expand Up @@ -138,7 +138,7 @@ export default {
return {
...this.getIntervalQuery(),
...pick(this.query, ['parameters', 'sampling']),
widget_filters: convertFilterToQuery(this.query.filter),
widget_filters: convertFiltersToQuery(this.query.filter, this.query.lockedFilter),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
:label="$t('settings.selectAFilter')"
:filters="userFilters"
:locked-filters="widgetFilters"
:locked-value="lockedFilter"
:locked-value="lockedFilters"
:value="filters"
:disabled="filterDisabled"
class="kpi-widget-filters__filter-selector mr-4"
Expand Down Expand Up @@ -79,7 +79,7 @@ export default {
type: Array,
default: () => [],
},
lockedFilter: {
lockedFilters: {
type: [String, Array],
required: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:widget-id="widget._id"
:user-filters="userPreference.filters"
:widget-filters="widget.filters"
:locked-filter="query.lockedFilter"
:locked-filters="query.lockedFilter"
:filters="query.filter"
:interval="query.interval"
:sampling="query.sampling"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ export const convertChartUserPreferenceToQuery = ({ content: { sampling, interva
* This function converts chart widgets default parameters to query Object
*
* @param {Widget} widget
* @returns {{ sampling: string, interval: Object }}
* @returns {{ lockedFilter: string | null, sampling: string, interval: Object }}
*/
export function convertChartWidgetDefaultParametersToQuery(widget) {
const { parameters: { default_sampling: defaultSampling, default_time_range: defaultTimeRange } } = widget;
const {
mainFilter,
default_sampling: defaultSampling,
default_time_range: defaultTimeRange,
} = widget.parameters;

return {
lockedFilter: mainFilter,
sampling: defaultSampling,
interval: {
from: QUICK_RANGES[defaultTimeRange].start,
Expand All @@ -85,7 +90,7 @@ export function convertChartWidgetDefaultParametersToQuery(widget) {
* @returns {Object}
*/
export function convertChartWidgetToQuery(widget) {
const { parameters: { comparison = false, metrics = [] } } = widget;
const { comparison = false, metrics = [] } = widget.parameters;

return {
...convertChartWidgetDefaultParametersToQuery(widget),
Expand All @@ -102,7 +107,10 @@ export function convertChartWidgetToQuery(widget) {
* @returns {Object}
*/
export function convertPieChartWidgetToQuery(widget) {
const { parameters: { metrics = [], aggregate_func: widgetAggregateFunc } } = widget;
const {
metrics = [],
aggregate_func: widgetAggregateFunc,
} = widget.parameters;

return {
...convertChartWidgetDefaultParametersToQuery(widget),
Expand All @@ -121,7 +129,7 @@ export function convertPieChartWidgetToQuery(widget) {
* @returns {Object}
*/
export function convertNumbersWidgetToQuery(widget) {
const { parameters: { metrics = [], show_trend: showTrend = false } } = widget;
const { metrics = [], show_trend: showTrend = false } = widget.parameters;

return {
...convertChartWidgetDefaultParametersToQuery(widget),
Expand All @@ -142,13 +150,11 @@ export function convertNumbersWidgetToQuery(widget) {
*/
export function convertStatisticsWidgetParametersToQuery(widget) {
const {
parameters: {
mainFilter,
mainParameter = {},
widgetColumns = [],
default_time_range: defaultTimeRange,
},
} = widget;
mainFilter,
mainParameter = {},
widgetColumns = [],
default_time_range: defaultTimeRange,
} = widget.parameters;

const query = {
interval: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { metricPresetsToForm, formToMetricPresets } from '@/helpers/entities/met
* @property {string} default_time_range
* @property {Sampling} default_sampling
* @property {boolean} comparison
* @property {string | null} mainFilter
*/

/**
Expand All @@ -32,6 +33,7 @@ export const barChartWidgetParametersToForm = (parameters = {}) => ({
default_time_range: parameters.default_time_range ?? QUICK_RANGES.last30Days.value,
default_sampling: parameters.default_sampling ?? SAMPLINGS.day,
comparison: parameters.comparison ?? false,
mainFilter: parameters.mainFilter ?? null,
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { metricPresetsToForm, formToMetricPresets } from '@/helpers/entities/met
* @property {string} default_time_range
* @property {Sampling} default_sampling
* @property {boolean} comparison
* @property {string | null} mainFilter
*/

/**
Expand All @@ -30,6 +31,7 @@ export const lineChartWidgetParametersToForm = (parameters = {}) => ({
default_time_range: parameters.default_time_range ?? QUICK_RANGES.last30Days.value,
default_sampling: parameters.default_sampling ?? SAMPLINGS.day,
comparison: parameters.comparison ?? false,
mainFilter: parameters.mainFilter ?? null,
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { metricPresetsToForm, formToMetricPresets } from '@/helpers/entities/met
* @property {Sampling} default_sampling
* @property {string} show_trend
* @property {number} [font_size]
* @property {string | null} mainFilter
*/

/**
Expand All @@ -32,6 +33,7 @@ export const numbersWidgetParametersToForm = (parameters = {}) => ({
default_sampling: parameters.default_sampling ?? SAMPLINGS.day,
show_trend: parameters.show_trend ?? false,
font_size: parameters.font_size,
mainFilter: parameters.mainFilter ?? null,
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { metricPresetsToForm, formToMetricPresets } from '@/helpers/entities/met
* @property {Sampling} default_sampling
* @property {string} aggregate_func
* @property {string} show_mode
* @property {string | null} mainFilter
*/

/**
Expand All @@ -38,6 +39,7 @@ export const pieChartWidgetParametersToForm = (parameters = {}) => ({
aggregate_func: parameters.aggregate_func ?? AGGREGATE_FUNCTIONS.avg,
default_time_range: parameters.default_time_range ?? QUICK_RANGES.last30Days.value,
default_sampling: parameters.default_sampling ?? SAMPLINGS.day,
mainFilter: parameters.mainFilter ?? null,
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ exports[`bar-chart-widget-form Renders \`bar-chart-widget-form\` widget settings
addable="true"
editable="true"
filters="[object Object]"
hideselector="true"
withentity="true"
/>
<field-switcher-stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ exports[`line-chart-widget-form Renders \`line-chart-widget-form\` widget settin
addable="true"
editable="true"
filters="[object Object]"
hideselector="true"
withentity="true"
/>
<field-switcher-stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ exports[`numbers-widget-form Renders \`numbers-widget-form\` widget settings wit
addable="true"
editable="true"
filters="[object Object]"
hideselector="true"
withentity="true"
/>
<field-switcher-stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ exports[`pie-chart-widget-form Renders \`pie-chart-widget-form\` widget settings
addable="true"
editable="true"
filters="[object Object]"
hideselector="true"
withentity="true"
/>
</widget-settings-group-stub>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`kpi-widget-filters Renders 'kpi-widget-filters' with custom props 1`] = `
<div
class="layout kpi-widget-filters wrap"
lockedfilter="locked-filter-id"
>
<c-quick-date-interval-field-stub
class="kpi-widget-filters__interval"
Expand All @@ -28,7 +29,6 @@ exports[`kpi-widget-filters Renders 'kpi-widget-filters' with custom props 1`] =
itemvalue="_id"
label="Select a filter"
lockedfilters="[object Object],[object Object],[object Object],[object Object]"
lockedvalue="locked-filter-id"
value="[object Object],[object Object]"
/>
<filters-list-btn-stub
Expand Down

0 comments on commit 1471cf3

Please sign in to comment.