Skip to content

Commit

Permalink
fix(sqllab): type error on renderBigIntStr (#22813)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Jan 23, 2023
1 parent 2a30bbc commit 02a3c0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ReactWrapper } from 'enzyme';
import { styledMount as mount } from 'spec/helpers/theming';
import FilterableTable, {
MAX_COLUMNS_FOR_TABLE,
renderBigIntStrToNumber,
convertBigIntStrToNumber,
} from 'src/components/FilterableTable';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -334,17 +334,17 @@ describe('FilterableTable sorting - RTL', () => {
});

test('renders bigInt value in a number format', () => {
expect(renderBigIntStrToNumber('123')).toBe('123');
expect(renderBigIntStrToNumber('some string value')).toBe(
expect(convertBigIntStrToNumber('123')).toBe('123');
expect(convertBigIntStrToNumber('some string value')).toBe(
'some string value',
);
expect(renderBigIntStrToNumber('{ a: 123 }')).toBe('{ a: 123 }');
expect(renderBigIntStrToNumber('"Not a Number"')).toBe('"Not a Number"');
expect(convertBigIntStrToNumber('{ a: 123 }')).toBe('{ a: 123 }');
expect(convertBigIntStrToNumber('"Not a Number"')).toBe('"Not a Number"');
// trim quotes for bigint string format
expect(renderBigIntStrToNumber('"-12345678901234567890"')).toBe(
expect(convertBigIntStrToNumber('"-12345678901234567890"')).toBe(
'-12345678901234567890',
);
expect(renderBigIntStrToNumber('"12345678901234567890"')).toBe(
expect(convertBigIntStrToNumber('"12345678901234567890"')).toBe(
'12345678901234567890',
);
});
6 changes: 5 additions & 1 deletion superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ function safeJsonObjectParse(
}
}

export function renderBigIntStrToNumber(value: string) {
export function convertBigIntStrToNumber(value: string | number) {
if (typeof value === 'string' && /^"-?\d+"$/.test(value)) {
return value.substring(1, value.length - 1);
}
return value;
}

function renderBigIntStrToNumber(value: string | number) {
return <>{convertBigIntStrToNumber(value)}</>;
}

const GRID_POSITION_ADJUSTMENT = 4;
const SCROLL_BAR_HEIGHT = 15;
// This regex handles all possible number formats in javascript, including ints, floats,
Expand Down

0 comments on commit 02a3c0d

Please sign in to comment.