fix(accidentForm): optimize participant filtering and update localAccident handling

- Improved availableMembers computed property to handle participant IDs more robustly, ensuring correct filtering of members.
- Enhanced watch on accident to prevent unnecessary updates to localAccident, avoiding potential infinite loops.
- Refined localAccident watchers to emit updates only on relevant changes to memberId and accident text, improving performance and reducing redundant emissions.
This commit is contained in:
Torsten Schulz (local)
2026-01-14 13:41:48 +01:00
parent fea84e210a
commit c4e237cfca

View File

@@ -86,7 +86,14 @@ export default {
},
computed: {
availableMembers() {
return this.members.filter(m => this.participants.indexOf(m.id) >= 0);
// participants ist ein Array von IDs, nicht von Objekten
const participantIds = Array.isArray(this.participants)
? (this.participants.length > 0 && typeof this.participants[0] === 'object'
? this.participants.map(p => p.id || p)
: this.participants)
: [];
const participantSet = new Set(participantIds);
return this.members.filter(m => participantSet.has(m.id));
},
isValid() {
return this.localAccident.memberId && this.localAccident.accident && this.localAccident.accident.trim() !== '';
@@ -95,15 +102,20 @@ export default {
watch: {
accident: {
handler(newVal) {
this.localAccident = { ...newVal };
// Nur aktualisieren, wenn sich wirklich etwas geändert hat (verhindert Endlosschleife)
if (newVal && (newVal.memberId !== this.localAccident.memberId || newVal.accident !== this.localAccident.accident)) {
this.localAccident = { ...newVal };
}
},
deep: true
immediate: true
},
localAccident: {
handler(newVal) {
this.$emit('update:accident', newVal);
},
deep: true
'localAccident.memberId'() {
// Emit nur bei Änderung der memberId, nicht bei jeder tiefen Änderung
this.$emit('update:accident', { ...this.localAccident });
},
'localAccident.accident'() {
// Emit nur bei Änderung des accident-Textes
this.$emit('update:accident', { ...this.localAccident });
}
},
methods: {