Skip to content

Commit

Permalink
feat(data-vi): support nulls sorting in chart queries (nocobase#6383)
Browse files Browse the repository at this point in the history
  • Loading branch information
2013xile authored Mar 7, 2025
1 parent f6ec9f8 commit c0bb9df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type OrderProps = {
field: string | string[];
alias?: string;
order?: 'asc' | 'desc';
nulls?: 'default' | 'first' | 'last';
};

export type QueryParams = Partial<{
Expand Down

0 comments on commit c0bb9df

Please sign in to comment.