Line data Source code
1 : import type { ConflictDetail } from '@/platform/customNodes/manager/types/conflictDetectionTypes'
2 :
3 : /**
4 : * Generates a localized conflict message for a given conflict detail.
5 : * This function should be used anywhere conflict messages need to be displayed.
6 : *
7 : * @param conflict The conflict detail object
8 : * @param t The i18n translation function
9 : * @returns A localized conflict message string
10 : */
11 0 : export function getConflictMessage(
12 : conflict: ConflictDetail,
13 : t: (key: string, params?: Record<string, unknown>) => string
14 : ): string {
15 0 : const messageKey = `manager.conflicts.conflictMessages.${conflict.type}`
16 :
17 : // For version and compatibility conflicts, use interpolated message
18 0 : if (
19 : conflict.type === 'comfyui_version' ||
20 : conflict.type === 'frontend_version' ||
21 : conflict.type === 'os' ||
22 : conflict.type === 'accelerator'
23 : ) {
24 0 : return t(messageKey, {
25 : current: conflict.current_value,
26 : required: conflict.required_value
27 : })
28 : }
29 :
30 : // For banned, pending, and import_failed, use simple message
31 0 : if (conflict.type === 'banned' || conflict.type === 'pending') {
32 0 : return t(messageKey)
33 : }
34 :
35 : // Fallback to generic message with interpolation
36 0 : return t('manager.conflicts.conflictMessages.generic', {
37 : current: conflict.current_value,
38 : required: conflict.required_value
39 : })
40 : }
41 :
42 : /**
43 : * Generates conflict messages for multiple conflicts and joins them.
44 : *
45 : * @param conflicts Array of conflict details
46 : * @param t The i18n translation function
47 : * @param separator The separator to use when joining messages (default: '; ')
48 : * @returns A single string with all conflict messages joined
49 : */
50 0 : export function getJoinedConflictMessages(
51 : conflicts: ConflictDetail[],
52 : t: (key: string, params?: Record<string, unknown>) => string,
53 : separator = '; '
54 : ): string {
55 0 : return conflicts
56 : .map((conflict) => getConflictMessage(conflict, t))
57 : .join(separator)
58 : }
|