Skip to content

Commit

Permalink
fix(sqllab): invalid start date (#25437)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and michael-s-molina committed Sep 28, 2023
1 parent 8dfe95f commit b83bd5d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
30 changes: 15 additions & 15 deletions superset-frontend/src/SqlLab/reducers/getInitialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
53 changes: 52 additions & 1 deletion superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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),
}),
);
});
});
});

0 comments on commit b83bd5d

Please sign in to comment.