()
| 41 | }; |
| 42 | |
| 43 | const refreshMatch = () => { |
| 44 | if (script) { |
| 45 | // 从数据库中获取是简单处理数据一致性的问题 |
| 46 | scriptDAO.get(script.uuid).then((res) => { |
| 47 | if (!res) { |
| 48 | return; |
| 49 | } |
| 50 | const matchArr = res.selfMetadata?.match || res.metadata.match || []; |
| 51 | const matchMap = new Map<string, boolean>(); |
| 52 | res.metadata.match?.forEach((m) => { |
| 53 | matchMap.set(m, true); |
| 54 | }); |
| 55 | const v: MatchItem[] = []; |
| 56 | matchArr.forEach((value, index) => { |
| 57 | v.push({ |
| 58 | id: index, |
| 59 | match: value, |
| 60 | byUser: !matchMap.has(value), |
| 61 | hasMatch: false, |
| 62 | isExclude: false, |
| 63 | }); |
| 64 | }); |
| 65 | setMatch(v); |
| 66 | |
| 67 | const excludeArr = res.selfMetadata?.exclude || res.metadata.exclude || []; |
| 68 | const excludeMap = new Map<string, boolean>(); |
| 69 | res.metadata.exclude?.forEach((m) => { |
| 70 | excludeMap.set(m, true); |
| 71 | }); |
| 72 | const e: MatchItem[] = []; |
| 73 | excludeArr.forEach((value, index) => { |
| 74 | const hasMatch = matchMap.has(value); |
| 75 | e.push({ |
| 76 | id: index, |
| 77 | match: value, |
| 78 | byUser: !excludeMap.has(value), |
| 79 | hasMatch, |
| 80 | isExclude: true, |
| 81 | }); |
| 82 | }); |
| 83 | setExclude(e); |
| 84 | }); |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | useEffect(() => { |
| 89 | refreshMatch(); |
no test coverage detected