fix(任务): 修复快速创建导致的重复ID
This commit is contained in:
@@ -3,6 +3,7 @@ import { create } from 'zustand';
|
||||
import type { TestCase, TestCaseStatus } from '@/lib/test-case';
|
||||
import { generateCaseNo, normalizeTestCases } from '@/lib/test-case';
|
||||
import { applyTestCaseTransition, normalizeTestCaseOnCreate } from '@/lib/test-case-workflow';
|
||||
import { createEntityId, dedupeEntityIds } from '@/lib/entity-id';
|
||||
import { loadServerData, saveServerData } from '@/lib/server-data';
|
||||
|
||||
function saveStored(items: TestCase[]) {
|
||||
@@ -33,7 +34,11 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
|
||||
|
||||
fetchTestCases: async () => {
|
||||
const cached = await loadStored();
|
||||
if (cached) set({ testCases: normalizeTestCases(cached) });
|
||||
if (cached) {
|
||||
const result = dedupeEntityIds(normalizeTestCases(cached), 'tc');
|
||||
if (result.changed) saveStored(result.items);
|
||||
set({ testCases: result.items });
|
||||
}
|
||||
},
|
||||
|
||||
createTestCase: (data) => {
|
||||
@@ -41,7 +46,7 @@ export const useTestCaseStore = create<TestCaseState>((set, get) => ({
|
||||
const now = new Date().toISOString();
|
||||
const tc: TestCase = normalizeTestCaseOnCreate({
|
||||
...data,
|
||||
id: `tc-${Date.now()}`,
|
||||
id: createEntityId('tc'),
|
||||
caseNo: generateCaseNo(list),
|
||||
status: 'pending',
|
||||
estimateHours: data.estimateHours ?? 0.5,
|
||||
|
||||
Reference in New Issue
Block a user