Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table null sorting #1981

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -57,18 +57,23 @@ function getSortingFunction(args: {
}

return function (row1, row2) {
const a = getSortAccessor(row1.original[columnIndex].value);
const b = getSortAccessor(row2.original[columnIndex].value);
const nullReplacement = columnType === 'number' ? -Infinity : '';
const a = getSortAccessor(row1.original[columnIndex].value, nullReplacement);
const b = getSortAccessor(row2.original[columnIndex].value, nullReplacement);

return ascending(a as Primitive, b as Primitive);
};
}

function getSortAccessor(value: unknown) {
function getSortAccessor(value: unknown, nullReplacement?: Primitive) {
if (isMarkupItem(value)) {
return markupToRawString(value);
}

if (value === null && typeof nullReplacement !== 'undefined') {
return nullReplacement;
}

return value as Primitive;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,66 @@ datalensTest.describe('Wizard', () => {
];
expect(await wizardPage.chartkit.getRowsTexts()).toEqual(expectedOrder);
});

datalensTest('Sorting numbers with null values', async ({page}) => {
const wizardPage = new WizardPage({page});
const chartContainer = page.locator(slct(WizardPageQa.SectionPreview));
const previewLoader = chartContainer.locator(slct(ChartKitQa.Loader));

await wizardPage.createNewFieldWithFormula('year', 'year([Order_date])');
await wizardPage.sectionVisualization.addFieldByClick(PlaceholderName.Filters, 'year');
await wizardPage.filterEditor.selectFilterOperation(Operations.EQ);
await wizardPage.filterEditor.setInputValue('2015');
await wizardPage.filterEditor.apply();

await wizardPage.createNewFieldWithFormula('month', 'datepart([Order_date], "month")');
await wizardPage.createNewFieldWithFormula(
'with_null',
'if([month] = 2) then null else [month] end',
);
await wizardPage.sectionVisualization.addFieldByClick(
PlaceholderName.FlatTableColumns,
'month',
);
await wizardPage.sectionVisualization.addFieldByClick(
PlaceholderName.FlatTableColumns,
'with_null',
);
await expect(previewLoader).not.toBeVisible();

const initialOrder = [
['1', '1'],
['2', 'null'],
['3', '3'],
['4', '4'],
['5', '5'],
['6', '6'],
['7', '7'],
['8', '8'],
['9', '9'],
['10', '10'],
['11', '11'],
['12', '12'],
];
expect(await wizardPage.chartkit.getRowsTexts()).toEqual(initialOrder);

// Sort values by clicking on header
await chartContainer.locator('thead', {hasText: 'with_null'}).first().click();
const expectedOrder = [
['12', '12'],
['11', '11'],
['10', '10'],
['9', '9'],
['8', '8'],
['7', '7'],
['6', '6'],
['5', '5'],
['4', '4'],
['3', '3'],
['1', '1'],
['2', 'null'],
];
expect(await wizardPage.chartkit.getRowsTexts()).toEqual(expectedOrder);
});
});
});
Loading