Skip to content

Commit da7bc59

Browse files
authored
DEV: Allow multiple upload fields in object site setting (#36605)
When multiple upload types were included in a object site setting, they were not given unique identifiers. This is problematic as all inputs were treated as one, meaning you could upload a asset to UPLOAD_FIELD_1, however uploading a asset to UPLOAD_FIELD_2 would override the first field. This PR concats the name of the setting to the id of the upload field to create a unique identifier.
1 parent 07c7ce3 commit da7bc59

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

frontend/discourse/admin/components/schema-setting/field.gjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default class SchemaSettingField extends Component {
5959
<this.component
6060
@value={{@value}}
6161
@spec={{@spec}}
62+
@name={{@name}}
6263
@onChange={{@onValueChange}}
6364
@description={{this.description}}
6465
@setting={{@setting}}

frontend/discourse/admin/components/schema-setting/types/upload.gjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class SchemaSettingTypeUpload extends Component {
2727
@onUploadDeleted={{this.uploadDeleted}}
2828
@additionalParams={{hash for_site_setting=true}}
2929
@type="site_setting"
30-
@id={{concat "schema-field-upload-" @setting.setting}}
30+
@id={{concat "schema-field-upload-" @setting.setting "-" @name}}
3131
@allowVideo={{true}}
3232
/>
3333

frontend/discourse/tests/integration/components/admin-schema-setting/editor-test.gjs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,5 +2446,78 @@ module(
24462446
assert.dom(MOVE_UP_BTN).isNotDisabled();
24472447
assert.dom(MOVE_DOWN_BTN).isDisabled();
24482448
});
2449+
2450+
test("multiple upload fields have unique IDs", async function (assert) {
2451+
const setting = SiteSetting.create({
2452+
setting: "objects_setting",
2453+
schema: {
2454+
name: "something",
2455+
properties: {
2456+
first_upload: {
2457+
type: "upload",
2458+
},
2459+
second_upload: {
2460+
type: "upload",
2461+
},
2462+
},
2463+
},
2464+
value: [{}],
2465+
});
2466+
2467+
await render(
2468+
<template>
2469+
<AdminSchemaSettingEditor
2470+
@id="1"
2471+
@setting={{setting}}
2472+
@schema={{setting.schema}}
2473+
@routeToRedirect="adminPlugins.show.settings"
2474+
/>
2475+
</template>
2476+
);
2477+
2478+
const inputFields = new InputFieldsFromDOM();
2479+
2480+
// Verify both upload fields exist
2481+
assert
2482+
.dom(inputFields.fields.first_upload.labelElement)
2483+
.hasText("first_upload");
2484+
assert
2485+
.dom(inputFields.fields.second_upload.labelElement)
2486+
.hasText("second_upload");
2487+
2488+
// The UppyImageUploader components should have unique IDs based on field names
2489+
const firstUploadId =
2490+
inputFields.fields.first_upload.inputElement.id ||
2491+
inputFields.fields.first_upload.inputElement.querySelector(
2492+
"[id^='schema-field-upload-']"
2493+
)?.id;
2494+
const secondUploadId =
2495+
inputFields.fields.second_upload.inputElement.id ||
2496+
inputFields.fields.second_upload.inputElement.querySelector(
2497+
"[id^='schema-field-upload-']"
2498+
)?.id;
2499+
2500+
assert.true(
2501+
!!firstUploadId,
2502+
"First upload field should have an ID attribute"
2503+
);
2504+
assert.true(
2505+
!!secondUploadId,
2506+
"Second upload field should have an ID attribute"
2507+
);
2508+
assert.notStrictEqual(
2509+
firstUploadId,
2510+
secondUploadId,
2511+
"Upload field IDs should be unique"
2512+
);
2513+
assert.true(
2514+
firstUploadId?.includes("first_upload"),
2515+
"First upload ID should include field name"
2516+
);
2517+
assert.true(
2518+
secondUploadId?.includes("second_upload"),
2519+
"Second upload ID should include field name"
2520+
);
2521+
});
24492522
}
24502523
);

0 commit comments

Comments
 (0)