Skip to content

Commit

Permalink
fix(sqllab): invalid start date (apache#25437)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Sep 27, 2023
1 parent f0080f9 commit ba5e2f6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
52 changes: 52 additions & 0 deletions superset-frontend/src/SqlLab/reducers/getInitialState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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),
}),
);
});
});
});
30 changes: 15 additions & 15 deletions superset-frontend/src/SqlLab/reducers/getInitialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
9 changes: 8 additions & 1 deletion superset-frontend/src/hooks/apiResources/sqlLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ba5e2f6

Please sign in to comment.