From f4786e566d0fc4368081fde13415115a72b6157c Mon Sep 17 00:00:00 2001 From: Corbin Date: Sun, 8 Oct 2023 20:14:48 -0400 Subject: [PATCH 01/21] test-written --- .../src/shared-controls/sharedControls.tsx | 11 ++++-- .../superset-ui-core/src/validator/index.ts | 1 + .../src/validator/validateMaxValue.ts | 8 +++++ .../test/validator/validateMaxValue.test.ts | 35 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts create mode 100644 superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index abf5153bb0d5..8477a4d600c2 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -47,6 +47,8 @@ import { isDefined, hasGenericChartAxes, NO_TIME_RANGE, + validateNonEmpty, + validateMaxValue, } from '@superset-ui/core'; import { @@ -245,10 +247,15 @@ const row_limit: SharedControlConfig<'SelectControl'> = { type: 'SelectControl', freeForm: true, label: t('Row limit'), - validators: [legacyValidateInteger], + clearable: false, + validators: [ + validateNonEmpty, + legacyValidateInteger, + v => validateMaxValue(v, 100000), + ], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), - description: t('Limits the number of rows that get displayed.'), + description: t('Limits the number of rows that get displayed!.'), }; const order_desc: SharedControlConfig<'CheckboxControl'> = { diff --git a/superset-frontend/packages/superset-ui-core/src/validator/index.ts b/superset-frontend/packages/superset-ui-core/src/validator/index.ts index 532efcc95911..fb37328c0229 100644 --- a/superset-frontend/packages/superset-ui-core/src/validator/index.ts +++ b/superset-frontend/packages/superset-ui-core/src/validator/index.ts @@ -22,3 +22,4 @@ export { default as legacyValidateNumber } from './legacyValidateNumber'; export { default as validateInteger } from './validateInteger'; export { default as validateNumber } from './validateNumber'; export { default as validateNonEmpty } from './validateNonEmpty'; +export { default as validateMaxValue } from './validateMaxValue'; diff --git a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts new file mode 100644 index 000000000000..fe4ba7a93aba --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts @@ -0,0 +1,8 @@ +import { t } from '../translation'; + +export default function validateMaxValue(v: unknown, max: unknown) { + if (typeof max === 'number' && typeof v === 'number' && v > max) { + return t('Value cannot exceed %s', max); + } + return false; +} diff --git a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts new file mode 100644 index 000000000000..f4efd0e3d121 --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { validateMaxValue } from '@superset-ui/core'; +import './setup'; + +describe('validateInteger()', () => { + it('returns the warning message if invalid', () => { + expect(validateMaxValue(10.1, 10)).toBeTruthy(); + expect(validateMaxValue(1, 0)).toBeTruthy(); + }); + it('returns false if the input is valid', () => { + expect(validateMaxValue(0, 1)).toBeFalsy(); + expect(validateMaxValue(10, 10)).toBeFalsy(); + expect(validateMaxValue(undefined, undefined)).toBeFalsy(); + expect(validateMaxValue(NaN, NaN)).toBeFalsy(); + expect(validateMaxValue(null, null)).toBeFalsy(); + }); +}); From 1265cb338a7807e4974e6001cb3ba7f231ee178f Mon Sep 17 00:00:00 2001 From: Corbin Date: Mon, 9 Oct 2023 11:58:49 -0400 Subject: [PATCH 02/21] update-test --- .../superset-ui-core/src/validator/validateMaxValue.ts | 2 +- .../superset-ui-core/test/validator/validateMaxValue.test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts index fe4ba7a93aba..0777f8ab18d7 100644 --- a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts +++ b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts @@ -1,7 +1,7 @@ import { t } from '../translation'; export default function validateMaxValue(v: unknown, max: unknown) { - if (typeof max === 'number' && typeof v === 'number' && v > max) { + if (typeof +max === 'number' && typeof +v === 'number' && +v > +max) { return t('Value cannot exceed %s', max); } return false; diff --git a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts index f4efd0e3d121..858cf5904660 100644 --- a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts @@ -24,6 +24,7 @@ describe('validateInteger()', () => { it('returns the warning message if invalid', () => { expect(validateMaxValue(10.1, 10)).toBeTruthy(); expect(validateMaxValue(1, 0)).toBeTruthy(); + expect(validateMaxValue('2', '1')).toBeTruthy(); }); it('returns false if the input is valid', () => { expect(validateMaxValue(0, 1)).toBeFalsy(); @@ -31,5 +32,7 @@ describe('validateInteger()', () => { expect(validateMaxValue(undefined, undefined)).toBeFalsy(); expect(validateMaxValue(NaN, NaN)).toBeFalsy(); expect(validateMaxValue(null, null)).toBeFalsy(); + expect(validateMaxValue('1', '1')).toBeFalsy(); + expect(validateMaxValue('a', 'b')).toBeFalsy(); }); }); From f1f3b6dab5590e98e77701e40aabc7612dab1108 Mon Sep 17 00:00:00 2001 From: Corbin Date: Mon, 9 Oct 2023 12:41:31 -0400 Subject: [PATCH 03/21] update-validator --- .../superset-ui-core/src/validator/validateMaxValue.ts | 4 ++-- .../test/validator/validateMaxValue.test.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts index 0777f8ab18d7..d7311c372d5f 100644 --- a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts +++ b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts @@ -1,7 +1,7 @@ import { t } from '../translation'; -export default function validateMaxValue(v: unknown, max: unknown) { - if (typeof +max === 'number' && typeof +v === 'number' && +v > +max) { +export default function validateMaxValue(v: unknown, max: Number) { + if (typeof Number(v) === 'number' && Number(v) > +max) { return t('Value cannot exceed %s', max); } return false; diff --git a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts index 858cf5904660..70f3d332c52e 100644 --- a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts @@ -24,15 +24,15 @@ describe('validateInteger()', () => { it('returns the warning message if invalid', () => { expect(validateMaxValue(10.1, 10)).toBeTruthy(); expect(validateMaxValue(1, 0)).toBeTruthy(); - expect(validateMaxValue('2', '1')).toBeTruthy(); + expect(validateMaxValue('2', 1)).toBeTruthy(); }); it('returns false if the input is valid', () => { expect(validateMaxValue(0, 1)).toBeFalsy(); expect(validateMaxValue(10, 10)).toBeFalsy(); - expect(validateMaxValue(undefined, undefined)).toBeFalsy(); + expect(validateMaxValue(undefined, 1)).toBeFalsy(); expect(validateMaxValue(NaN, NaN)).toBeFalsy(); - expect(validateMaxValue(null, null)).toBeFalsy(); - expect(validateMaxValue('1', '1')).toBeFalsy(); - expect(validateMaxValue('a', 'b')).toBeFalsy(); + expect(validateMaxValue(null, 1)).toBeFalsy(); + expect(validateMaxValue('1', 1)).toBeFalsy(); + expect(validateMaxValue('a', 1)).toBeFalsy(); }); }); From 5ee5421aa6e4e8650de465ed238d246ae4b9c76e Mon Sep 17 00:00:00 2001 From: Corbin Date: Tue, 10 Oct 2023 08:38:11 -0400 Subject: [PATCH 04/21] removed ! --- .../src/shared-controls/sharedControls.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 8477a4d600c2..69fa8a686490 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -255,7 +255,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { ], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), - description: t('Limits the number of rows that get displayed!.'), + description: t('Limits the number of rows that get displayed.'), }; const order_desc: SharedControlConfig<'CheckboxControl'> = { From f0d1dd20337c9c349df8ec5e6e5837a943af79f6 Mon Sep 17 00:00:00 2001 From: Corbin Date: Tue, 10 Oct 2023 11:58:04 -0400 Subject: [PATCH 05/21] removedNumber check --- .../packages/superset-ui-core/src/validator/validateMaxValue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts index d7311c372d5f..24c1da1c79dd 100644 --- a/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts +++ b/superset-frontend/packages/superset-ui-core/src/validator/validateMaxValue.ts @@ -1,7 +1,7 @@ import { t } from '../translation'; export default function validateMaxValue(v: unknown, max: Number) { - if (typeof Number(v) === 'number' && Number(v) > +max) { + if (Number(v) > +max) { return t('Value cannot exceed %s', max); } return false; From 935b3b76ebd5930af077fb196b192fe7ad748bd5 Mon Sep 17 00:00:00 2001 From: Corbin Date: Thu, 26 Oct 2023 12:33:02 -0400 Subject: [PATCH 06/21] removed validatenonempty --- .../src/shared-controls/sharedControls.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 69fa8a686490..7e687d5a09d4 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -248,11 +248,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { freeForm: true, label: t('Row limit'), clearable: false, - validators: [ - validateNonEmpty, - legacyValidateInteger, - v => validateMaxValue(v, 100000), - ], + validators: [legacyValidateInteger, v => validateMaxValue(v, 100000)], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t('Limits the number of rows that get displayed.'), From f2040854842f2836d861b7cbb92d20791b143876 Mon Sep 17 00:00:00 2001 From: Corbin Date: Thu, 30 Nov 2023 12:37:33 -0500 Subject: [PATCH 07/21] eslint fix --- .../src/shared-controls/sharedControls.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 7e687d5a09d4..7441a4b4ff75 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -47,7 +47,6 @@ import { isDefined, hasGenericChartAxes, NO_TIME_RANGE, - validateNonEmpty, validateMaxValue, } from '@superset-ui/core'; From dfdc714e00d40a7ea673d51a73811b9bcb265396 Mon Sep 17 00:00:00 2001 From: Corbin Date: Fri, 8 Dec 2023 12:31:37 -0500 Subject: [PATCH 08/21] SQL_MAX_ROW from config --- .../src/shared-controls/sharedControls.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 7441a4b4ff75..6b1fc508af26 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -85,7 +85,9 @@ import { dndAdhocMetricControl2, dndXAxisControl, } from './dndControls'; +import getBootstrapData from '../../../../src/utils/getBootstrapData'; +const sqlMaxRow = getBootstrapData().common.conf.SQL_MAX_ROW; export { withDndFallback } from './dndControls'; const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); @@ -247,7 +249,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { freeForm: true, label: t('Row limit'), clearable: false, - validators: [legacyValidateInteger, v => validateMaxValue(v, 100000)], + validators: [legacyValidateInteger, v => validateMaxValue(v, sqlMaxRow)], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t('Limits the number of rows that get displayed.'), From a788303b6ff4c498f0a3685961dabd016fc2cf29 Mon Sep 17 00:00:00 2001 From: Corbin Date: Fri, 8 Dec 2023 12:43:15 -0500 Subject: [PATCH 09/21] added sql max row --- .../src/shared-controls/sharedControls.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 6b1fc508af26..83195a11012e 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -88,7 +88,6 @@ import { import getBootstrapData from '../../../../src/utils/getBootstrapData'; const sqlMaxRow = getBootstrapData().common.conf.SQL_MAX_ROW; -export { withDndFallback } from './dndControls'; const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); const sequentialSchemeRegistry = getSequentialSchemeRegistry(); From 02803fdb34ca034e20a0890ad18143d0a99f5320 Mon Sep 17 00:00:00 2001 From: Corbin Date: Tue, 12 Dec 2023 10:59:24 -0500 Subject: [PATCH 10/21] modified bootstrap import --- .../src/shared-controls/sharedControls.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 0d185c450eff..4677d17af2c6 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -50,6 +50,7 @@ import { validateMaxValue, } from '@superset-ui/core'; +import getBootstrapData from 'src/utils/getBootstrapData'; import { formatSelectOptions, D3_FORMAT_OPTIONS, @@ -85,7 +86,6 @@ import { dndAdhocMetricControl2, dndXAxisControl, } from './dndControls'; -import getBootstrapData from '../../../../src/utils/getBootstrapData'; const sqlMaxRow = getBootstrapData().common.conf.SQL_MAX_ROW; From 3575408afab7be39ecefa794c209c9224e3d0784 Mon Sep 17 00:00:00 2001 From: Corbin Date: Tue, 12 Dec 2023 11:28:53 -0500 Subject: [PATCH 11/21] added withDndFallback --- .../src/shared-controls/sharedControls.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 4677d17af2c6..76a094d9c472 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -87,6 +87,8 @@ import { dndXAxisControl, } from './dndControls'; +export { withDndFallback } from './dndControls'; + const sqlMaxRow = getBootstrapData().common.conf.SQL_MAX_ROW; const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); From b31870aa08c0c7f1feb5ce0dd01b781df9abb576 Mon Sep 17 00:00:00 2001 From: Corbin Date: Thu, 14 Dec 2023 11:30:55 -0500 Subject: [PATCH 12/21] fixed lint issue for import --- .../src/shared-controls/sharedControls.tsx | 7 ++--- .../src/utils/getBootstrapData.ts | 27 +++++++++++++++++++ superset/initialization/__init__.py | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 76a094d9c472..5ce42481b367 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -50,7 +50,8 @@ import { validateMaxValue, } from '@superset-ui/core'; -import getBootstrapData from 'src/utils/getBootstrapData'; +// eslint-disable-next-line import/no-unresolved +import getBootstrapData from '../utils/getBootstrapData'; import { formatSelectOptions, D3_FORMAT_OPTIONS, @@ -89,7 +90,7 @@ import { export { withDndFallback } from './dndControls'; -const sqlMaxRow = getBootstrapData().common.conf.SQL_MAX_ROW; +const { SQL_MAX_ROW } = getBootstrapData().common.conf; const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); const sequentialSchemeRegistry = getSequentialSchemeRegistry(); @@ -248,7 +249,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { freeForm: true, label: t('Row limit'), clearable: false, - validators: [legacyValidateInteger, v => validateMaxValue(v, sqlMaxRow)], + validators: [legacyValidateInteger, v => validateMaxValue(v, SQL_MAX_ROW)], default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t( diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts new file mode 100644 index 000000000000..e426498e5738 --- /dev/null +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { BootstrapData } from 'src/types/bootstrapTypes'; +import { DEFAULT_BOOTSTRAP_DATA } from 'src/constants'; + +export default function getBootstrapData(): BootstrapData { + const appContainer = document.getElementById('app'); + const dataBootstrap = appContainer?.getAttribute('data-bootstrap'); + return dataBootstrap ? JSON.parse(dataBootstrap) : DEFAULT_BOOTSTRAP_DATA; +} diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py index 09212120ece1..2a611deca87b 100644 --- a/superset/initialization/__init__.py +++ b/superset/initialization/__init__.py @@ -28,7 +28,7 @@ from flask_appbuilder import expose, IndexView from flask_babel import gettext as __ from flask_compress import Compress -from flask_session import Session +# from flask_session import Session from werkzeug.middleware.proxy_fix import ProxyFix from superset.constants import CHANGE_ME_SECRET_KEY From a94dcedb1945b3985e5b001a9875cc95d3c764f0 Mon Sep 17 00:00:00 2001 From: Corbin Date: Thu, 14 Dec 2023 11:42:29 -0500 Subject: [PATCH 13/21] added getBootstrapData export to index.ts --- .../src/shared-controls/sharedControls.tsx | 1 - .../packages/superset-ui-chart-controls/src/utils/index.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 5ce42481b367..3480b3cb0e6a 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -50,7 +50,6 @@ import { validateMaxValue, } from '@superset-ui/core'; -// eslint-disable-next-line import/no-unresolved import getBootstrapData from '../utils/getBootstrapData'; import { formatSelectOptions, diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts index 4fa4243c1e85..ba75ddfb7ec7 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts @@ -25,3 +25,4 @@ export { default as columnChoices } from './columnChoices'; export * from './defineSavedMetrics'; export * from './getStandardizedControls'; export * from './getTemporalColumns'; +export * from './getBootstrapData'; From e089ac7be7bec0a903f349c1762c05ac2f747ee5 Mon Sep 17 00:00:00 2001 From: Corbin Date: Thu, 14 Dec 2023 11:52:01 -0500 Subject: [PATCH 14/21] added flask_sesion --- superset/initialization/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/initialization/__init__.py b/superset/initialization/__init__.py index 2a611deca87b..09212120ece1 100644 --- a/superset/initialization/__init__.py +++ b/superset/initialization/__init__.py @@ -28,7 +28,7 @@ from flask_appbuilder import expose, IndexView from flask_babel import gettext as __ from flask_compress import Compress -# from flask_session import Session +from flask_session import Session from werkzeug.middleware.proxy_fix import ProxyFix from superset.constants import CHANGE_ME_SECRET_KEY From 65494d9196a85638dee0b65587d5f47e96cbc24d Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Mon, 18 Dec 2023 17:46:37 -0800 Subject: [PATCH 15/21] add types --- .../superset-ui-chart-controls/src/constants.ts | 13 ++++++++++++- .../superset-ui-chart-controls/src/types.ts | 7 +++++++ .../src/utils/getBootstrapData.ts | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts index cbde46b0ef4d..d38a9fee70ca 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts @@ -24,7 +24,12 @@ import { QueryColumn, DatasourceType, } from '@superset-ui/core'; -import { ColumnMeta, SortSeriesData, SortSeriesType } from './types'; +import { + BootstrapData, + ColumnMeta, + SortSeriesData, + SortSeriesType, +} from './types'; // eslint-disable-next-line import/prefer-default-export export const TIME_FILTER_LABELS = { @@ -75,3 +80,9 @@ export const DEFAULT_XAXIS_SORT_SERIES_DATA: SortSeriesData = { sort_series_type: SortSeriesType.Name, sort_series_ascending: true, }; + +export const DEFAULT_BOOTSTRAP_DATA: BootstrapData = { + common: { + conf: {}, + }, +}; diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts index 09e4f63ee3d3..7f155177a414 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts @@ -557,3 +557,10 @@ export type ControlFormItemSpec = { defaultValue?: Currency; } : {}); + +interface CommonBootstrapData { + conf: JsonObject; +} +export interface BootstrapData { + common: CommonBootstrapData; +} diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts index e426498e5738..9f3729c9500f 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts @@ -17,8 +17,8 @@ * under the License. */ -import { BootstrapData } from 'src/types/bootstrapTypes'; -import { DEFAULT_BOOTSTRAP_DATA } from 'src/constants'; +import { BootstrapData } from '../types'; +import { DEFAULT_BOOTSTRAP_DATA } from '../constants'; export default function getBootstrapData(): BootstrapData { const appContainer = document.getElementById('app'); From bf1c46445995c1f5648965a78a2bc296c6be2511 Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Tue, 19 Dec 2023 11:31:45 -0800 Subject: [PATCH 16/21] address comments --- .../src/shared-controls/sharedControls.tsx | 9 +++--- .../src/utils/getBootstrapData.ts | 27 ----------------- .../src/utils/index.ts | 1 - .../test/validator/validateMaxValue.test.ts | 29 +++++++++---------- 4 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 3480b3cb0e6a..b87fc833838c 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -50,7 +50,6 @@ import { validateMaxValue, } from '@superset-ui/core'; -import getBootstrapData from '../utils/getBootstrapData'; import { formatSelectOptions, D3_FORMAT_OPTIONS, @@ -89,8 +88,6 @@ import { export { withDndFallback } from './dndControls'; -const { SQL_MAX_ROW } = getBootstrapData().common.conf; - const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); const sequentialSchemeRegistry = getSequentialSchemeRegistry(); @@ -248,7 +245,11 @@ const row_limit: SharedControlConfig<'SelectControl'> = { freeForm: true, label: t('Row limit'), clearable: false, - validators: [legacyValidateInteger, v => validateMaxValue(v, SQL_MAX_ROW)], + validators: [ + legacyValidateInteger, + (v, state) => validateMaxValue(v, state?.maxValue), + ], + mapStateToProps: state => ({ maxValue: state?.common.conf.SQL_MAX_ROW }), default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t( diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts deleted file mode 100644 index 9f3729c9500f..000000000000 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/getBootstrapData.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { BootstrapData } from '../types'; -import { DEFAULT_BOOTSTRAP_DATA } from '../constants'; - -export default function getBootstrapData(): BootstrapData { - const appContainer = document.getElementById('app'); - const dataBootstrap = appContainer?.getAttribute('data-bootstrap'); - return dataBootstrap ? JSON.parse(dataBootstrap) : DEFAULT_BOOTSTRAP_DATA; -} diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts index ba75ddfb7ec7..4fa4243c1e85 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/index.ts @@ -25,4 +25,3 @@ export { default as columnChoices } from './columnChoices'; export * from './defineSavedMetrics'; export * from './getStandardizedControls'; export * from './getTemporalColumns'; -export * from './getBootstrapData'; diff --git a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts index 70f3d332c52e..6a8ed1642e7b 100644 --- a/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/validator/validateMaxValue.test.ts @@ -20,19 +20,18 @@ import { validateMaxValue } from '@superset-ui/core'; import './setup'; -describe('validateInteger()', () => { - it('returns the warning message if invalid', () => { - expect(validateMaxValue(10.1, 10)).toBeTruthy(); - expect(validateMaxValue(1, 0)).toBeTruthy(); - expect(validateMaxValue('2', 1)).toBeTruthy(); - }); - it('returns false if the input is valid', () => { - expect(validateMaxValue(0, 1)).toBeFalsy(); - expect(validateMaxValue(10, 10)).toBeFalsy(); - expect(validateMaxValue(undefined, 1)).toBeFalsy(); - expect(validateMaxValue(NaN, NaN)).toBeFalsy(); - expect(validateMaxValue(null, 1)).toBeFalsy(); - expect(validateMaxValue('1', 1)).toBeFalsy(); - expect(validateMaxValue('a', 1)).toBeFalsy(); - }); +test('validateInteger returns the warning message if invalid', () => { + expect(validateMaxValue(10.1, 10)).toBeTruthy(); + expect(validateMaxValue(1, 0)).toBeTruthy(); + expect(validateMaxValue('2', 1)).toBeTruthy(); +}); + +test('validateInteger returns false if the input is valid', () => { + expect(validateMaxValue(0, 1)).toBeFalsy(); + expect(validateMaxValue(10, 10)).toBeFalsy(); + expect(validateMaxValue(undefined, 1)).toBeFalsy(); + expect(validateMaxValue(NaN, NaN)).toBeFalsy(); + expect(validateMaxValue(null, 1)).toBeFalsy(); + expect(validateMaxValue('1', 1)).toBeFalsy(); + expect(validateMaxValue('a', 1)).toBeFalsy(); }); From 36207e984c7edf628cba80c645f26e03236a23bb Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Tue, 19 Dec 2023 13:03:24 -0800 Subject: [PATCH 17/21] Apply suggestions from code review Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com> --- .../superset-ui-chart-controls/src/constants.ts | 13 +------------ .../superset-ui-chart-controls/src/types.ts | 7 ------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts index d38a9fee70ca..cbde46b0ef4d 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts @@ -24,12 +24,7 @@ import { QueryColumn, DatasourceType, } from '@superset-ui/core'; -import { - BootstrapData, - ColumnMeta, - SortSeriesData, - SortSeriesType, -} from './types'; +import { ColumnMeta, SortSeriesData, SortSeriesType } from './types'; // eslint-disable-next-line import/prefer-default-export export const TIME_FILTER_LABELS = { @@ -80,9 +75,3 @@ export const DEFAULT_XAXIS_SORT_SERIES_DATA: SortSeriesData = { sort_series_type: SortSeriesType.Name, sort_series_ascending: true, }; - -export const DEFAULT_BOOTSTRAP_DATA: BootstrapData = { - common: { - conf: {}, - }, -}; diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts index 7f155177a414..09e4f63ee3d3 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts @@ -557,10 +557,3 @@ export type ControlFormItemSpec = { defaultValue?: Currency; } : {}); - -interface CommonBootstrapData { - conf: JsonObject; -} -export interface BootstrapData { - common: CommonBootstrapData; -} From 720675d5986abd80b89f73c9754cf987853cccf6 Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Wed, 20 Dec 2023 09:28:53 -0800 Subject: [PATCH 18/21] fix unit tests --- .../src/shared-controls/sharedControls.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index b87fc833838c..f8e79a032410 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -249,7 +249,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { legacyValidateInteger, (v, state) => validateMaxValue(v, state?.maxValue), ], - mapStateToProps: state => ({ maxValue: state?.common.conf.SQL_MAX_ROW }), + mapStateToProps: state => ({ maxValue: state?.common?.conf?.SQL_MAX_ROW }), default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t( From 5e2be223f528a8ab1721fb60232ee916abaceb57 Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Wed, 20 Dec 2023 11:13:23 -0800 Subject: [PATCH 19/21] fix e2e --- .../packages/superset-ui-chart-controls/src/constants.ts | 2 ++ .../src/shared-controls/sharedControls.tsx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts index cbde46b0ef4d..ae6dd8f894d8 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/constants.ts @@ -26,6 +26,8 @@ import { } from '@superset-ui/core'; import { ColumnMeta, SortSeriesData, SortSeriesType } from './types'; +export const DEFAULT_MAX_ROW = 100000; + // eslint-disable-next-line import/prefer-default-export export const TIME_FILTER_LABELS = { time_range: t('Time Range'), diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index f8e79a032410..739b6eb62786 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -59,7 +59,7 @@ import { DEFAULT_TIME_FORMAT, DEFAULT_NUMBER_FORMAT, } from '../utils'; -import { TIME_FILTER_LABELS } from '../constants'; +import { DEFAULT_MAX_ROW, TIME_FILTER_LABELS } from '../constants'; import { SharedControlConfig, Dataset, @@ -247,7 +247,7 @@ const row_limit: SharedControlConfig<'SelectControl'> = { clearable: false, validators: [ legacyValidateInteger, - (v, state) => validateMaxValue(v, state?.maxValue), + (v, state) => validateMaxValue(v, state?.maxValue || DEFAULT_MAX_ROW), ], mapStateToProps: state => ({ maxValue: state?.common?.conf?.SQL_MAX_ROW }), default: 10000, From 4023d65838836dc5da546ad4c5ebcd367fe5c65e Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Thu, 21 Dec 2023 12:27:15 -0800 Subject: [PATCH 20/21] try see if e2e pass without state --- .../src/shared-controls/sharedControls.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 739b6eb62786..735cb44d824b 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -247,9 +247,9 @@ const row_limit: SharedControlConfig<'SelectControl'> = { clearable: false, validators: [ legacyValidateInteger, - (v, state) => validateMaxValue(v, state?.maxValue || DEFAULT_MAX_ROW), + v => validateMaxValue(v, DEFAULT_MAX_ROW), ], - mapStateToProps: state => ({ maxValue: state?.common?.conf?.SQL_MAX_ROW }), + // mapStateToProps: state => ({ maxValue: state?.common?.conf?.SQL_MAX_ROW }), default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t( From 7edb4552481e19da38fada2db5260887eb24c82d Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Thu, 21 Dec 2023 13:08:25 -0800 Subject: [PATCH 21/21] add DEFAULT_MAX_ROW --- .../src/shared-controls/sharedControls.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx index 735cb44d824b..341aaa0729f0 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx @@ -247,9 +247,9 @@ const row_limit: SharedControlConfig<'SelectControl'> = { clearable: false, validators: [ legacyValidateInteger, - v => validateMaxValue(v, DEFAULT_MAX_ROW), + (v, state) => + validateMaxValue(v, state?.common?.conf?.SQL_MAX_ROW || DEFAULT_MAX_ROW), ], - // mapStateToProps: state => ({ maxValue: state?.common?.conf?.SQL_MAX_ROW }), default: 10000, choices: formatSelectOptions(ROW_LIMIT_OPTIONS), description: t(