Settings panel

Summary:
This enables opening the settings panel from Sandy. Created a small code switch in layouting to make sure it looks ok in both sandy and native dialog. Inside the settings no new components are used yet, which will be done in next diffs.

Also removed the close button from temporarily titlebar as settings are now accessible from Sandy chrome

Reviewed By: cekkaewnumchai

Differential Revision: D23812321

fbshipit-source-id: f8888373632786bb75f6dad635d300729b5086dc
This commit is contained in:
Michel Weststrate
2020-09-22 12:01:46 -07:00
committed by Facebook GitHub Bot
parent 1c3df6ed8e
commit fdd2151532
5 changed files with 95 additions and 44 deletions

View File

@@ -27,6 +27,7 @@ import restartFlipper from '../utils/restartFlipper';
import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel'; import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel';
import SandySettingsPanel from '../fb-stubs/SandySettingsPanel'; import SandySettingsPanel from '../fb-stubs/SandySettingsPanel';
import {reportUsage} from '../utils/metrics'; import {reportUsage} from '../utils/metrics';
import {Modal} from 'antd';
const Container = styled(FlexColumn)({ const Container = styled(FlexColumn)({
padding: 20, padding: 20,
@@ -41,6 +42,7 @@ const Title = styled(Text)({
}); });
type OwnProps = { type OwnProps = {
useSandy?: boolean;
onHide: () => void; onHide: () => void;
platform: NodeJS.Platform; platform: NodeJS.Platform;
}; };
@@ -88,6 +90,39 @@ class SettingsSheet extends Component<Props, State> {
this.props.onHide(); this.props.onHide();
}; };
renderSandyContainer(
contents: React.ReactElement,
footer: React.ReactElement,
) {
return (
<Modal
visible
onCancel={this.props.onHide}
width={570}
title="Settings"
footer={footer}>
<FlexColumn>{contents}</FlexColumn>
</Modal>
);
}
renderNativeContainer(
contents: React.ReactElement,
footer: React.ReactElement,
) {
return (
<Container>
<Title>Settings</Title>
{contents}
<br />
<FlexRow>
<Spacer />
{footer}
</FlexRow>
</Container>
);
}
render() { render() {
const { const {
enableAndroid, enableAndroid,
@@ -100,14 +135,14 @@ class SettingsSheet extends Component<Props, State> {
enableSandy, enableSandy,
darkMode, darkMode,
} = this.state.updatedSettings; } = this.state.updatedSettings;
const {useSandy} = this.props;
const settingsPristine = const settingsPristine =
isEqual(this.props.settings, this.state.updatedSettings) && isEqual(this.props.settings, this.state.updatedSettings) &&
isEqual(this.props.launcherSettings, this.state.updatedLauncherSettings); isEqual(this.props.launcherSettings, this.state.updatedLauncherSettings);
return ( const contents = (
<Container> <>
<Title>Settings</Title>
<ToggledSection <ToggledSection
label="Android Developer" label="Android Developer"
toggled={enableAndroid} toggled={enableAndroid}
@@ -276,9 +311,11 @@ class SettingsSheet extends Component<Props, State> {
}} }}
/> />
</ToggledSection> </ToggledSection>
<br /> </>
<FlexRow> );
<Spacer />
const footer = (
<>
<Button compact padded onClick={this.props.onHide}> <Button compact padded onClick={this.props.onHide}>
Cancel Cancel
</Button> </Button>
@@ -297,9 +334,12 @@ class SettingsSheet extends Component<Props, State> {
onClick={this.applyChanges}> onClick={this.applyChanges}>
Apply and Restart Apply and Restart
</Button> </Button>
</FlexRow> </>
</Container>
); );
return useSandy
? this.renderSandyContainer(contents, footer)
: this.renderNativeContainer(contents, footer);
} }
} }

View File

