Move troubleshooting guide into a modal

Reviewed By: aigoncharov

Differential Revision: D48066773

fbshipit-source-id: 05aca8c75aa30325e1a8c5f31301db1e89ec25af
This commit is contained in:
Anton Kastritskiy
2023-08-07 03:54:28 -07:00
committed by Facebook GitHub Bot
parent 60419c54f2
commit 08371d3a6b
3 changed files with 52 additions and 35 deletions

View File

@@ -26,9 +26,7 @@ import {sideEffect} from '../utils/sideEffect';
import {waitFor} from '../utils/waitFor'; import {waitFor} from '../utils/waitFor';
import {NotificationBody} from '../ui/components/NotificationBody'; import {NotificationBody} from '../ui/components/NotificationBody';
import {Layout} from '../ui'; import {Layout} from '../ui';
import {setStaticView} from '../reducers/connections'; import {toggleConnectivityModal} from '../reducers/application';
import {TroubleshootingHub} from '../chrome/TroubleshootingHub';
import {setTopLevelSelection} from '../reducers/application';
export function connectFlipperServerToStore( export function connectFlipperServerToStore(
server: FlipperServer, server: FlipperServer,
@@ -314,8 +312,7 @@ function showConnectivityTroubleshootNotification(
type="primary" type="primary"
style={{float: 'right'}} style={{float: 'right'}}
onClick={() => { onClick={() => {
store.dispatch(setTopLevelSelection('connectivity')); store.dispatch(toggleConnectivityModal());
store.dispatch(setStaticView(TroubleshootingHub));
notification.close(key); notification.close(key);
}}> }}>
Troubleshoot Troubleshoot

View File

@@ -11,11 +11,7 @@ import {v1 as uuidv1} from 'uuid';
import {getRenderHostInstance} from 'flipper-frontend-core'; import {getRenderHostInstance} from 'flipper-frontend-core';
import {Actions} from './'; import {Actions} from './';
export type ToplevelNavigationItem = export type ToplevelNavigationItem = 'appinspect' | 'notification' | undefined;
| 'appinspect'
| 'notification'
| 'connectivity'
| undefined;
export type LauncherMsg = { export type LauncherMsg = {
message: string; message: string;
@@ -44,7 +40,7 @@ export type ShareType = {
export type State = { export type State = {
topLevelSelection: ToplevelNavigationItem; topLevelSelection: ToplevelNavigationItem;
hasLeftSidebar: boolean; isTroubleshootingModalOpen: boolean;
leftSidebarVisible: boolean; leftSidebarVisible: boolean;
rightSidebarVisible: boolean; rightSidebarVisible: boolean;
rightSidebarAvailable: boolean; rightSidebarAvailable: boolean;
@@ -88,11 +84,15 @@ export type Action =
| { | {
type: 'REMOVE_STATUS_MSG'; type: 'REMOVE_STATUS_MSG';
payload: {msg: string; sender: string}; payload: {msg: string; sender: string};
}
| {
type: 'TOGGLE_CONNECTIVITY_MODAL';
}; };
export const initialState: () => State = () => ({ export const initialState: () => State = () => ({
topLevelSelection: 'appinspect', topLevelSelection: 'appinspect',
hasLeftSidebar: true, hasLeftSidebar: true,
isTroubleshootingModalOpen: false,
leftSidebarVisible: true, leftSidebarVisible: true,
rightSidebarVisible: true, rightSidebarVisible: true,
rightSidebarAvailable: false, rightSidebarAvailable: false,
@@ -125,7 +125,6 @@ export default function reducer(
): State { ): State {
state = state || initialState(); state = state || initialState();
if ( if (
action.type === 'hasLeftSidebar' ||
action.type === 'leftSidebarVisible' || action.type === 'leftSidebarVisible' ||
action.type === 'rightSidebarVisible' || action.type === 'rightSidebarVisible' ||
action.type === 'rightSidebarAvailable' action.type === 'rightSidebarAvailable'
@@ -147,16 +146,15 @@ export default function reducer(
} else if (action.type === 'topLevelSelection') { } else if (action.type === 'topLevelSelection') {
const topLevelSelection = action.payload; const topLevelSelection = action.payload;
const hasLeftSidebar =
topLevelSelection === 'appinspect' ||
topLevelSelection === 'notification';
return { return {
...state, ...state,
leftSidebarVisible: hasLeftSidebar,
hasLeftSidebar,
topLevelSelection, topLevelSelection,
}; };
} else if (action.type === 'TOGGLE_CONNECTIVITY_MODAL') {
return {
...state,
isTroubleshootingModalOpen: !state.isTroubleshootingModalOpen,
};
} else if (action.type === 'windowIsFocused') { } else if (action.type === 'windowIsFocused') {
return { return {
...state, ...state,
@@ -206,6 +204,10 @@ export const setTopLevelSelection = (
payload, payload,
}); });
export const toggleConnectivityModal = (): Action => ({
type: 'TOGGLE_CONNECTIVITY_MODAL',
});
export const toggleLeftSidebarVisible = (payload?: boolean): Action => ({ export const toggleLeftSidebarVisible = (payload?: boolean): Action => ({
type: 'leftSidebarVisible', type: 'leftSidebarVisible',
payload, payload,

View File

@@ -34,6 +34,7 @@ import {
} from '@ant-design/icons'; } from '@ant-design/icons';
import { import {
setTopLevelSelection, setTopLevelSelection,
toggleConnectivityModal,
toggleLeftSidebarVisible, toggleLeftSidebarVisible,
toggleRightSidebarVisible, toggleRightSidebarVisible,
ToplevelNavigationItem, ToplevelNavigationItem,
@@ -268,12 +269,10 @@ function NotificationButton({
function LeftSidebarToggleButton() { function LeftSidebarToggleButton() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const hasMainMenu = useStore((state) => state.application.hasLeftSidebar);
const mainMenuVisible = useStore( const mainMenuVisible = useStore(
(state) => state.application.leftSidebarVisible, (state) => state.application.leftSidebarVisible,
); );
if (hasMainMenu) {
return ( return (
<NavbarButton <NavbarButton
label="Sidebar" label="Sidebar"
@@ -286,9 +285,6 @@ function LeftSidebarToggleButton() {
); );
} }
return null;
}
function RightSidebarToggleButton() { function RightSidebarToggleButton() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const rightSidebarAvailable = useStore( const rightSidebarAvailable = useStore(
@@ -517,8 +513,7 @@ function TroubleshootMenu() {
<Menu.Item <Menu.Item
key="connectivity" key="connectivity"
onClick={() => { onClick={() => {
store.dispatch(setTopLevelSelection('connectivity')); store.dispatch(toggleConnectivityModal());
store.dispatch(setStaticView(TroubleshootingHub));
}}> }}>
Troubleshoot Connectivity Troubleshoot Connectivity
</Menu.Item> </Menu.Item>
@@ -553,10 +548,33 @@ function TroubleshootMenu() {
isOpen={isFlipperDevToolsModalOpen} isOpen={isFlipperDevToolsModalOpen}
onClose={() => setFlipperDevToolsModalOpen(false)} onClose={() => setFlipperDevToolsModalOpen(false)}
/> />
<TroubleshootingModal />
</> </>
); );
} }
function TroubleshootingModal() {
const store = useStore();
const isOpen = useStore(
(state) => state.application.isTroubleshootingModalOpen,
);
return (
<Modal
visible={isOpen}
onCancel={() => store.dispatch(toggleConnectivityModal())}
width="100%"
footer={null}
style={{
// override default `top: 100px`
top: '5vh',
}}>
<div style={{minHeight: '80vh', width: '100%', display: 'flex'}}>
<TroubleshootingHub />
</div>
</Modal>
);
}
function FlipperDevToolsModal({ function FlipperDevToolsModal({
isOpen, isOpen,
onClose, onClose,