forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(native filters): rendering performance improvement by reduce over…
…rendering (apache#25901)
- Loading branch information
1 parent
92ac6b2
commit e1d73d5
Showing
12 changed files
with
191 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
superset-frontend/src/dashboard/components/SyncDashboardState/SyncDashboardState.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import { render } from 'spec/helpers/testing-library'; | ||
import { getItem, LocalStorageKeys } from 'src/utils/localStorageHelpers'; | ||
import SyncDashboardState from '.'; | ||
|
||
test('stores the dashboard info with local storages', () => { | ||
const testDashboardPageId = 'dashboardPageId'; | ||
render(<SyncDashboardState dashboardPageId={testDashboardPageId} />, { | ||
useRedux: true, | ||
}); | ||
expect(getItem(LocalStorageKeys.dashboard__explore_context, {})).toEqual({ | ||
[testDashboardPageId]: expect.objectContaining({ | ||
dashboardPageId: testDashboardPageId, | ||
}), | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
superset-frontend/src/dashboard/components/SyncDashboardState/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* 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 React, { useEffect } from 'react'; | ||
import pick from 'lodash/pick'; | ||
import { shallowEqual, useSelector } from 'react-redux'; | ||
import { DashboardContextForExplore } from 'src/types/DashboardContextForExplore'; | ||
import { | ||
getItem, | ||
LocalStorageKeys, | ||
setItem, | ||
} from 'src/utils/localStorageHelpers'; | ||
import { RootState } from 'src/dashboard/types'; | ||
import { getActiveFilters } from 'src/dashboard/util/activeDashboardFilters'; | ||
|
||
type Props = { dashboardPageId: string }; | ||
|
||
const EMPTY_OBJECT = {}; | ||
|
||
export const getDashboardContextLocalStorage = () => { | ||
const dashboardsContexts = getItem( | ||
LocalStorageKeys.dashboard__explore_context, | ||
{}, | ||
); | ||
// A new dashboard tab id is generated on each dashboard page opening. | ||
// We mark ids as redundant when user leaves the dashboard, because they won't be reused. | ||
// Then we remove redundant dashboard contexts from local storage in order not to clutter it | ||
return Object.fromEntries( | ||
Object.entries(dashboardsContexts).filter( | ||
([, value]) => !value.isRedundant, | ||
), | ||
); | ||
}; | ||
|
||
const updateDashboardTabLocalStorage = ( | ||
dashboardPageId: string, | ||
dashboardContext: DashboardContextForExplore, | ||
) => { | ||
const dashboardsContexts = getDashboardContextLocalStorage(); | ||
setItem(LocalStorageKeys.dashboard__explore_context, { | ||
...dashboardsContexts, | ||
[dashboardPageId]: dashboardContext, | ||
}); | ||
}; | ||
|
||
const SyncDashboardState: React.FC<Props> = ({ dashboardPageId }) => { | ||
const dashboardContextForExplore = useSelector< | ||
RootState, | ||
DashboardContextForExplore | ||
>( | ||
({ dashboardInfo, dashboardState, nativeFilters, dataMask }) => ({ | ||
labelColors: dashboardInfo.metadata?.label_colors || EMPTY_OBJECT, | ||
sharedLabelColors: | ||
dashboardInfo.metadata?.shared_label_colors || EMPTY_OBJECT, | ||
colorScheme: dashboardState?.colorScheme, | ||
chartConfiguration: | ||
dashboardInfo.metadata?.chart_configuration || EMPTY_OBJECT, | ||
nativeFilters: Object.entries(nativeFilters.filters).reduce( | ||
(acc, [key, filterValue]) => ({ | ||
...acc, | ||
[key]: pick(filterValue, ['chartsInScope']), | ||
}), | ||
{}, | ||
), | ||
dataMask, | ||
dashboardId: dashboardInfo.id, | ||
filterBoxFilters: getActiveFilters(), | ||
dashboardPageId, | ||
}), | ||
shallowEqual, | ||
); | ||
|
||
useEffect(() => { | ||
updateDashboardTabLocalStorage(dashboardPageId, dashboardContextForExplore); | ||
return () => { | ||
// mark tab id as redundant when dashboard unmounts - case when user opens | ||
// Explore in the same tab | ||
updateDashboardTabLocalStorage(dashboardPageId, { | ||
...dashboardContextForExplore, | ||
isRedundant: true, | ||
}); | ||
}; | ||
}, [dashboardContextForExplore, dashboardPageId]); | ||
|
||
return null; | ||
}; | ||
|
||
export default SyncDashboardState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.