feat(data-vi): support nulls sorting in chart queries (#6383)

This commit is contained in:
YANG QIA 2025-03-07 11:36:33 +08:00 committed by GitHub
parent f6ec9f82b4
commit c0bb9dff91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 6 deletions

View File

@ -424,16 +424,34 @@ export const querySchema: ISchema = {
order: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
'x-component': 'Select',
'x-component-props': {
defaultValue: 'ASC',
optionType: 'button',
style: {
width: '128px',
},
},
enum: ['ASC', 'DESC'],
},
nulls: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
defaultValue: 'default',
},
enum: [
{
label: lang('Default'),
value: 'default',
},
{
label: lang('NULLS first'),
value: 'first',
},
{
label: lang('NULLS last'),
value: 'last',
},
],
},
},
{
'x-reactions': '{{ useOrderReaction }}',

View File

@ -84,7 +84,14 @@ export class QueryParser {
orders.forEach((item: OrderProps) => {
const alias = sequelize.getQueryInterface().quoteIdentifier(item.alias);
const name = hasAgg ? sequelize.literal(alias) : sequelize.col(item.field as string);
order.push([name, item.order || 'ASC']);
let sort = item.order || 'ASC';
if (item.nulls === 'first') {
sort += ' NULLS FIRST';
}
if (item.nulls === 'last') {
sort += ' NULLS LAST';
}
order.push([name, sort]);
});
return order;
}

View File

@ -27,6 +27,7 @@ export type OrderProps = {
field: string | string[];
alias?: string;
order?: 'asc' | 'desc';
nulls?: 'default' | 'first' | 'last';
};
export type QueryParams = Partial<{