This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b83bd5dc1c42d38b68a6efc128a51f981745be1c
Author: JUST.in DO IT <justin.p...@airbnb.com>
AuthorDate: Wed Sep 27 12:23:59 2023 -0700

    fix(sqllab): invalid start date (#25437)
---
 .../src/SqlLab/reducers/getInitialState.js         | 30 ++++++------
 .../src/SqlLab/reducers/getInitialState.test.ts    | 53 +++++++++++++++++++++-
 2 files changed, 67 insertions(+), 16 deletions(-)

diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.js 
b/superset-frontend/src/SqlLab/reducers/getInitialState.js
index b6fdbe1491..dd24054e11 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.js
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.js
@@ -135,20 +135,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
@@ -209,7 +196,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/SqlLab/reducers/getInitialState.test.ts 
b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
index c06633c6f5..420ef69c7b 100644
--- a/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
+++ b/superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
+import { runningQuery, successfulQuery } from 'src/SqlLab/fixtures';
 import getInitialState, { dedupeTabHistory } from './getInitialState';
 
 const apiData = {
@@ -121,5 +121,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),
+        }),
+      );
+    });
   });
 });

Reply via email to