Form fields now reflect archetype data after selection

This commit is contained in:
2026-02-22 19:04:05 +02:00
parent 1ccf855913
commit fadd492421

View File

@@ -197,12 +197,15 @@ export default function MelodyForm() {
lastEditedBy: userName,
adminNotes,
};
return {
const body = {
information: { ...infoWithoutNotes, totalActiveBells },
default_settings: settings,
type, url, uid, pid,
type, uid, pid,
metadata,
};
// Only send url if non-empty — avoids overwriting a backend-set URL with an empty string
if (url) body.url = url;
return body;
};
const uploadFiles = async (melodyId) => {
@@ -562,7 +565,7 @@ export default function MelodyForm() {
<label className="block text-sm font-medium mb-1" style={labelStyle}>PID (Playback ID)</label>
<input type="text" value={pid} onChange={(e) => setPid(e.target.value)} placeholder="eg. builtin_festive_vesper" className={inputClass} />
</div>
{isEdit && url && (
{url && (
<div className="md:col-span-2">
<label className="block text-sm font-medium mb-1" style={labelStyle}>URL (auto-set from binary upload)</label>
<input type="text" value={url} readOnly className={inputClass} style={{ opacity: 0.7 }} />
@@ -804,7 +807,24 @@ export default function MelodyForm() {
setShowSelectBuilt(false);
setAssignedBinaryName(archetype.name);
if (!pid.trim() && archetype.pid) setPid(archetype.pid);
if (isEdit) loadMelody();
if (archetype.steps != null) updateInfo("steps", archetype.steps);
if (archetype.totalNotes != null) updateInfo("totalNotes", archetype.totalNotes);
if (archetype.archetype_csv != null) updateInfo("archetype_csv", archetype.archetype_csv);
if (isEdit) {
loadMelody();
} else {
// Refresh files so binary_url and url are shown
const mid = savedMelodyId;
if (mid) {
Promise.all([
api.get(`/melodies/${mid}/files`),
api.get(`/melodies/${mid}`),
]).then(([files, m]) => {
setExistingFiles(files);
if (m.url) setUrl(m.url);
}).catch(() => {});
}
}
}}
/>
<BuildOnTheFlyModal
@@ -819,7 +839,23 @@ export default function MelodyForm() {
setShowBuildOnTheFly(false);
setAssignedBinaryName(archetype.name);
if (!pid.trim() && archetype.pid) setPid(archetype.pid);
if (isEdit) loadMelody();
if (archetype.steps != null) updateInfo("steps", archetype.steps);
if (archetype.totalNotes != null) updateInfo("totalNotes", archetype.totalNotes);
if (archetype.archetype_csv != null) updateInfo("archetype_csv", archetype.archetype_csv);
if (isEdit) {
loadMelody();
} else {
const mid = savedMelodyId;
if (mid) {
Promise.all([
api.get(`/melodies/${mid}/files`),
api.get(`/melodies/${mid}`),
]).then(([files, m]) => {
setExistingFiles(files);
if (m.url) setUrl(m.url);
}).catch(() => {});
}
}
}}
/>
</>