Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('getOptions', () => {
it('returns all of the types, sorted', () => {
const { options } = getOptions(schema, {});
expect(options).toEqual([
makeOption(schema, 'boolean'),
makeOption(schema, 'number'),
makeOption(schema, 'string'),
makeOption(schema, 'number'),
makeOption(schema, 'boolean'),
]);
});
});
Expand Down Expand Up @@ -71,13 +71,13 @@ describe('getOptions', () => {
const { options } = getOptions(schema, definitions);
const optionKeys = options.map((o) => o.key);
expect(optionKeys).toEqual([
'my awesome string',
'boolean',
'string',
'number',
'boolean',
'my awesome string',
'an enum',
'dropdown',
'another type',
'string',
'unknown',
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ function getOptionLabel(schema: JSONSchema7): string {
return type || 'unknown';
}

const typePriorityWeights = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cool to weight the types based on their order in the sdk schema. Then the schema has control and maybe uischema could provide weight/ordering overrides.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GeoffCoxMSFT Technically speaking it was taking the order of the schema before this PR. So changing the order there would have solved the issue. This PR is just a way to fix the issue client side, which is quicker.

string: 5,
number: 4,
boolean: 3,
array: 2,
object: 1,
};

const sortOptionsByTypeWeights = ({ key: type1 }, { key: type2 }): number => {
return (typePriorityWeights[type1] || 0) > (typePriorityWeights[type2] || 0) ? -1 : 1;
};

export function getOptions(
schema: JSONSchema7,
definitions?: SchemaDefinitions
Expand All @@ -40,7 +52,7 @@ export function getOptions(
data: { schema: { ...schema, type: t }, icon: getFieldIconText(t) },
}));

options.sort(({ text: t1 }, { text: t2 }) => (t1 > t2 ? 1 : -1));
options.sort(sortOptionsByTypeWeights);

return { options, isNested };
}
Expand All @@ -64,6 +76,8 @@ export function getOptions(
})
.filter(Boolean) as IDropdownOption[];

options.sort(sortOptionsByTypeWeights);

const expression = (resolvedOneOf as JSONSchema7[]).find(({ $role }) => $role === 'expression');
const merged = merge({}, omit(schema, 'oneOf'), expression);

Expand Down