-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(native filters): rendering performance improvement by reduce overrendering #25901
Changes from all commits
a50a8f5
69f5448
aebc791
3aa2790
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
}), | ||
}); | ||
}); |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ import { | |
onFiltersRefreshSuccess, | ||
setDirectPathToChild, | ||
} from 'src/dashboard/actions/dashboardState'; | ||
import { RESPONSIVE_WIDTH } from 'src/filters/components/common'; | ||
import { FAST_DEBOUNCE } from 'src/constants'; | ||
import { dispatchHoverAction, dispatchFocusAction } from './utils'; | ||
import { FilterControlProps } from './types'; | ||
|
@@ -322,7 +323,7 @@ const FilterValue: React.FC<FilterControlProps> = ({ | |
) : ( | ||
<SuperChart | ||
height={HEIGHT} | ||
width="100%" | ||
width={RESPONSIVE_WIDTH} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the advantage of using this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The RESPONSE_WIDTH change is related to the topic no.2 ( |
||
showOverflow={showOverflow} | ||
formData={formData} | ||
displaySettings={displaySettings} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a hook rather than a component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is related to the topic no.3
3. descendants over-rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thank you for explanation!