This is an automated email from the ASF dual-hosted git repository.
justinpark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new ba5e2f634a fix(sqllab): invalid start date (#25437)
ba5e2f634a is described below
commit ba5e2f634a8d5ed159c7f3758e43b071f242a840
Author: JUST.in DO IT <[email protected]>
AuthorDate: Wed Sep 27 12:23:59 2023 -0700
fix(sqllab): invalid start date (#25437)
---
.../src/SqlLab/reducers/getInitialState.test.ts | 52 ++++++++++++++++++++++
.../src/SqlLab/reducers/getInitialState.ts | 30 ++++++-------
superset-frontend/src/hooks/apiResources/sqlLab.ts | 9 +++-
3 files changed, 75 insertions(+), 16 deletions(-)
diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
index c4f064f650..aca11e2cca 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
@@ -18,6 +18,7 @@
*/
import { DEFAULT_COMMON_BOOTSTRAP_DATA } from 'src/constants';
+import { runningQuery, successfulQuery } from 'src/SqlLab/fixtures';
import getInitialState, { dedupeTabHistory } from './getInitialState';
const apiData = {
@@ -192,5 +193,56 @@ describe('getInitialState', () => {
}).sqlLab.tables;
expect(initializedTables.map(({ id }) => id)).toEqual([1, 2, 6]);
});
+
+ it('should parse the float dttm value', () => {
+ const startDttmInStr = '1693433503447.166992';
+ const endDttmInStr = '1693433503500.23132';
+
+ localStorage.setItem(
+ 'redux',
+ JSON.stringify({
+ sqlLab: {
+ tables: [
+ { id: 1, name: 'test1' },
+ { id: 6, name: 'test6' },
+ ],
+ queryEditors: [{ id: 1, title: 'editor1' }],
+ queries: {
+ localStoragePersisted: {
+ ...successfulQuery,
+ id: 'localStoragePersisted',
+ startDttm: startDttmInStr,
+ endDttm: endDttmInStr,
+ },
+ },
+ tabHistory: [],
+ },
+ }),
+ );
+
+ const initializedQueries = getInitialState({
+ ...apiData,
+ queries: {
+ backendPersisted: {
+ ...runningQuery,
+ id: 'backendPersisted',
+ startDttm: startDttmInStr,
+ endDttm: endDttmInStr,
+ },
+ },
+ }).sqlLab.queries;
+ expect(initializedQueries.backendPersisted).toEqual(
+ expect.objectContaining({
+ startDttm: Number(startDttmInStr),
+ endDttm: Number(endDttmInStr),
+ }),
+ );
+ expect(initializedQueries.localStoragePersisted).toEqual(
+ expect.objectContaining({
+ startDttm: Number(startDttmInStr),
+ endDttm: Number(endDttmInStr),
+ }),
+ );
+ });
});
});
diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.ts
b/superset-frontend/src/SqlLab/reducers/getInitialState.ts
index 9867e9bf2c..cd5c46540b 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.ts
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.ts
@@ -130,20 +130,7 @@ export default function getInitialState({
});
}
- const queries = Object.fromEntries(
- Object.entries(queries_ || {}).map(([queryId, query]) => [
- queryId,
- {
- ...query,
- ...(query.startDttm && {
- startDttm: Number(query.startDttm),
- }),
- ...(query.endDttm && {
- endDttm: Number(query.endDttm),
- }),
- },
- ]),
- );
+ const queries = { ...queries_ };
/**
* If the `SQLLAB_BACKEND_PERSISTENCE` feature flag is off, or if the user
@@ -205,7 +192,20 @@ export default function getInitialState({
alerts: [],
databases,
offline: false,
- queries,
+ queries: Object.fromEntries(
+ Object.entries(queries).map(([queryId, query]) => [
+ queryId,
+ {
+ ...query,
+ ...(query.startDttm && {
+ startDttm: Number(query.startDttm),
+ }),
+ ...(query.endDttm && {
+ endDttm: Number(query.endDttm),
+ }),
+ },
+ ]),
+ ),
queryEditors: Object.values(queryEditors),
tabHistory: dedupeTabHistory(tabHistory),
tables: Object.values(tables),
diff --git a/superset-frontend/src/hooks/apiResources/sqlLab.ts
b/superset-frontend/src/hooks/apiResources/sqlLab.ts
index dac53043c3..123db414e2 100644
--- a/superset-frontend/src/hooks/apiResources/sqlLab.ts
+++ b/superset-frontend/src/hooks/apiResources/sqlLab.ts
@@ -53,7 +53,14 @@ export type InitialState = {
extra_json?: object;
};
databases: object[];
- queries: Record<string, QueryResponse & { inLocalStorage?: boolean }>;
+ queries: Record<
+ string,
+ Omit<QueryResponse, 'startDttm' | 'endDttm'> & {
+ startDttm: number | string;
+ endDttm: number | string;
+ inLocalStorage?: boolean;
+ }
+ >;
tab_state_ids: {
id: number;
label: string;