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(frontend): allow "constructor" property in response data #25407

Merged
merged 8 commits into from
Apr 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import { cloneDeepWith } from 'lodash';

import { ParseMethod, TextResponse, JsonResponse } from '../types';

const JSONbig = _JSONbig({
constructorAction: 'preserve',
});

export default async function parseResponse<T extends ParseMethod = 'json'>(
apiPromise: Promise<Response>,
parseMethod?: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ describe('parseResponse()', () => {

it('resolves to big number value if `parseMethod=json-bigint`', async () => {
const mockBigIntUrl = '/mock/get/bigInt';
const mockGetBigIntPayload =
'{ "value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" }, "number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 } }';
const mockGetBigIntPayload = `{
"value": 9223372036854775807, "minus": { "value": -483729382918228373892, "str": "something" },
"number": 1234, "floatValue": { "plus": 0.3452211361231223, "minus": -0.3452211361231223 },
"string.constructor": "data.constructor",
"constructor": "constructor"
}`;
fetchMock.get(mockBigIntUrl, mockGetBigIntPayload);
const responseBigNumber = await parseResponse(
callApi({ url: mockBigIntUrl, method: 'GET' }),
Expand All @@ -167,6 +171,10 @@ describe('parseResponse()', () => {
expect(Math.abs(responseBigNumber.json.floatValue.minus)).toEqual(
responseBigNumber.json.floatValue.plus,
);
expect(responseBigNumber.json['string.constructor']).toEqual(
'data.constructor',
);
expect(responseBigNumber.json.constructor).toEqual('constructor');
});

it('rejects if request.ok=false', async () => {
Expand Down
7 changes: 6 additions & 1 deletion superset-frontend/src/components/FilterableTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
import JSONbig from 'json-bigint';
import _JSONbig from 'json-bigint';
import React, { useEffect, useRef, useState, useMemo } from 'react';
import { getMultipleTextDimensions, styled } from '@superset-ui/core';
import { useDebounceValue } from 'src/hooks/useDebounceValue';
import { useCellContentParser } from './useCellContentParser';
import { renderResultCell } from './utils';
import { Table, TableSize } from '../Table';

const JSONbig = _JSONbig({
storeAsString: true,
constructorAction: 'preserve',
});

const SCROLL_BAR_HEIGHT = 15;
// This regex handles all possible number formats in javascript, including ints, floats,
// exponential notation, NaN, and Infinity.
Expand Down
Loading