@@ -9,13 +9,14 @@
import {FlexColumn, styled, FlexRow, ToggleButton} from 'flipper'; import {FlexColumn, styled, FlexRow, ToggleButton} from 'flipper';
import React from 'react'; import React from 'react';
import {theme} from '../../sandy-chrome/theme';
const IndentedSection = styled(FlexColumn)({ const IndentedSection = styled(FlexColumn)({
paddingLeft: 50, paddingLeft: 50,
paddingBottom: 10, paddingBottom: 10,
}); });
const GreyedOutOverlay = styled.div({ const GreyedOutOverlay = styled.div({
backgroundColor: '#EFEEEF', background: theme.backgroundDefault,
borderRadius: 4, borderRadius: 4,
opacity: 0.6, opacity: 0.6,
height: '100%', height: '100%',

View File

@@ -7,7 +7,7 @@
* @format * @format
*/ */
import React, {cloneElement} from 'react'; import React, {cloneElement, useState, useCallback} from 'react';
import {styled, FlexColumn} from 'flipper'; import {styled, FlexColumn} from 'flipper';
import {Button, Divider, Badge, Tooltip} from 'antd'; import {Button, Divider, Badge, Tooltip} from 'antd';
import { import {
@@ -25,6 +25,7 @@ import {SidebarLeft, SidebarRight} from './SandyIcons';
import {useDispatch, useStore} from '../utils/useStore'; import {useDispatch, useStore} from '../utils/useStore';
import {toggleLeftSidebarVisible} from '../reducers/application'; import {toggleLeftSidebarVisible} from '../reducers/application';
import {theme} from './theme'; import {theme} from './theme';
import SettingsSheet from '../chrome/SettingsSheet';
const LeftRailContainer = styled(FlexColumn)({ const LeftRailContainer = styled(FlexColumn)({
background: theme.backgroundDefault, background: theme.backgroundDefault,
@@ -62,7 +63,7 @@ function LeftRailButton({
icon?: React.ReactElement; icon?: React.ReactElement;
small?: boolean; small?: boolean;
toggled?: boolean; toggled?: boolean;
selected?: boolean; selected?: boolean; // TODO: make sure only one element can be selected
count?: number; count?: number;
title: string; title: string;
onClick?: React.MouseEventHandler<HTMLElement>; onClick?: React.MouseEventHandler<HTMLElement>;
@@ -123,7 +124,7 @@ export function LeftRail() {
small small
title="Help / Start Screen" title="Help / Start Screen"
/> />
<LeftRailButton icon={<SettingOutlined />} small title="Settings" /> <ShowSettingsButton />
<LeftRailButton <LeftRailButton
icon={<BugOutlined />} icon={<BugOutlined />}
small small
@@ -160,3 +161,22 @@ function LeftSidebarToggleButton() {
/> />
); );
} }
function ShowSettingsButton() {
const [showSettings, setShowSettings] = useState(false);
const onClose = useCallback(() => setShowSettings(false), []);
return (
<>
<LeftRailButton
icon={<SettingOutlined />}
small
title="Settings"
onClick={() => setShowSettings(true)}
selected={showSettings}
/>
{showSettings && (
<SettingsSheet platform={process.platform} onHide={onClose} useSandy />
)}
</>
);
}

View File

@@ -39,7 +39,9 @@ export function SandyApp({logger}: {logger: Logger}) {
<LeftMenu collapsed={!mainMenuVisible}> <LeftMenu collapsed={!mainMenuVisible}>
<LeftRail /> <LeftRail />
{mainMenuVisible && ( {mainMenuVisible && (
<div style={{background: 'white', width: '100%'}}>LeftMenu</div> <div style={{background: theme.backgroundDefault, width: '100%'}}>
LeftMenu
</div>
)} )}
</LeftMenu> </LeftMenu>
<MainContainer> <MainContainer>

View File

@@ -8,10 +8,7 @@
*/ */
import React from 'react'; import React from 'react';
import {updateSettings} from '../reducers/settings';
import {styled, colors} from 'flipper'; import {styled, colors} from 'flipper';
import {Button, Space} from 'antd';
import {CloseCircleOutlined} from '@ant-design/icons';
import FpsGraph from '../chrome/FpsGraph'; import FpsGraph from '../chrome/FpsGraph';
import NetworkGraph from '../chrome/NetworkGraph'; import NetworkGraph from '../chrome/NetworkGraph';
import isProduction from '../utils/isProduction'; import isProduction from '../utils/isProduction';
@@ -20,7 +17,7 @@ import AutoUpdateVersion from '../chrome/AutoUpdateVersion';
import UpdateIndicator from '../chrome/UpdateIndicator'; import UpdateIndicator from '../chrome/UpdateIndicator';
import RatingButton from '../chrome/RatingButton'; import RatingButton from '../chrome/RatingButton';
import {Version} from '../chrome/TitleBar'; import {Version} from '../chrome/TitleBar';
import {useDispatch, useStore} from '../utils/useStore'; import {useStore} from '../utils/useStore';
import config from '../fb-stubs/config'; import config from '../fb-stubs/config';
import {remote} from 'electron'; import {remote} from 'electron';
@@ -51,21 +48,12 @@ const TemporarilyTitlebarContainer = styled('div')<{focused?: boolean}>(
// This component should be dropped, and insetTitlebar should be removed from Electron startup once Sandy is the default // This component should be dropped, and insetTitlebar should be removed from Electron startup once Sandy is the default
// But: figure out where to put the graphs, version numbers, flipper rating ets :) // But: figure out where to put the graphs, version numbers, flipper rating ets :)
export function TemporarilyTitlebar() { export function TemporarilyTitlebar() {
const dispatch = useDispatch();
const settings = useStore((state) => state.settingsState);
const launcherMsg = useStore((state) => state.application.launcherMsg); const launcherMsg = useStore((state) => state.application.launcherMsg);
const isFocused = useStore((state) => state.application.windowIsFocused); const isFocused = useStore((state) => state.application.windowIsFocused);
return ( return (
<TemporarilyTitlebarContainer focused={isFocused}> <TemporarilyTitlebarContainer focused={isFocused}>
[Sandy] Flipper{' '} [Sandy] Flipper{' '}
<Button
size="small"
type="link"
icon={<CloseCircleOutlined />}
onClick={() =>
dispatch(updateSettings({...settings, enableSandy: false}))
}></Button>
{!isProduction() && <NetworkGraph height={20} width={60} />} {!isProduction() && <NetworkGraph height={20} width={60} />}
{!isProduction() && <FpsGraph height={20} width={60} />} {!isProduction() && <FpsGraph height={20} width={60} />}
{config.showFlipperRating ? <RatingButton /> : null} {config.showFlipperRating ? <RatingButton /> : null}