save task column filter (#14587)

* save task column filter

* remove old setting

* fix tests
This commit is contained in:
negue
2023-05-15 23:01:32 +02:00
committed by GitHub
parent 9b8f213c63
commit e3a1ea6180
6 changed files with 53 additions and 26 deletions

View File

@@ -144,22 +144,6 @@
>{{ $t('startAdvCollapsed') }}</span> >{{ $t('startAdvCollapsed') }}</span>
</label> </label>
</div> </div>
<div class="checkbox">
<label>
<input
v-model="user.preferences.dailyDueDefaultView"
type="checkbox"
class="mr-2"
@change="set('dailyDueDefaultView')"
>
<span
class="hint"
popover-trigger="mouseenter"
popover-placement="right"
:popover="$t('dailyDueDefaultViewPop')"
>{{ $t('dailyDueDefaultView') }}</span>
</label>
</div>
<div <div
v-if="party.memberCount === 1" v-if="party.memberCount === 1"
class="checkbox" class="checkbox"

View File

@@ -521,7 +521,12 @@ export default {
// Get Category Filter Labels // Get Category Filter Labels
this.typeFilters = getFilterLabels(this.type, this.challenge); this.typeFilters = getFilterLabels(this.type, this.challenge);
// Set default filter for task column // Set default filter for task column
this.activateFilter(this.type);
if (this.challenge) {
this.activateFilter(this.type);
} else {
this.activateFilter(this.type, this.user.preferences.tasks.activeFilter[this.type], true);
}
}, },
mounted () { mounted () {
this.setColumnBackgroundVisibility(); this.setColumnBackgroundVisibility();
@@ -661,7 +666,7 @@ export default {
taskSummary (task) { taskSummary (task) {
this.$emit('taskSummary', task); this.$emit('taskSummary', task);
}, },
activateFilter (type, filter = '') { activateFilter (type, filter = '', skipSave = false) {
// Needs a separate API call as this data may not reside in store // Needs a separate API call as this data may not reside in store
if (type === 'todo' && filter === 'complete2') { if (type === 'todo' && filter === 'complete2') {
if (this.group && this.group._id) { if (this.group && this.group._id) {
@@ -677,14 +682,16 @@ export default {
// as default filter for daily // as default filter for daily
// and set the filter as 'due' only when the component first // and set the filter as 'due' only when the component first
// loads and not on subsequent reloads. // loads and not on subsequent reloads.
if ( if (type === 'daily' && filter === '' && !this.challenge) {
type === 'daily' && filter === '' && !this.challenge
&& this.user.preferences.dailyDueDefaultView
) {
filter = 'due'; // eslint-disable-line no-param-reassign filter = 'due'; // eslint-disable-line no-param-reassign
} }
this.activeFilter = getActiveFilter(type, filter, this.challenge); this.activeFilter = getActiveFilter(type, filter, this.challenge);
if (!skipSave && !this.challenge) {
const propertyToUpdate = `preferences.tasks.activeFilter.${type}`;
this.$store.dispatch('user:set', { [propertyToUpdate]: filter });
}
}, },
setColumnBackgroundVisibility () { setColumnBackgroundVisibility () {
this.$nextTick(() => { this.$nextTick(() => {

View File

@@ -21,6 +21,18 @@ describe('Task Column', () => {
getters: { getters: {
'tasks:getFilteredTaskList': () => [], 'tasks:getFilteredTaskList': () => [],
}, },
state: {
user: {
data: {
preferences: {
tasks: {
activeFilter: {},
},
},
},
},
},
}, },
mocks, mocks,
stubs, stubs,
@@ -76,7 +88,20 @@ describe('Task Column', () => {
'tasks:getFilteredTaskList': () => () => habits, 'tasks:getFilteredTaskList': () => () => habits,
}; };
const store = new Store({ getters }); const store = new Store({
getters,
state: {
user: {
data: {
preferences: {
tasks: {
activeFilter: {},
},
},
},
},
},
});
wrapper = makeWrapper({ store }); wrapper = makeWrapper({ store });
}); });

View File

@@ -22,7 +22,13 @@ describe('Task', () => {
state: { state: {
user: { user: {
data: { data: {
preferences: {}, preferences: {
tasks: {
activeFilter: {
},
},
},
...additionalUserData, ...additionalUserData,
}, },
}, },

View File

@@ -5,8 +5,6 @@
"helpWithTranslation": "Would you like to help with the translation of Habitica? Great! Then visit <a href=\"/groups/guild/7732f64c-33ee-4cce-873c-fc28f147a6f7\">the Aspiring Linguists Guild</a>!", "helpWithTranslation": "Would you like to help with the translation of Habitica? Great! Then visit <a href=\"/groups/guild/7732f64c-33ee-4cce-873c-fc28f147a6f7\">the Aspiring Linguists Guild</a>!",
"stickyHeader": "Sticky header", "stickyHeader": "Sticky header",
"newTaskEdit": "Open new tasks in edit mode", "newTaskEdit": "Open new tasks in edit mode",
"dailyDueDefaultView": "Set Dailies default to 'due' tab",
"dailyDueDefaultViewPop": "With this option set, the Dailies tasks will default to 'due' instead of 'all'",
"reverseChatOrder": "Show chat messages in reverse order", "reverseChatOrder": "Show chat messages in reverse order",
"startAdvCollapsed": "Advanced Settings in tasks start collapsed", "startAdvCollapsed": "Advanced Settings in tasks start collapsed",
"startAdvCollapsedPop": "With this option set, Advanced Settings will be hidden when you first open a task for editing.", "startAdvCollapsedPop": "With this option set, Advanced Settings will be hidden when you first open a task for editing.",

View File

@@ -534,6 +534,7 @@ export default new Schema({
stickyHeader: { $type: Boolean, default: true }, stickyHeader: { $type: Boolean, default: true },
disableClasses: { $type: Boolean, default: false }, disableClasses: { $type: Boolean, default: false },
newTaskEdit: { $type: Boolean, default: false }, newTaskEdit: { $type: Boolean, default: false },
// not used anymore, now the current filter is saved in preferences.activeFilter
dailyDueDefaultView: { $type: Boolean, default: false }, dailyDueDefaultView: { $type: Boolean, default: false },
advancedCollapsed: { $type: Boolean, default: false }, advancedCollapsed: { $type: Boolean, default: false },
toolbarCollapsed: { $type: Boolean, default: false }, toolbarCollapsed: { $type: Boolean, default: false },
@@ -594,6 +595,12 @@ export default new Schema({
mirrorGroupTasks: [ mirrorGroupTasks: [
{ $type: String, validate: [v => validator.isUUID(v), 'Invalid group UUID.'], ref: 'Group' }, { $type: String, validate: [v => validator.isUUID(v), 'Invalid group UUID.'], ref: 'Group' },
], ],
activeFilter: {
habit: { $type: String, default: 'all' },
daily: { $type: String, default: 'all' },
todo: { $type: String, default: 'remaining' },
reward: { $type: String, default: 'all' },
},
}, },
improvementCategories: { improvementCategories: {
$type: Array, $type: Array,