@e-llm-studio/instant-learning 1.3.22 → 1.3.24-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/features/LearningManagement/LearningManagement.js +27 -0
- package/dist/cjs/features/LearningManagement/LearningManagement.js.map +1 -1
- package/dist/cjs/features/LearningManagement/LearningTemplateLayout.js +4 -2
- package/dist/cjs/features/LearningManagement/LearningTemplateLayout.js.map +1 -1
- package/dist/cjs/features/LearningManagement/RuleContent/RuleContent.js +11 -1
- package/dist/cjs/features/LearningManagement/RuleContent/RuleContent.js.map +1 -1
- package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js +39 -29
- package/dist/cjs/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
- package/dist/cjs/features/LearningManagement/utils/learningFlow.js +92 -0
- package/dist/cjs/features/LearningManagement/utils/learningFlow.js.map +1 -1
- package/dist/cjs/schema-driven/components/FileUploadField.js +76 -13
- package/dist/cjs/schema-driven/components/FileUploadField.js.map +1 -1
- package/dist/cjs/schema-driven/components/FileUploadField.module.css.js +1 -1
- package/dist/cjs/schema-driven/components/PromptTextEditorField.js +100 -23
- package/dist/cjs/schema-driven/components/PromptTextEditorField.js.map +1 -1
- package/dist/cjs/schema-driven/utils/fileUploadService.js +46 -0
- package/dist/cjs/schema-driven/utils/fileUploadService.js.map +1 -1
- package/dist/features/LearningManagement/LearningManagement.js +27 -0
- package/dist/features/LearningManagement/LearningManagement.js.map +1 -1
- package/dist/features/LearningManagement/LearningTemplateLayout.js +4 -2
- package/dist/features/LearningManagement/LearningTemplateLayout.js.map +1 -1
- package/dist/features/LearningManagement/RuleContent/RuleContent.js +11 -1
- package/dist/features/LearningManagement/RuleContent/RuleContent.js.map +1 -1
- package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js +41 -31
- package/dist/features/LearningManagement/components/InstantLearningModalDynamic.js.map +1 -1
- package/dist/features/LearningManagement/utils/learningFlow.js +92 -1
- package/dist/features/LearningManagement/utils/learningFlow.js.map +1 -1
- package/dist/schema-driven/components/FileUploadField.js +78 -15
- package/dist/schema-driven/components/FileUploadField.js.map +1 -1
- package/dist/schema-driven/components/FileUploadField.module.css.js +1 -1
- package/dist/schema-driven/components/PromptTextEditorField.js +100 -23
- package/dist/schema-driven/components/PromptTextEditorField.js.map +1 -1
- package/dist/schema-driven/utils/fileUploadService.js +45 -1
- package/dist/schema-driven/utils/fileUploadService.js.map +1 -1
- package/dist/types/src/features/LearningManagement/LearningManagement.d.ts +11 -1
- package/dist/types/src/features/LearningManagement/LearningManagement.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/LearningManagementTest.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts +9 -0
- package/dist/types/src/features/LearningManagement/LearningTemplateLayout.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts +9 -0
- package/dist/types/src/features/LearningManagement/RuleContent/RuleContent.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/components/InstantLearningModalDynamic.d.ts.map +1 -1
- package/dist/types/src/features/LearningManagement/utils/learningFlow.d.ts +4 -0
- package/dist/types/src/features/LearningManagement/utils/learningFlow.d.ts.map +1 -1
- package/dist/types/src/schema-driven/components/FileUploadField.d.ts +1 -1
- package/dist/types/src/schema-driven/components/FileUploadField.d.ts.map +1 -1
- package/dist/types/src/schema-driven/components/PromptTextEditorField.d.ts.map +1 -1
- package/dist/types/src/schema-driven/utils/fileUploadService.d.ts +26 -0
- package/dist/types/src/schema-driven/utils/fileUploadService.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { useDynamicFormStore } from '../../../schema-driven/store/useDynamicFormStore.js';
|
|
2
|
+
import { useLearningTemplateStore } from '../store/useLearningTemplateStore.js';
|
|
3
|
+
|
|
1
4
|
const resolveIsEditMode = ({
|
|
2
5
|
flow,
|
|
3
6
|
editingRule,
|
|
@@ -6,6 +9,94 @@ const resolveIsEditMode = ({
|
|
|
6
9
|
if (flow) return flow === "edit";
|
|
7
10
|
return !!(editingRule || editingVariants && editingVariants.length > 0);
|
|
8
11
|
};
|
|
12
|
+
const seedHostFormValues = (schema, input) => {
|
|
13
|
+
var _a, _b, _c, _d, _e, _f;
|
|
14
|
+
if (!input || Object.keys(input).length === 0) return;
|
|
15
|
+
const globalValues = {};
|
|
16
|
+
const variantValues = {};
|
|
17
|
+
const learningMetadata = {
|
|
18
|
+
...(_b = (_a = input.learningMetadata) != null ? _a : input.learning_metadata) != null ? _b : {}
|
|
19
|
+
};
|
|
20
|
+
const metadataValues = (_c = learningMetadata.properties) != null ? _c : learningMetadata;
|
|
21
|
+
const hasValue = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
22
|
+
const normalizeFieldKey = (key) => key.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
23
|
+
const unwrapValue = (value) => value && typeof value === "object" && !Array.isArray(value) && hasValue(value, "value") ? value.value : value;
|
|
24
|
+
const traverse = (properties = {}, inVariant = false) => {
|
|
25
|
+
Object.entries(properties).forEach(([propertyKey, node]) => {
|
|
26
|
+
var _a2, _b2, _c2, _d2;
|
|
27
|
+
const dataKey = node == null ? void 0 : node.data_key;
|
|
28
|
+
const cleanKey = typeof dataKey === "string" ? dataKey.replace(/^global\./, "") : propertyKey;
|
|
29
|
+
const sources = [input, metadataValues];
|
|
30
|
+
const aliases = {
|
|
31
|
+
rule_title: ["title", "ruleTitle"],
|
|
32
|
+
rule_description: ["description", "ruleDescription"],
|
|
33
|
+
wta: ["whenToApply", "when_to_apply"],
|
|
34
|
+
wnta: ["whenNotToApply", "when_not_to_apply"],
|
|
35
|
+
instruction_prompt: ["instructionPrompt"]
|
|
36
|
+
};
|
|
37
|
+
const candidateKeys = [cleanKey, dataKey, propertyKey, ...(_a2 = aliases[propertyKey]) != null ? _a2 : []].filter(Boolean);
|
|
38
|
+
let matchedKey;
|
|
39
|
+
let matchedSource;
|
|
40
|
+
for (const source of sources) {
|
|
41
|
+
matchedKey = candidateKeys.find((key) => hasValue(source, key));
|
|
42
|
+
if (!matchedKey) {
|
|
43
|
+
const normalizedCandidates = new Set(candidateKeys.map(normalizeFieldKey));
|
|
44
|
+
matchedKey = Object.keys(source).find((key) => normalizedCandidates.has(normalizeFieldKey(key)));
|
|
45
|
+
}
|
|
46
|
+
if (matchedKey) {
|
|
47
|
+
matchedSource = source;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (matchedKey) {
|
|
52
|
+
let value = unwrapValue(matchedSource[matchedKey]);
|
|
53
|
+
if ((node == null ? void 0 : node.bpa_ui_component) === "ConditionSection" && Array.isArray(value)) {
|
|
54
|
+
value = value.map((item) => typeof item === "string" ? item : item == null ? void 0 : item.text).filter((item) => typeof item === "string" && item.trim()).join(" OR ");
|
|
55
|
+
}
|
|
56
|
+
const isVariantField = inVariant && !String(dataKey != null ? dataKey : "").startsWith("global.");
|
|
57
|
+
if (isVariantField) {
|
|
58
|
+
(_b2 = variantValues.tier_1) != null ? _b2 : variantValues.tier_1 = {};
|
|
59
|
+
(_d2 = (_c2 = variantValues.tier_1)[0]) != null ? _d2 : _c2[0] = {};
|
|
60
|
+
variantValues.tier_1[0][cleanKey] = value;
|
|
61
|
+
} else {
|
|
62
|
+
globalValues[cleanKey] = value;
|
|
63
|
+
}
|
|
64
|
+
if ((node == null ? void 0 : node.core_field) === false) {
|
|
65
|
+
learningMetadata[propertyKey] = value;
|
|
66
|
+
}
|
|
67
|
+
if (propertyKey === "instruction_prompt" || cleanKey === "instructionPrompt") {
|
|
68
|
+
learningMetadata.instruction_prompt = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (node == null ? void 0 : node.properties) {
|
|
72
|
+
const isVariantWrapper = (node == null ? void 0 : node.is_repeatable_variant) === true || (node == null ? void 0 : node.bpa_ui_component) === "VariantListWrapper";
|
|
73
|
+
traverse(node.properties, inVariant || isVariantWrapper);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const schemaRoot = (_d = schema == null ? void 0 : schema.teachMe) != null ? _d : schema;
|
|
78
|
+
if (schemaRoot == null ? void 0 : schemaRoot.properties) {
|
|
79
|
+
traverse(schemaRoot.properties);
|
|
80
|
+
} else {
|
|
81
|
+
Object.entries(input).forEach(([key, value]) => {
|
|
82
|
+
if (key !== "learningMetadata" && key !== "learning_metadata") globalValues[key] = value;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const explicitMetadata = (_e = input.learningMetadata) != null ? _e : input.learning_metadata;
|
|
86
|
+
if (explicitMetadata && typeof explicitMetadata === "object") {
|
|
87
|
+
Object.assign(learningMetadata, (_f = explicitMetadata.properties) != null ? _f : explicitMetadata);
|
|
88
|
+
}
|
|
89
|
+
if (hasValue(input, "instructionPrompt")) {
|
|
90
|
+
learningMetadata.instruction_prompt = input.instructionPrompt;
|
|
91
|
+
}
|
|
92
|
+
useDynamicFormStore.getState().initializeStore(globalValues, variantValues);
|
|
93
|
+
if (Object.keys(learningMetadata).length > 0) {
|
|
94
|
+
useLearningTemplateStore.getState().setLearningMetadata({
|
|
95
|
+
...useLearningTemplateStore.getState().learningMetadata,
|
|
96
|
+
...learningMetadata
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
9
100
|
|
|
10
|
-
export { resolveIsEditMode };
|
|
101
|
+
export { resolveIsEditMode, seedHostFormValues };
|
|
11
102
|
//# sourceMappingURL=learningFlow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learningFlow.js","sources":["../../../../src/features/LearningManagement/utils/learningFlow.ts"],"sourcesContent":["import { RuleDefinition, RuleVariant } from '../types';\n\n/**\n * Explicit source of truth for which Teach Me flow the modal is in.\n *\n * - `\"create\"` → Create/Add UI, ALWAYS, regardless of whether the RHS has\n * pre-populated variant data (e.g. a draft variant seeded into `editingVariants`).\n * - `\"edit\"` → Edit UI for an existing rule/variant.\n *\n * Decoupling the flow from the mere presence of `editingVariants` is what lets a\n * draft variant be populated into the RHS while the form still behaves as a new\n * learning. See RuleContent's `handleEditVariant` for where a draft click sets\n * `flow = \"create\"`.\n */\nexport type InstantLearningFlow = 'create' | 'edit';\n\nexport interface ResolveIsEditModeArgs {\n /** Explicit flow. When provided it is the sole source of truth. */\n flow?: InstantLearningFlow | null;\n editingRule?: RuleDefinition | null;\n editingVariants?: RuleVariant[] | null;\n}\n\n/**\n * Single source of truth for \"is the modal in edit mode?\".\n *\n * When an explicit `flow` is provided it wins outright — so `flow === \"create\"`\n * always means Create/Add even when `editingVariants` is populated. When `flow`\n * is absent we fall back to the legacy heuristic (`editingRule || editingVariants`)\n * so existing callers that don't yet pass `flow` keep their exact behavior.\n */\nexport const resolveIsEditMode = ({\n flow,\n editingRule,\n editingVariants,\n}: ResolveIsEditModeArgs): boolean => {\n if (flow) return flow === 'edit';\n return !!(editingRule || (editingVariants && editingVariants.length > 0));\n};\n"],"names":[],"mappings":"AA+BO,MAAM,oBAAoB,CAAC;AAAA,EAChC,IAAA;AAAA,EACA,WAAA;AAAA,EACA,eAAA;AACF,CAAsC,KAAA;AACpC,EAAI,IAAA,IAAA,SAAa,IAAS,KAAA,MAAA,CAAA;AAC1B,EAAA,OAAO,CAAC,EAAE,WAAgB,IAAA,eAAA,IAAmB,gBAAgB,MAAS,GAAA,CAAA,CAAA,CAAA;AACxE;;;;"}
|
|
1
|
+
{"version":3,"file":"learningFlow.js","sources":["../../../../src/features/LearningManagement/utils/learningFlow.ts"],"sourcesContent":["import { useDynamicFormStore } from '../../../schema-driven/store/useDynamicFormStore';\nimport { useLearningTemplateStore } from '../store/useLearningTemplateStore';\nimport { RuleDefinition, RuleVariant } from '../types';\n\n/**\n * Explicit source of truth for which Teach Me flow the modal is in.\n *\n * - `\"create\"` → Create/Add UI, ALWAYS, regardless of whether the RHS has\n * pre-populated variant data (e.g. a draft variant seeded into `editingVariants`).\n * - `\"edit\"` → Edit UI for an existing rule/variant.\n *\n * Decoupling the flow from the mere presence of `editingVariants` is what lets a\n * draft variant be populated into the RHS while the form still behaves as a new\n * learning. See RuleContent's `handleEditVariant` for where a draft click sets\n * `flow = \"create\"`.\n */\nexport type InstantLearningFlow = 'create' | 'edit';\n\nexport interface ResolveIsEditModeArgs {\n /** Explicit flow. When provided it is the sole source of truth. */\n flow?: InstantLearningFlow | null;\n editingRule?: RuleDefinition | null;\n editingVariants?: RuleVariant[] | null;\n}\n\n/**\n * Single source of truth for \"is the modal in edit mode?\".\n *\n * When an explicit `flow` is provided it wins outright — so `flow === \"create\"`\n * always means Create/Add even when `editingVariants` is populated. When `flow`\n * is absent we fall back to the legacy heuristic (`editingRule || editingVariants`)\n * so existing callers that don't yet pass `flow` keep their exact behavior.\n */\n\nexport const resolveIsEditMode = ({\n flow,\n editingRule,\n editingVariants,\n}: ResolveIsEditModeArgs): boolean => {\n if (flow) return flow === 'edit';\n return !!(editingRule || (editingVariants && editingVariants.length > 0));\n};\n\n\n/** Seed host-provided values into both the schema-driven RHS store and legacy\n * learningMetadata store. Form values can be keyed by data_key or schema\n * property name; variant fields land in the first create variant. */\nexport const seedHostFormValues = (schema: any, input: Record<string, any>) => {\n if (!input || Object.keys(input).length === 0) return;\n\n const globalValues: Record<string, any> = {};\n const variantValues: Record<string, Record<number, Record<string, any>>> = {};\n const learningMetadata: Record<string, any> = {\n ...(input.learningMetadata ?? input.learning_metadata ?? {}),\n };\n const metadataValues = learningMetadata.properties ?? learningMetadata;\n const hasValue = (source: Record<string, any>, key: string) =>\n Object.prototype.hasOwnProperty.call(source, key);\n const normalizeFieldKey = (key: string) => key.replace(/[^a-z0-9]/gi, '').toLowerCase();\n const unwrapValue = (value: any) =>\n value && typeof value === 'object' && !Array.isArray(value) && hasValue(value, 'value')\n ? value.value\n : value;\n\n const traverse = (properties: Record<string, any> = {}, inVariant = false) => {\n Object.entries(properties).forEach(([propertyKey, node]) => {\n const dataKey = node?.data_key;\n const cleanKey = typeof dataKey === 'string' ? dataKey.replace(/^global\\./, '') : propertyKey;\n const sources = [input, metadataValues];\n const aliases: Record<string, string[]> = {\n rule_title: ['title', 'ruleTitle'],\n rule_description: ['description', 'ruleDescription'],\n wta: ['whenToApply', 'when_to_apply'],\n wnta: ['whenNotToApply', 'when_not_to_apply'],\n instruction_prompt: ['instructionPrompt'],\n };\n const candidateKeys = [cleanKey, dataKey, propertyKey, ...(aliases[propertyKey] ?? [])]\n .filter(Boolean) as string[];\n let matchedKey: string | undefined;\n let matchedSource: Record<string, any> | undefined;\n for (const source of sources) {\n matchedKey = candidateKeys.find((key) => hasValue(source, key));\n if (!matchedKey) {\n const normalizedCandidates = new Set(candidateKeys.map(normalizeFieldKey));\n matchedKey = Object.keys(source).find((key) => normalizedCandidates.has(normalizeFieldKey(key)));\n }\n if (matchedKey) {\n matchedSource = source;\n break;\n }\n }\n\n if (matchedKey) {\n let value = unwrapValue(matchedSource![matchedKey]);\n // ConditionSectionField displays conditions by splitting an OR-delimited\n // string. Accept host arrays too, so common formValues arrays render.\n if (node?.bpa_ui_component === 'ConditionSection' && Array.isArray(value)) {\n value = value\n .map((item: any) => typeof item === 'string' ? item : item?.text)\n .filter((item: any) => typeof item === 'string' && item.trim())\n .join(' OR ');\n }\n const isVariantField = inVariant && !String(dataKey ?? '').startsWith('global.');\n if (isVariantField) {\n variantValues.tier_1 ??= {};\n variantValues.tier_1[0] ??= {};\n variantValues.tier_1[0][cleanKey] = value;\n } else {\n globalValues[cleanKey] = value;\n }\n\n if (node?.core_field === false) {\n learningMetadata[propertyKey] = value;\n }\n if (propertyKey === 'instruction_prompt' || cleanKey === 'instructionPrompt') {\n learningMetadata.instruction_prompt = value;\n }\n }\n\n if (node?.properties) {\n const isVariantWrapper =\n node?.is_repeatable_variant === true || node?.bpa_ui_component === 'VariantListWrapper';\n traverse(node.properties, inVariant || isVariantWrapper);\n }\n });\n };\n\n const schemaRoot = schema?.teachMe ?? schema;\n if (schemaRoot?.properties) {\n traverse(schemaRoot.properties);\n } else {\n Object.entries(input).forEach(([key, value]) => {\n if (key !== 'learningMetadata' && key !== 'learning_metadata') globalValues[key] = value;\n });\n }\n\n // Preserve metadata supplied in its API shape while also accepting flat\n // property values from formValues.\n const explicitMetadata = input.learningMetadata ?? input.learning_metadata;\n if (explicitMetadata && typeof explicitMetadata === 'object') {\n Object.assign(learningMetadata, explicitMetadata.properties ?? explicitMetadata);\n }\n if (hasValue(input, 'instructionPrompt')) {\n learningMetadata.instruction_prompt = input.instructionPrompt;\n }\n\n useDynamicFormStore.getState().initializeStore(globalValues, variantValues);\n if (Object.keys(learningMetadata).length > 0) {\n useLearningTemplateStore.getState().setLearningMetadata({\n ...useLearningTemplateStore.getState().learningMetadata,\n ...learningMetadata,\n });\n }\n};"],"names":["_a","_b","_c","_d"],"mappings":";;;AAkCO,MAAM,oBAAoB,CAAC;AAAA,EAChC,IAAA;AAAA,EACA,WAAA;AAAA,EACA,eAAA;AACF,CAAsC,KAAA;AACpC,EAAI,IAAA,IAAA,SAAa,IAAS,KAAA,MAAA,CAAA;AAC1B,EAAA,OAAO,CAAC,EAAE,WAAgB,IAAA,eAAA,IAAmB,gBAAgB,MAAS,GAAA,CAAA,CAAA,CAAA;AACxE,EAAA;AAMa,MAAA,kBAAA,GAAqB,CAAC,MAAA,EAAa,KAA+B,KAAA;AA/C/E,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AAgDE,EAAA,IAAI,CAAC,KAAS,IAAA,MAAA,CAAO,KAAK,KAAK,CAAA,CAAE,WAAW,CAAG,EAAA,OAAA;AAE/C,EAAA,MAAM,eAAoC,EAAC,CAAA;AAC3C,EAAA,MAAM,gBAAqE,EAAC,CAAA;AAC5E,EAAA,MAAM,gBAAwC,GAAA;AAAA,IAC5C,IAAI,EAAM,GAAA,CAAA,EAAA,GAAA,KAAA,CAAA,gBAAA,KAAN,YAA0B,KAAM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AAA,CAAA;AAAA,GAC9C;AAEA,EAAA,mBAAA,CAAoB,QAAS,EAAA,CAAE,eAAgB,CAAA,YAAA,EAAc,aAAa,CAAA,CAAA;AAC1E,EAAA,IAAI,MAAO,CAAA,IAAA,CAAK,gBAAgB,CAAA,CAAE,SAAS,CAAG,EAAA;AAC5C,IAAyB,wBAAA,CAAA,QAAA,GAAW,mBAAoB,CAAA;AAAA,MACtD,GAAG,wBAAyB,CAAA,QAAA,EAAW,CAAA,gBAAA;AAAA,MACvC,GAAG,gBAAA;AAAA,KACJ,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
-
import { AlertCircle, X, Upload, FileText, Loader2, Check, Pencil } from 'lucide-react';
|
|
3
|
+
import { AlertCircle, X, Upload, FileText, Loader2, Trash2, Check, Pencil } from 'lucide-react';
|
|
4
4
|
import { SectionWrapper } from '../../features/IL-OTJ/_components/molecules/Sections/SectionWrapper.js';
|
|
5
5
|
import { InputDataReasoningCard } from '../../features/IL-OTJ/_components/InputDataReasoningCard.js';
|
|
6
6
|
import { ButtonCognitiveIcon } from '../../features/IL-OTJ/_components/_svg/ButtonCognitiveIcon.js';
|
|
@@ -9,7 +9,7 @@ import useEnvStore from '../../features/LearningManagement/store/useEnvStore.js'
|
|
|
9
9
|
import { useConfigStore } from '../../features/LearningManagement/store/useConfigStore.js';
|
|
10
10
|
import { useLearningTemplateStore } from '../../features/LearningManagement/store/useLearningTemplateStore.js';
|
|
11
11
|
import useAuthStore from '../../features/LearningManagement/store/useAuthStore.js';
|
|
12
|
-
import { parseMaxFileSizeBytes, formatFileSize, normalizeAcceptString, getGCSSignedUrl, isFileAccepted, isImageFile, uploadFilesBatch, getFileExtension } from '../utils/fileUploadService.js';
|
|
12
|
+
import { parseMaxFileSizeBytes, formatFileSize, normalizeAcceptString, getGCSSignedUrl, isFileAccepted, createTimestampedFile, isImageFile, uploadFilesBatch, getFileExtension, deleteFileFromGCS } from '../utils/fileUploadService.js';
|
|
13
13
|
import { getOptionalGuidelineRuntimeConfig } from '../../features/IL-marketplace/services/guideline.runtime.config.js';
|
|
14
14
|
import styles from './FileUploadField.module.css.js';
|
|
15
15
|
|
|
@@ -78,7 +78,10 @@ function FileUploadField(props) {
|
|
|
78
78
|
const [duplicateWarning, setDuplicateWarning] = useState(null);
|
|
79
79
|
const [formatWarning, setFormatWarning] = useState(null);
|
|
80
80
|
const [sizeWarning, setSizeWarning] = useState(null);
|
|
81
|
+
const [emptyFileWarning, setEmptyFileWarning] = useState(null);
|
|
81
82
|
const [limitWarning, setLimitWarning] = useState(null);
|
|
83
|
+
const [deleteWarning, setDeleteWarning] = useState(null);
|
|
84
|
+
const [deletingFileIds, setDeletingFileIds] = useState(() => /* @__PURE__ */ new Set());
|
|
82
85
|
const fileInputRef = useRef(null);
|
|
83
86
|
const { getGlobalField, getVariantField, clearAllMirages, getGlobalMirage, getVariantMirage } = useDynamicFormStore();
|
|
84
87
|
const dataKey = (schema == null ? void 0 : schema.data_key) || id;
|
|
@@ -258,7 +261,9 @@ function FileUploadField(props) {
|
|
|
258
261
|
setDuplicateWarning(null);
|
|
259
262
|
setFormatWarning(null);
|
|
260
263
|
setSizeWarning(null);
|
|
264
|
+
setEmptyFileWarning(null);
|
|
261
265
|
setLimitWarning(null);
|
|
266
|
+
setDeleteWarning(null);
|
|
262
267
|
const remainingSlots = isFinite(effectiveMaxUploads) ? Math.max(0, effectiveMaxUploads - filesList.length) : Infinity;
|
|
263
268
|
if (remainingSlots <= 0) {
|
|
264
269
|
setLimitWarning(
|
|
@@ -282,8 +287,11 @@ function FileUploadField(props) {
|
|
|
282
287
|
const validFiles = [];
|
|
283
288
|
const invalidFiles = [];
|
|
284
289
|
const oversizedFiles = [];
|
|
290
|
+
const emptyFiles = [];
|
|
285
291
|
for (const file of filesToProcess) {
|
|
286
|
-
if (
|
|
292
|
+
if (file.size === 0) {
|
|
293
|
+
emptyFiles.push(file);
|
|
294
|
+
} else if (!isFileAccepted(file, normalizedAccept)) {
|
|
287
295
|
invalidFiles.push(file);
|
|
288
296
|
} else if (effectiveMaxFileSizeBytes !== null && file.size > effectiveMaxFileSizeBytes) {
|
|
289
297
|
oversizedFiles.push(file);
|
|
@@ -301,14 +309,23 @@ function FileUploadField(props) {
|
|
|
301
309
|
const message = oversizedFiles.length === 1 ? `File "${oversizedNames}" exceeds the ${maxFileSizeLabel} per-file size limit.` : `Files "${oversizedNames}" exceed the ${maxFileSizeLabel} per-file size limit.`;
|
|
302
310
|
setSizeWarning(message);
|
|
303
311
|
}
|
|
312
|
+
if (emptyFiles.length > 0) {
|
|
313
|
+
const emptyNames = emptyFiles.map((file) => file.name).join(", ");
|
|
314
|
+
const message = emptyFiles.length === 1 ? `File "${emptyNames}" is empty and cannot be uploaded.` : `Files "${emptyNames}" are empty and cannot be uploaded.`;
|
|
315
|
+
setEmptyFileWarning(message);
|
|
316
|
+
}
|
|
304
317
|
if (validFiles.length === 0) {
|
|
305
318
|
if (fileInputRef.current) {
|
|
306
319
|
fileInputRef.current.value = "";
|
|
307
320
|
}
|
|
308
321
|
return;
|
|
309
322
|
}
|
|
323
|
+
const uploadTimestamp = Date.now();
|
|
324
|
+
const filesForUpload = validFiles.map(
|
|
325
|
+
(file, index) => createTimestampedFile(file, uploadTimestamp, index)
|
|
326
|
+
);
|
|
310
327
|
setIsUploading(true);
|
|
311
|
-
const optimisticItems =
|
|
328
|
+
const optimisticItems = filesForUpload.map((file, i) => {
|
|
312
329
|
const isImg = isImageFile(file.name, file.type);
|
|
313
330
|
let previewBlobUrl = void 0;
|
|
314
331
|
try {
|
|
@@ -333,7 +350,7 @@ function FileUploadField(props) {
|
|
|
333
350
|
try {
|
|
334
351
|
const result = await uploadFilesBatch({
|
|
335
352
|
projectId: resolvedProjectId || "",
|
|
336
|
-
files:
|
|
353
|
+
files: filesForUpload,
|
|
337
354
|
token: resolvedToken,
|
|
338
355
|
artifactUserName: resolvedUserName,
|
|
339
356
|
artifactUserEmail: resolvedUserEmail,
|
|
@@ -473,25 +490,66 @@ function FileUploadField(props) {
|
|
|
473
490
|
if (!isEditing) return;
|
|
474
491
|
(_a2 = fileInputRef.current) == null ? void 0 : _a2.click();
|
|
475
492
|
};
|
|
476
|
-
const
|
|
493
|
+
const handleDeleteFile = async (file, e) => {
|
|
477
494
|
e.stopPropagation();
|
|
478
495
|
if (!isEditing || !onChange) return;
|
|
496
|
+
if (deletingFileIds.has(file.id)) return;
|
|
479
497
|
setDuplicateWarning(null);
|
|
480
498
|
setFormatWarning(null);
|
|
481
499
|
setSizeWarning(null);
|
|
500
|
+
setEmptyFileWarning(null);
|
|
482
501
|
setLimitWarning(null);
|
|
502
|
+
setDeleteWarning(null);
|
|
483
503
|
if (fileInputRef.current) {
|
|
484
504
|
fileInputRef.current.value = "";
|
|
485
505
|
}
|
|
486
|
-
|
|
487
|
-
|
|
506
|
+
if (!file.url) {
|
|
507
|
+
if (file.status === "error") {
|
|
508
|
+
onChange(filesList.filter((item) => item.id !== file.id));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
setDeleteWarning(`Cannot delete "${file.name}": its storage path is unavailable.`);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
setDeletingFileIds((currentIds) => new Set(currentIds).add(file.id));
|
|
515
|
+
try {
|
|
516
|
+
const result = await deleteFileFromGCS({
|
|
517
|
+
projectId: resolvedProjectId || "",
|
|
518
|
+
fileUrl: file.url,
|
|
519
|
+
token: resolvedToken
|
|
520
|
+
});
|
|
521
|
+
if (result.error) {
|
|
522
|
+
setDeleteWarning(`Failed to delete "${file.name}": ${result.error.errorMessage}`);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
if (file.url) {
|
|
526
|
+
setSignedUrlMap((currentUrls) => {
|
|
527
|
+
const nextUrls = { ...currentUrls };
|
|
528
|
+
delete nextUrls[file.url];
|
|
529
|
+
return nextUrls;
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
onChange(filesList.filter((item) => item.id !== file.id));
|
|
533
|
+
} catch (error) {
|
|
534
|
+
setDeleteWarning(
|
|
535
|
+
`Failed to delete "${file.name}": ${(error == null ? void 0 : error.message) || "Unexpected error"}`
|
|
536
|
+
);
|
|
537
|
+
} finally {
|
|
538
|
+
setDeletingFileIds((currentIds) => {
|
|
539
|
+
const nextIds = new Set(currentIds);
|
|
540
|
+
nextIds.delete(file.id);
|
|
541
|
+
return nextIds;
|
|
542
|
+
});
|
|
543
|
+
}
|
|
488
544
|
};
|
|
489
545
|
const inlineSnapshotRef = useRef(null);
|
|
490
546
|
const handleInlineStart = () => {
|
|
491
547
|
setDuplicateWarning(null);
|
|
492
548
|
setFormatWarning(null);
|
|
493
549
|
setSizeWarning(null);
|
|
550
|
+
setEmptyFileWarning(null);
|
|
494
551
|
setLimitWarning(null);
|
|
552
|
+
setDeleteWarning(null);
|
|
495
553
|
inlineSnapshotRef.current = JSON.parse(JSON.stringify(filesList));
|
|
496
554
|
setActiveEditId == null ? void 0 : setActiveEditId(id);
|
|
497
555
|
};
|
|
@@ -503,7 +561,9 @@ function FileUploadField(props) {
|
|
|
503
561
|
setDuplicateWarning(null);
|
|
504
562
|
setFormatWarning(null);
|
|
505
563
|
setSizeWarning(null);
|
|
564
|
+
setEmptyFileWarning(null);
|
|
506
565
|
setLimitWarning(null);
|
|
566
|
+
setDeleteWarning(null);
|
|
507
567
|
setActiveEditId == null ? void 0 : setActiveEditId(null);
|
|
508
568
|
};
|
|
509
569
|
const handleInlineDone = () => {
|
|
@@ -638,10 +698,10 @@ function FileUploadField(props) {
|
|
|
638
698
|
onChange: handleNativeFileChange
|
|
639
699
|
}
|
|
640
700
|
),
|
|
641
|
-
(duplicateWarning || formatWarning || sizeWarning || limitWarning) && /* @__PURE__ */ jsxs("div", { className: styles.warningBanner, role: "alert", children: [
|
|
701
|
+
(duplicateWarning || formatWarning || sizeWarning || emptyFileWarning || limitWarning || deleteWarning) && /* @__PURE__ */ jsxs("div", { className: styles.warningBanner, role: "alert", children: [
|
|
642
702
|
/* @__PURE__ */ jsxs("div", { className: styles.warningContent, children: [
|
|
643
703
|
/* @__PURE__ */ jsx(AlertCircle, { size: 16, color: "#D97706", style: { flexShrink: 0 } }),
|
|
644
|
-
/* @__PURE__ */ jsx("span", { className: styles.warningText, children: [duplicateWarning, formatWarning, sizeWarning, limitWarning].filter(Boolean).join(" ") })
|
|
704
|
+
/* @__PURE__ */ jsx("span", { className: styles.warningText, children: [duplicateWarning, formatWarning, sizeWarning, emptyFileWarning, limitWarning, deleteWarning].filter(Boolean).join(" ") })
|
|
645
705
|
] }),
|
|
646
706
|
/* @__PURE__ */ jsx(
|
|
647
707
|
"button",
|
|
@@ -651,7 +711,9 @@ function FileUploadField(props) {
|
|
|
651
711
|
setDuplicateWarning(null);
|
|
652
712
|
setFormatWarning(null);
|
|
653
713
|
setSizeWarning(null);
|
|
714
|
+
setEmptyFileWarning(null);
|
|
654
715
|
setLimitWarning(null);
|
|
716
|
+
setDeleteWarning(null);
|
|
655
717
|
},
|
|
656
718
|
className: styles.warningCloseBtn,
|
|
657
719
|
title: "Dismiss notification",
|
|
@@ -706,6 +768,7 @@ function FileUploadField(props) {
|
|
|
706
768
|
var _a2, _b2;
|
|
707
769
|
const extension = getFileExtension(file.name || file.filename);
|
|
708
770
|
const isItemUploading = file.status === "uploading";
|
|
771
|
+
const isItemDeleting = deletingFileIds.has(file.id);
|
|
709
772
|
const hasError = file.status === "error";
|
|
710
773
|
const isImg = isImageFile(file.name || file.filename, file.type);
|
|
711
774
|
const fileGcsUrl = file.url || "";
|
|
@@ -774,15 +837,15 @@ function FileUploadField(props) {
|
|
|
774
837
|
] })
|
|
775
838
|
] })
|
|
776
839
|
] }),
|
|
777
|
-
/* @__PURE__ */ jsx("div", { className: styles.fileActionsRight, children: isItemUploading ? /* @__PURE__ */ jsx(Loader2, { size: 18, className: styles.loadingSpinner }) : isEditing ? /* @__PURE__ */ jsx(
|
|
840
|
+
/* @__PURE__ */ jsx("div", { className: styles.fileActionsRight, children: isItemUploading || isItemDeleting ? /* @__PURE__ */ jsx(Loader2, { size: 18, className: styles.loadingSpinner }) : isEditing ? /* @__PURE__ */ jsx(
|
|
778
841
|
"button",
|
|
779
842
|
{
|
|
780
843
|
type: "button",
|
|
781
844
|
className: styles.removeButton,
|
|
782
|
-
title: "
|
|
783
|
-
"aria-label": `
|
|
784
|
-
onClick: (e) =>
|
|
785
|
-
children: /* @__PURE__ */ jsx(
|
|
845
|
+
title: "Delete file",
|
|
846
|
+
"aria-label": `Delete ${file.name}`,
|
|
847
|
+
onClick: (e) => void handleDeleteFile(file, e),
|
|
848
|
+
children: /* @__PURE__ */ jsx(Trash2, { size: 18 })
|
|
786
849
|
}
|
|
787
850
|
) : null })
|
|
788
851
|
]
|