Skip to content

Commit

Permalink
fix: fix activity orga view not reloading after filter change
Browse files Browse the repository at this point in the history
  • Loading branch information
neferin12 committed Sep 6, 2024
1 parent ea4bb45 commit ed76e58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
24 changes: 6 additions & 18 deletions client/src/components/Orga/OrgaActivities.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
</b-input-group>
<hr />
<tag-dropdown
@change="taskFilterChange"
v-model="selectedTasks"
@change="loadActivities"
:label="t('task', 2)"
:options="
tasks.map((u) => {
Expand All @@ -27,7 +28,8 @@
></tag-dropdown>
<hr />
<tag-dropdown
@change="userFilterChange"
v-model="selectedUsers"
@change="loadActivities"
:options="
users.map((u) => {
return { desc: u.name, id: u.id };
Expand Down Expand Up @@ -104,8 +106,8 @@ const errorStore = useErrorStore();
const tasks: Ref<Array<Task>> = ref([]);
const users: Ref<Array<User>> = ref([]);
const selectedTasks: Ref<Array<Task>> = ref([]);
const selectedUsers: Ref<Array<User>> = ref([]);
const selectedTasks: Ref<TagOption[]> = ref([]);
const selectedUsers: Ref<TagOption[]> = ref([]);
const activities: Ref<Activity[]> = ref([]);
Expand Down Expand Up @@ -142,18 +144,6 @@ onMounted(() => {
loadActivities();
});
function taskFilterChange(newTasks: TagOption[]) {
selectedTasks.value = newTasks.map(
(nt) => tasks.value.filter((t) => t.id === nt.id)[0]
);
}
function userFilterChange(newUsers: TagOption[]) {
selectedUsers.value = newUsers.map(
(nu) => users.value.filter((u) => u.id === nu.id)[0]
);
}
function loadActivities() {
const startDate = new Date(from.value);
const endDate = new Date(to.value);
Expand Down Expand Up @@ -245,8 +235,6 @@ function downloadJSON() {
watch(from, loadActivities);
watch(to, loadActivities);
watch(selectedTasks, loadActivities);
watch(selectedUsers, loadActivities);
</script>

<style>
Expand Down
13 changes: 6 additions & 7 deletions client/src/components/tagDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</template>

<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { computed, type ModelRef, ref, watch } from 'vue';
import type { Ref } from 'vue';
import { useI18n } from 'vue-i18n';
import type { TagOption } from '@/additionalTypes';
Expand All @@ -70,20 +70,20 @@ const props = defineProps<{
}>();
const search = ref('');
const tags: Ref<TagOption[]> = ref([]);
const tags = defineModel<TagOption[]>({ required: true });
const criteria = computed(() => {
return search.value.trim().toLowerCase();
});
const availableOptions = computed(() => {
const options = props.options.filter(
(opt) => tags.value.indexOf(opt) === -1
(opt) => tags.value.indexOf(opt) === -1,
);
if (criteria.value) {
// Show only options that match criteria
return options.filter(
(opt) => opt.desc.toLowerCase().indexOf(criteria.value) > -1
(opt) => opt.desc.toLowerCase().indexOf(criteria.value) > -1,
);
}
// Show all options available
Expand All @@ -100,17 +100,16 @@ const searchDesc = computed(() => {
function onOptionClick(option: TagOption) {
tags.value.push(option);
search.value = '';
emit('change', tags.value);
}
function removeTag(option: TagOption) {
tags.value.splice(tags.value.indexOf(option), 1);
emit('change', tags.value);
}
const emit = defineEmits<{ (e: 'change', newValue: TagOption[]): void }>();
watch(tags, () => {
emit('change', tags.value);
});
</script>

<style>
Expand Down

0 comments on commit ed76e58

Please sign in to comment.