mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-30 17:06:34 +08:00
Fix multiselect dynamic data source default splitting (#35340)
When a multiselect dialog field uses data_source: "dynamic", a comma-separated default value (e.g. "Product1,Product2") was rendered as a single chip instead of two separate pre-selected chips. --------- Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
@@ -389,6 +389,66 @@ describe('dialog_conversion', () => {
|
||||
const result = getDefaultValue(element);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should handle dynamic multiselect defaults with comma-separated values', () => {
|
||||
const element = {
|
||||
type: 'select',
|
||||
data_source: 'dynamic',
|
||||
multiselect: true,
|
||||
default: 'Product1,Product2',
|
||||
} as DialogElement;
|
||||
|
||||
const result = getDefaultValue(element);
|
||||
expect(result).toEqual([
|
||||
{label: 'Product1', value: 'Product1'},
|
||||
{label: 'Product2', value: 'Product2'},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle dynamic multiselect defaults with spaced comma-separated values', () => {
|
||||
const element = {
|
||||
type: 'select',
|
||||
data_source: 'dynamic',
|
||||
multiselect: true,
|
||||
default: 'Product1, Product2, Product3',
|
||||
} as DialogElement;
|
||||
|
||||
const result = getDefaultValue(element);
|
||||
expect(result).toEqual([
|
||||
{label: 'Product1', value: 'Product1'},
|
||||
{label: 'Product2', value: 'Product2'},
|
||||
{label: 'Product3', value: 'Product3'},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle dynamic multiselect defaults with array input', () => {
|
||||
const element = {
|
||||
type: 'select',
|
||||
data_source: 'dynamic',
|
||||
multiselect: true,
|
||||
default: ['Product1', 'Product2'],
|
||||
} as unknown as DialogElement;
|
||||
|
||||
const result = getDefaultValue(element);
|
||||
expect(result).toEqual([
|
||||
{label: 'Product1', value: 'Product1'},
|
||||
{label: 'Product2', value: 'Product2'},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle dynamic single select default unchanged', () => {
|
||||
const element = {
|
||||
type: 'select',
|
||||
data_source: 'dynamic',
|
||||
default: 'Product1,Product2',
|
||||
} as DialogElement;
|
||||
|
||||
const result = getDefaultValue(element);
|
||||
expect(result).toEqual({
|
||||
label: 'Product1,Product2',
|
||||
value: 'Product1,Product2',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getOptions', () => {
|
||||
|
||||
@@ -265,6 +265,15 @@ export function getDefaultValue(element: DialogElement): AppFormValue {
|
||||
case DialogElementTypes.RADIO: {
|
||||
// Handle dynamic selects that use data_source instead of static options
|
||||
if (element.type === 'select' && element.data_source === 'dynamic' && element.default) {
|
||||
if (element.multiselect) {
|
||||
const values = Array.isArray(element.default) ?
|
||||
element.default :
|
||||
String(element.default).split(',');
|
||||
const normalizedValues = values.
|
||||
map((val) => String(val).trim()).
|
||||
filter((val) => val.length > 0);
|
||||
return normalizedValues.length > 0 ? normalizedValues.map((v) => ({label: v, value: v})) : null;
|
||||
}
|
||||
return {
|
||||
label: String(element.default),
|
||||
value: String(element.default),
|
||||
|
||||
Reference in New Issue
Block a user