Skip to content

Commit

Permalink
Merge branch 'fix/#52/ui-filter-content-not-updated' into 'develop'
Browse files Browse the repository at this point in the history
[Issue #52] UI Filter content not updated

See merge request canopsis/canopsis-pro!371
  • Loading branch information
mmourcia committed Nov 19, 2021
2 parents 01acb7c + ba974ea commit ceddab2
Show file tree
Hide file tree
Showing 29 changed files with 168 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { submittableMixin } from '@/mixins/submittable';
import { confirmableModalMixin } from '@/mixins/confirmable-modal';
import entitiesViewMixin from '@/mixins/entities/view';
import { entitiesViewGroupMixin } from '@/mixins/entities/view/group';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import { entitiesUserPreferenceMixin } from '@/mixins/entities/user-preference';
import { permissionsTechnicalViewMixin } from '@/mixins/permissions/technical/view';
import ViewForm from '@/components/other/view/view-form.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default {
const newValue = this.isMultiple ? selectedFilters : selectedFilters[0];
return this.$emit('update:filters', filters.map(removeSelectedProperty), newValue);
this.$emit('update:filters', filters.map(removeSelectedProperty), newValue);
},
isFilterEqual(firstFilter, secondFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@delete="showDeleteFilterModal(index)"
)
v-btn.ml-0(
data-test="addFilter",
v-if="hasAccessToAddFilter",
color="primary",
outline,
Expand Down Expand Up @@ -102,7 +101,7 @@ export default {
title: this.$t('modals.filter.edit.title'),
entitiesType: this.entitiesType,
existingTitles: this.existingTitles,
action: newFilter => this.updateItemInArray(index, newFilter),
action: newFilter => this.updateItemInArray(index, { ...filter, ...newFilter }),
},
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { generateCopyOfViewTab, getViewsTabsWidgetsIdsMappings } from '@/helpers
import { viewToRequest } from '@/helpers/forms/view';
import { authMixin } from '@/mixins/auth';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import { entitiesUserPreferenceMixin } from '@/mixins/entities/user-preference';
const { mapGetters: viewMapGetters, mapActions: viewMapActions } = createNamespacedHelpers('view');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
with-color-indicator
)
v-divider
field-default-elements-per-page(v-model="settings.widget_preferences.itemsPerPage")
field-default-elements-per-page(v-model="settings.userPreferenceContent.itemsPerPage")
v-divider
field-opened-resolved-filter(v-model="settings.widget.parameters.opened")
v-divider
Expand Down Expand Up @@ -180,17 +180,15 @@ export default {
return {
settings: {
widget: alarmListWidgetToForm(widget),
widget_preferences: {
itemsPerPage: PAGINATION_LIMIT,
},
userPreferenceContent: { itemsPerPage: PAGINATION_LIMIT },
},
};
},
mounted() {
const { widget_preferences: widgetPreference } = this.userPreference;
const { content } = this.userPreference;
this.settings.widget_preferences = {
itemsPerPage: get(widgetPreference, 'itemsPerPage', PAGINATION_LIMIT),
this.settings.userPreferenceContent = {
itemsPerPage: get(content, 'itemsPerPage', PAGINATION_LIMIT),
};
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
</template>

<script>
import { isUndefined } from 'lodash';
import { FILTER_DEFAULT_VALUES, ENTITIES_TYPES } from '@/constants';
import { authMixin } from '@/mixins/auth';
Expand Down Expand Up @@ -63,12 +61,8 @@ export default {
},
},
methods: {
updateFilters(filters, value) {
updateFilters(filters) {
this.$emit('update:filters', filters);
if (!isUndefined(value)) {
this.$emit('input', value);
}
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ export default {
},
updateCorrelation(correlation) {
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
isCorrelationEnabled: correlation,
});
Expand All @@ -229,9 +227,7 @@ export default {
updateCategory(category) {
const categoryId = category && category._id;
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
category: categoryId,
});
Expand All @@ -243,9 +239,7 @@ export default {
},
updateRecordsPerPage(limit) {
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
itemsPerPage: limit,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export default {
},
methods: {
updateNoEvents(noEvents) {
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
noEvents,
});
Expand All @@ -207,9 +205,7 @@ export default {
updateCategory(category) {
const categoryId = category && category._id;
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
category: categoryId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ export default {
updateCategory(category) {
const categoryId = category && category._id;
this.updateWidgetPreferencesInUserPreference({
...this.userPreference.widget_preferences,
this.updateContentInUserPreference({
category: categoryId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { STATS_DEFAULT_COLOR, STATS_CURVES_POINTS_STYLES } from '@/constants';
import entitiesStatsMixin from '@/mixins/entities/stats';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import widgetStatsWrapperMixin from '@/mixins/widget/stats/stats-wrapper';
import widgetStatsChartWrapperMixin from '@/mixins/widget/stats/stats-chart-wrapper';
Expand All @@ -28,7 +27,6 @@ export default {
mixins: [
entitiesStatsMixin,
widgetFetchQueryMixin,
entitiesUserPreferenceMixin,
widgetStatsWrapperMixin,
widgetStatsChartWrapperMixin,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { STATS_DEFAULT_COLOR } from '@/constants';
import entitiesStatsMixin from '@/mixins/entities/stats';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import widgetStatsWrapperMixin from '@/mixins/widget/stats/stats-wrapper';
import widgetStatsChartWrapperMixin from '@/mixins/widget/stats/stats-chart-wrapper';
Expand All @@ -28,7 +27,6 @@ export default {
mixins: [
entitiesStatsMixin,
widgetFetchQueryMixin,
entitiesUserPreferenceMixin,
widgetStatsWrapperMixin,
widgetStatsChartWrapperMixin,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { STATS_DISPLAY_MODE, STATS_CRITICITY, SORT_ORDERS } from '@/constants';
import entitiesStatsMixin from '@/mixins/entities/stats';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import widgetStatsQueryMixin from '@/mixins/widget/stats/stats-query';
import widgetStatsWrapperMixin from '@/mixins/widget/stats/stats-wrapper';
import widgetStatsTableWrapperMixin from '@/mixins/widget/stats/stats-table-wrapper';
Expand All @@ -46,7 +45,6 @@ export default {
mixins: [
entitiesStatsMixin,
widgetFetchQueryMixin,
entitiesUserPreferenceMixin,
widgetStatsQueryMixin,
widgetStatsWrapperMixin,
widgetStatsTableWrapperMixin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { dataTableCustomSortWithNullIgnoring } from '@/helpers/sort';
import entitiesStatsMixin from '@/mixins/entities/stats';
import { widgetFetchQueryMixin } from '@/mixins/widget/fetch-query';
import entitiesUserPreferenceMixin from '@/mixins/entities/user-preference';
import widgetStatsQueryMixin from '@/mixins/widget/stats/stats-query';
import widgetStatsWrapperMixin from '@/mixins/widget/stats/stats-wrapper';
import widgetStatsTableWrapperMixin from '@/mixins/widget/stats/stats-table-wrapper';
Expand All @@ -54,7 +53,6 @@ export default {
mixins: [
entitiesStatsMixin,
widgetFetchQueryMixin,
entitiesUserPreferenceMixin,
widgetStatsQueryMixin,
widgetStatsWrapperMixin,
widgetStatsTableWrapperMixin,
Expand Down
2 changes: 1 addition & 1 deletion community/sources/webcore/src/canopsis-next/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const API_ROUTES = {
contextExport: '/api/v4/entity-export',
actions: '/api/v2/actions',
event: '/api/v4/event',
userPreferences: '/rest/userpreferences/userpreferences',
userPreferences: '/api/v4/user-preferences',
view: '/api/v4/views',
bulkView: '/api/v4/bulk/views',
viewPosition: '/api/v4/view-positions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,24 +324,6 @@ export function generateViewTab(title = '') {
};
}

/**
* Generate user preference by widget and user objects
*
* @param {Object} widget
* @param {Object} user
* @returns {Object}
*/
export function generateUserPreferenceByWidgetAndUser(widget, user) {
return {
_id: `${widget._id}_${user._id}`,
widget_preferences: {},
name: user._id,
widget_id: widget._id,
widgetXtype: widget.type,
crecord_type: 'userpreferences',
};
}

/**
* Generate copy of view tab
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function getMainFilterAndCondition(widget, userPreference) {
mainFilter: userMainFilter,
mainFilterCondition: userMainFilterCondition = FILTER_MONGO_OPERATORS.and,
mainFilterUpdatedAt: userMainFilterUpdatedAt = 0,
} = userPreference.widget_preferences;
} = userPreference.content;

const {
mainFilter: widgetMainFilter,
Expand All @@ -57,7 +57,7 @@ export function getMainFilterAndCondition(widget, userPreference) {
let mainFilter = userMainFilter;
let condition = userMainFilterCondition;

if (isEmpty(mainFilter) && !isEmpty(widgetMainFilter) && widgetMainFilterUpdatedAt >= userMainFilterUpdatedAt) {
if (!isEmpty(widgetMainFilter) && widgetMainFilterUpdatedAt >= userMainFilterUpdatedAt) {
mainFilter = widgetMainFilter;
condition = widgetMainFilterCondition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function getRemediationInstructionsFilters(widget, userPreference) {
const {
disabledWidgetRemediationInstructionsFilters: disabledWidgetFilters = [],
remediationInstructionsFilters: filters = [],
} = userPreference.widget_preferences;
} = userPreference.content;

const preparedWidgetFilters = widgetFilters
.filter(filter => !disabledWidgetFilters.includes(filter._id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEFAULT_PERIODIC_REFRESH } from '@/constants';

import uuid from '../uuid';
import { durationWithEnabledToForm, formToDurationWithEnabled } from '../date/duration';
import { generateViewTab } from '../entities';
import { generateCopyOfViewTab, generateViewTab } from '../entities';

import { enabledToForm } from './shared/common';

Expand Down Expand Up @@ -277,6 +277,15 @@ export const getExportedGroupsWrappers = (groups = []) =>
return acc;
}, []);

/**
* Prepare imported view tabs
*
* @param {ViewTab[]} tabs
* @return {ViewTab[]}
*/
export const prepareImportedViewTabs = (tabs = []) =>
tabs.map(tab => generateCopyOfViewTab(tab));

/**
* Prepare imported views
*
Expand All @@ -285,7 +294,12 @@ export const getExportedGroupsWrappers = (groups = []) =>
* @return {View[]}
*/
export const prepareImportedViews = (views, group) =>
views.map(view => ({ ...view, _id: uuid(), group: group || view.group }));
views.map(view => ({
...view,
_id: uuid(),
group: group || view.group,
tabs: prepareImportedViewTabs(view.tabs),
}));

/**
* Prepare imported groups
Expand Down
21 changes: 11 additions & 10 deletions community/sources/webcore/src/canopsis-next/src/helpers/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ export function convertCounterWidgetToQuery(widget) {
* @param {Object} userPreference
* @returns {{}}
*/
export function convertAlarmUserPreferenceToQuery({ widget_preferences: widgetPreferences }) {
export function convertAlarmUserPreferenceToQuery({ content }) {
const {
itemsPerPage,
category,
isCorrelationEnabled = false,
} = widgetPreferences;
} = content;

const query = {
correlation: isCorrelationEnabled,
Expand All @@ -290,8 +290,8 @@ export function convertAlarmUserPreferenceToQuery({ widget_preferences: widgetPr
* @param {Object} userPreference
* @returns {{ category: string }}
*/
export function convertWeatherUserPreferenceToQuery({ widget_preferences: widgetPreferences }) {
const { category } = widgetPreferences;
export function convertWeatherUserPreferenceToQuery({ content }) {
const { category } = content;

return { category };
}
Expand All @@ -302,8 +302,8 @@ export function convertWeatherUserPreferenceToQuery({ widget_preferences: widget
* @param {Object} userPreference
* @returns {{ category: string }}
*/
export function convertContextUserPreferenceToQuery({ widget_preferences: widgetPreferences }) {
const { category, noEvents } = widgetPreferences;
export function convertContextUserPreferenceToQuery({ content }) {
const { category, noEvents } = content;

return {
category,
Expand All @@ -319,10 +319,11 @@ export function convertContextUserPreferenceToQuery({ widget_preferences: widget
* This function converts userPreference to query Object
*
* @param {Object} userPreference
* @returns {{}}
* @param {WidgetType} widgetType
* @returns {Object}
*/
export function convertUserPreferenceToQuery(userPreference) {
switch (userPreference.widgetXtype) {
export function convertUserPreferenceToQuery(userPreference, widgetType) {
switch (widgetType) {
case WIDGET_TYPES.alarmList:
return convertAlarmUserPreferenceToQuery(userPreference);
case WIDGET_TYPES.context:
Expand Down Expand Up @@ -375,7 +376,7 @@ export function convertWidgetToQuery(widget) {
*/
export function prepareQuery(widget, userPreference) {
const widgetQuery = convertWidgetToQuery(widget);
const userPreferenceQuery = convertUserPreferenceToQuery(userPreference);
const userPreferenceQuery = convertUserPreferenceToQuery(userPreference, widget.type);
let query = {
...widgetQuery,
...userPreferenceQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createNamespacedHelpers } from 'vuex';

const { mapActions, mapGetters } = createNamespacedHelpers('broadcastMessage');

export const entitiesBroadcastMessagesMixin = {
export const entitiesBroadcastMessageMixin = {
computed: {
...mapGetters({
broadcastMessages: 'items',
Expand Down
Loading

0 comments on commit ceddab2

Please sign in to comment.