@e-llm-studio/instant-learning 1.3.23 → 1.3.24-alpha.3
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 +23 -5
- 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 +99 -23
- package/dist/cjs/schema-driven/components/PromptTextEditorField.js.map +1 -1
- package/dist/cjs/schema-driven/utils/fileUploadService.js +13 -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 +24 -6
- 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 +99 -23
- package/dist/schema-driven/components/PromptTextEditorField.js.map +1 -1
- package/dist/schema-driven/utils/fileUploadService.js +13 -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.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 +5 -0
- package/dist/types/src/schema-driven/utils/fileUploadService.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -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,CAAA,iBAAA,KAAhC,YAAqD,EAAC;AAAA,G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,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;;;;"}
|
|
@@ -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, deleteFileFromGCS } 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,6 +78,7 @@ 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);
|
|
82
83
|
const [deleteWarning, setDeleteWarning] = useState(null);
|
|
83
84
|
const [deletingFileIds, setDeletingFileIds] = useState(() => /* @__PURE__ */ new Set());
|
|
@@ -260,6 +261,7 @@ function FileUploadField(props) {
|
|
|
260
261
|
setDuplicateWarning(null);
|
|
261
262
|
setFormatWarning(null);
|
|
262
263
|
setSizeWarning(null);
|
|
264
|
+
setEmptyFileWarning(null);
|
|
263
265
|
setLimitWarning(null);
|
|
264
266
|
setDeleteWarning(null);
|
|
265
267
|
const remainingSlots = isFinite(effectiveMaxUploads) ? Math.max(0, effectiveMaxUploads - filesList.length) : Infinity;
|
|
@@ -285,8 +287,11 @@ function FileUploadField(props) {
|
|
|
285
287
|
const validFiles = [];
|
|
286
288
|
const invalidFiles = [];
|
|
287
289
|
const oversizedFiles = [];
|
|
290
|
+
const emptyFiles = [];
|
|
288
291
|
for (const file of filesToProcess) {
|
|
289
|
-
if (
|
|
292
|
+
if (file.size === 0) {
|
|
293
|
+
emptyFiles.push(file);
|
|
294
|
+
} else if (!isFileAccepted(file, normalizedAccept)) {
|
|
290
295
|
invalidFiles.push(file);
|
|
291
296
|
} else if (effectiveMaxFileSizeBytes !== null && file.size > effectiveMaxFileSizeBytes) {
|
|
292
297
|
oversizedFiles.push(file);
|
|
@@ -304,14 +309,23 @@ function FileUploadField(props) {
|
|
|
304
309
|
const message = oversizedFiles.length === 1 ? `File "${oversizedNames}" exceeds the ${maxFileSizeLabel} per-file size limit.` : `Files "${oversizedNames}" exceed the ${maxFileSizeLabel} per-file size limit.`;
|
|
305
310
|
setSizeWarning(message);
|
|
306
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
|
+
}
|
|
307
317
|
if (validFiles.length === 0) {
|
|
308
318
|
if (fileInputRef.current) {
|
|
309
319
|
fileInputRef.current.value = "";
|
|
310
320
|
}
|
|
311
321
|
return;
|
|
312
322
|
}
|
|
323
|
+
const uploadTimestamp = Date.now();
|
|
324
|
+
const filesForUpload = validFiles.map(
|
|
325
|
+
(file, index) => createTimestampedFile(file, uploadTimestamp, index)
|
|
326
|
+
);
|
|
313
327
|
setIsUploading(true);
|
|
314
|
-
const optimisticItems =
|
|
328
|
+
const optimisticItems = filesForUpload.map((file, i) => {
|
|
315
329
|
const isImg = isImageFile(file.name, file.type);
|
|
316
330
|
let previewBlobUrl = void 0;
|
|
317
331
|
try {
|
|
@@ -336,7 +350,7 @@ function FileUploadField(props) {
|
|
|
336
350
|
try {
|
|
337
351
|
const result = await uploadFilesBatch({
|
|
338
352
|
projectId: resolvedProjectId || "",
|
|
339
|
-
files:
|
|
353
|
+
files: filesForUpload,
|
|
340
354
|
token: resolvedToken,
|
|
341
355
|
artifactUserName: resolvedUserName,
|
|
342
356
|
artifactUserEmail: resolvedUserEmail,
|
|
@@ -483,6 +497,7 @@ function FileUploadField(props) {
|
|
|
483
497
|
setDuplicateWarning(null);
|
|
484
498
|
setFormatWarning(null);
|
|
485
499
|
setSizeWarning(null);
|
|
500
|
+
setEmptyFileWarning(null);
|
|
486
501
|
setLimitWarning(null);
|
|
487
502
|
setDeleteWarning(null);
|
|
488
503
|
if (fileInputRef.current) {
|
|
@@ -532,6 +547,7 @@ function FileUploadField(props) {
|
|
|
532
547
|
setDuplicateWarning(null);
|
|
533
548
|
setFormatWarning(null);
|
|
534
549
|
setSizeWarning(null);
|
|
550
|
+
setEmptyFileWarning(null);
|
|
535
551
|
setLimitWarning(null);
|
|
536
552
|
setDeleteWarning(null);
|
|
537
553
|
inlineSnapshotRef.current = JSON.parse(JSON.stringify(filesList));
|
|
@@ -545,6 +561,7 @@ function FileUploadField(props) {
|
|
|
545
561
|
setDuplicateWarning(null);
|
|
546
562
|
setFormatWarning(null);
|
|
547
563
|
setSizeWarning(null);
|
|
564
|
+
setEmptyFileWarning(null);
|
|
548
565
|
setLimitWarning(null);
|
|
549
566
|
setDeleteWarning(null);
|
|
550
567
|
setActiveEditId == null ? void 0 : setActiveEditId(null);
|
|
@@ -681,10 +698,10 @@ function FileUploadField(props) {
|
|
|
681
698
|
onChange: handleNativeFileChange
|
|
682
699
|
}
|
|
683
700
|
),
|
|
684
|
-
(duplicateWarning || formatWarning || sizeWarning || limitWarning || deleteWarning) && /* @__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: [
|
|
685
702
|
/* @__PURE__ */ jsxs("div", { className: styles.warningContent, children: [
|
|
686
703
|
/* @__PURE__ */ jsx(AlertCircle, { size: 16, color: "#D97706", style: { flexShrink: 0 } }),
|
|
687
|
-
/* @__PURE__ */ jsx("span", { className: styles.warningText, children: [duplicateWarning, formatWarning, sizeWarning, limitWarning, deleteWarning].filter(Boolean).join(" ") })
|
|
704
|
+
/* @__PURE__ */ jsx("span", { className: styles.warningText, children: [duplicateWarning, formatWarning, sizeWarning, emptyFileWarning, limitWarning, deleteWarning].filter(Boolean).join(" ") })
|
|
688
705
|
] }),
|
|
689
706
|
/* @__PURE__ */ jsx(
|
|
690
707
|
"button",
|
|
@@ -694,6 +711,7 @@ function FileUploadField(props) {
|
|
|
694
711
|
setDuplicateWarning(null);
|
|
695
712
|
setFormatWarning(null);
|
|
696
713
|
setSizeWarning(null);
|
|
714
|
+
setEmptyFileWarning(null);
|
|
697
715
|
setLimitWarning(null);
|
|
698
716
|
setDeleteWarning(null);
|
|
699
717
|
},
|