kgabryje commented on code in PR #31029:
URL: https://github.com/apache/superset/pull/31029#discussion_r1853864848
##########
superset-frontend/src/dashboard/components/Header/index.jsx:
##########
@@ -170,209 +146,253 @@ const discardBtnStyle = theme => css`
height: ${theme.gridUnit * 8}px;
`;
-class Header extends PureComponent {
- static discardChanges() {
- const url = new URL(window.location.href);
+const discardChanges = () => {
+ const url = new URL(window.location.href);
- url.searchParams.delete('edit');
- window.location.assign(url);
- }
+ url.searchParams.delete('edit');
+ window.location.assign(url);
+};
- constructor(props) {
- super(props);
- this.state = {
- didNotifyMaxUndoHistoryToast: false,
- emphasizeUndo: false,
- emphasizeRedo: false,
- showingPropertiesModal: false,
- isDropdownVisible: false,
- };
+const Header = () => {
+ const dispatch = useDispatch();
+ const [didNotifyMaxUndoHistoryToast, setDidNotifyMaxUndoHistoryToast] =
+ useState(false);
+ const [emphasizeUndo, setEmphasizeUndo] = useState(false);
+ const [emphasizeRedo, setEmphasizeRedo] = useState(false);
+ const [showingPropertiesModal, setShowingPropertiesModal] = useState(false);
+ const [isDropdownVisible, setIsDropdownVisible] = useState(false);
+ const [showingEmbedModal, setShowingEmbedModal] = useState(false);
+ const dashboardInfo = useSelector(state => state.dashboardInfo);
+ const layout = useSelector(state => state.dashboardLayout.present);
+ const undoLength = useSelector(state => state.dashboardLayout.past.length);
+ const redoLength = useSelector(state => state.dashboardLayout.future.length);
+ const dataMask = useSelector(state => state.dataMask);
+ const user = useSelector(state => state.user);
+ const chartIds = useChartIds();
+
+ const {
+ expandedSlices,
+ refreshFrequency,
+ shouldPersistRefreshFrequency,
+ customCss,
+ colorNamespace,
+ colorScheme,
+ isStarred,
+ isPublished,
+ hasUnsavedChanges,
+ maxUndoHistoryExceeded,
+ editMode,
+ lastModifiedTime,
+ } = useSelector(
+ state => ({
+ expandedSlices: state.dashboardState.expandedSlices,
+ refreshFrequency: state.dashboardState.refreshFrequency,
+ shouldPersistRefreshFrequency:
+ !!state.dashboardState.shouldPersistRefreshFrequency,
+ customCss: state.dashboardState.css,
+ colorNamespace: state.dashboardState.colorNamespace,
+ colorScheme: state.dashboardState.colorScheme,
+ isStarred: !!state.dashboardState.isStarred,
+ isPublished: !!state.dashboardState.isPublished,
+ hasUnsavedChanges: !!state.dashboardState.hasUnsavedChanges,
+ maxUndoHistoryExceeded: !!state.dashboardState.maxUndoHistoryExceeded,
+ editMode: !!state.dashboardState.editMode,
+ lastModifiedTime: state.lastModifiedTime,
+ }),
+ shallowEqual,
+ );
+ const isLoading = useSelector(state => isDashboardLoading(state.charts));
+
+ const refreshTimer = useRef(0);
+ const ctrlYTimeout = useRef(0);
+ const ctrlZTimeout = useRef(0);
+
+ const dashboardTitle = layout[DASHBOARD_HEADER_ID]?.meta?.text;
+ const { slug } = dashboardInfo;
+ const actualLastModifiedTime = Math.max(
+ lastModifiedTime,
+ dashboardInfo.last_modified_time,
+ );
+ const boundActionCreators = useMemo(
+ () =>
+ bindActionCreators(
+ {
+ addSuccessToast,
+ addDangerToast,
+ addWarningToast,
+ onUndo: undoLayoutAction,
+ onRedo: redoLayoutAction,
+ setEditMode,
+ setUnsavedChanges,
+ fetchFaveStar,
+ saveFaveStar,
+ savePublished,
+ fetchCharts,
+ updateDashboardTitle,
+ updateCss,
+ onChange,
+ onSave: saveDashboardRequest,
+ setMaxUndoHistoryExceeded,
+ maxUndoHistoryToast,
+ logEvent,
+ setRefreshFrequency,
+ onRefresh,
+ dashboardInfoChanged,
+ dashboardTitleChanged,
+ },
+ dispatch,
+ ),
+ [dispatch],
+ );
+
+ const startPeriodicRender = useCallback(
+ interval => {
+ let intervalMessage;
+
+ if (interval) {
+ const periodicRefreshOptions =
+ dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS;
Review Comment:
it doesn't change, but _technically_ it could since it's a part of the redux
state object, so it should be included in the dependency array - it won't hurt
and it won't trigger a lint warning
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]