Fix getters mutating state on repeated access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 07:31:59 +08:00
parent ef8ce0d778
commit eeea16be38
4 changed files with 77 additions and 35 deletions

View File

@@ -163,38 +163,42 @@ export const useConformanceStore = defineStore('conformanceStore', {
},
cases: state => {
if(state.allCases !== null){
const newData = state.allCases.map(c => {
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:mm');
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:mm');
c.facets.forEach(fac => {
switch(fac.type) {
return state.allCases.map(c => {
const facets = c.facets.map(fac => {
const copy = { ...fac };
switch(copy.type) {
case 'dummy': //sonar-qube
case 'duration-list':
fac.value = fac.value.map(v => v !== null ? abbreviateNumber(new Decimal(v.toFixed(2))) : null);
fac.value = (fac.value).map(v => v.trim()).join(', ');
copy.value = copy.value.map(v => v !== null ? abbreviateNumber(new Decimal(v.toFixed(2))) : null);
copy.value = (copy.value).map(v => v.trim()).join(', ');
break;
default:
break;
};
return fac;
return copy;
});
c.attributes.forEach(att => {
switch (att.type) {
const attributes = c.attributes.map(att => {
const copy = { ...att };
switch (copy.type) {
case 'date':
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:mm:ss') : null;
copy.value = copy.value !== null ? moment(copy.value).format('YYYY/MM/DD HH:mm:ss') : null;
break;
case 'float':
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
copy.value = copy.value !== null ? new Decimal(copy.value).toFixed(2) : null;
break
default:
break;
}
return att;
return copy;
});
const { facets, attributes, ...rest } = c;
return { ...rest, facets, attributes };
return {
...c,
started_at: moment(c.started_at).format('YYYY/MM/DD HH:mm'),
completed_at: moment(c.completed_at).format('YYYY/MM/DD HH:mm'),
facets,
attributes,
};
});
return newData
};
},
loopTraces: state => {
@@ -205,25 +209,28 @@ export const useConformanceStore = defineStore('conformanceStore', {
},
loopCases: state => {
if(state.allLoopCases !== null){
const newData = state.allLoopCases.map(c => {
c.started_at = moment(c.started_at).format('YYYY/MM/DD HH:mm');
c.completed_at = moment(c.completed_at).format('YYYY/MM/DD HH:mm');
c.attributes.forEach(att => {
switch (att.type) {
return state.allLoopCases.map(c => {
const attributes = c.attributes.map(att => {
const copy = { ...att };
switch (copy.type) {
case 'date':
att.value = att.value !== null ? moment(att.value).format('YYYY/MM/DD HH:mm:ss') : null;
copy.value = copy.value !== null ? moment(copy.value).format('YYYY/MM/DD HH:mm:ss') : null;
break;
case 'float':
att.value = att.value !== null ? new Decimal(att.value).toFixed(2) : null;
copy.value = copy.value !== null ? new Decimal(copy.value).toFixed(2) : null;
break
default:
break;
}
return att;
return copy;
});
return c;
return {
...c,
started_at: moment(c.started_at).format('YYYY/MM/DD HH:mm'),
completed_at: moment(c.completed_at).format('YYYY/MM/DD HH:mm'),
attributes,
};
});
return newData;
};
},
},