Introduce favorite plugins
Summary: This diff lands improved sidebar navigation. The old functionality to order plugins based on last-recently-used, and cropping at 5 items has been removed. Instead, items can be starred and their position will be fixed. Together with the app switcher introduced this should lead to a cleaner, stabler, and more customizable UI. Reviewed By: jknoxville Differential Revision: D18299401 fbshipit-source-id: 29b7eb3a4130933c637f7c81834558bf738d5bf0
This commit is contained in:
committed by
Facebook Github Bot
parent
969a857fae
commit
3cee927674
@@ -22,7 +22,6 @@ import {registerPlugins} from './reducers/plugins';
|
|||||||
import createTableNativePlugin from './plugins/TableNativePlugin';
|
import createTableNativePlugin from './plugins/TableNativePlugin';
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
import {Responder} from 'rsocket-types/ReactiveSocketTypes';
|
|
||||||
|
|
||||||
type Plugins = Array<string>;
|
type Plugins = Array<string>;
|
||||||
|
|
||||||
@@ -98,11 +97,6 @@ const handleError = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MAX_MINIMUM_PLUGINS = 5;
|
|
||||||
export const SHOW_REMAINING_PLUGIN_IF_LESS_THAN = 3;
|
|
||||||
export const SAVED_PLUGINS_COUNT =
|
|
||||||
MAX_MINIMUM_PLUGINS + SHOW_REMAINING_PLUGIN_IF_LESS_THAN;
|
|
||||||
|
|
||||||
export default class Client extends EventEmitter {
|
export default class Client extends EventEmitter {
|
||||||
app: App | undefined;
|
app: App | undefined;
|
||||||
connected: boolean;
|
connected: boolean;
|
||||||
@@ -111,8 +105,6 @@ export default class Client extends EventEmitter {
|
|||||||
sdkVersion: number;
|
sdkVersion: number;
|
||||||
messageIdCounter: number;
|
messageIdCounter: number;
|
||||||
plugins: Plugins;
|
plugins: Plugins;
|
||||||
lessPlugins: Plugins | undefined;
|
|
||||||
showAllPlugins: boolean;
|
|
||||||
connection: RSocketClientSocket<any, any> | null | undefined;
|
connection: RSocketClientSocket<any, any> | null | undefined;
|
||||||
store: Store;
|
store: Store;
|
||||||
activePlugins: Set<string>;
|
activePlugins: Set<string>;
|
||||||
@@ -146,7 +138,6 @@ export default class Client extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.plugins = plugins ? plugins : [];
|
this.plugins = plugins ? plugins : [];
|
||||||
this.showAllPlugins = false;
|
|
||||||
this.connection = conn;
|
this.connection = conn;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
@@ -188,29 +179,6 @@ export default class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sort plugins by LRU order stored in lessPlugins; if not, sort by alphabet
|
|
||||||
byClientLRU(
|
|
||||||
pluginsCount: number,
|
|
||||||
a: typeof FlipperPlugin,
|
|
||||||
b: typeof FlipperPlugin,
|
|
||||||
): number {
|
|
||||||
// Sanity check
|
|
||||||
if (this.lessPlugins != null) {
|
|
||||||
const showPluginsCount =
|
|
||||||
pluginsCount >= MAX_MINIMUM_PLUGINS + SHOW_REMAINING_PLUGIN_IF_LESS_THAN
|
|
||||||
? MAX_MINIMUM_PLUGINS
|
|
||||||
: pluginsCount;
|
|
||||||
let idxA = this.lessPlugins.indexOf(a.id);
|
|
||||||
idxA = idxA < 0 || idxA >= showPluginsCount ? showPluginsCount : idxA;
|
|
||||||
let idxB = this.lessPlugins.indexOf(b.id);
|
|
||||||
idxB = idxB < 0 || idxB >= showPluginsCount ? showPluginsCount : idxB;
|
|
||||||
if (idxA !== idxB) {
|
|
||||||
return idxA > idxB ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (a.title || a.id) > (b.title || b.id) ? 1 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* All clients should have a corresponding Device in the store.
|
/* All clients should have a corresponding Device in the store.
|
||||||
However, clients can connect before a device is registered, so wait a
|
However, clients can connect before a device is registered, so wait a
|
||||||
while for the device to be registered if it isn't already. */
|
while for the device to be registered if it isn't already. */
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {styled, colors} from 'flipper';
|
import {styled, colors, Glyph} from 'flipper';
|
||||||
import React, {useState, memo} from 'react';
|
import React, {useState, memo} from 'react';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {FlipperError, dismissError} from '../reducers/connections';
|
import {FlipperError, dismissError} from '../reducers/connections';
|
||||||
@@ -51,7 +51,13 @@ const ErrorBar = memo(function ErrorBar(props: Props) {
|
|||||||
<DismissAllErrors
|
<DismissAllErrors
|
||||||
onClick={() => setCollapsed(c => !c)}
|
onClick={() => setCollapsed(c => !c)}
|
||||||
title="Show / hide errors">
|
title="Show / hide errors">
|
||||||
{collapsed ? `▼ ${errorCount}` : '▲'}
|
<Glyph
|
||||||
|
color={colors.white}
|
||||||
|
size={8}
|
||||||
|
name={collapsed ? 'chevron-down' : 'chevron-up'}
|
||||||
|
style={{marginRight: 4}}
|
||||||
|
/>
|
||||||
|
{collapsed && errorCount}
|
||||||
</DismissAllErrors>
|
</DismissAllErrors>
|
||||||
</ErrorBarContainer>
|
</ErrorBarContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ import {
|
|||||||
FlipperDevicePlugin,
|
FlipperDevicePlugin,
|
||||||
LoadingIndicator,
|
LoadingIndicator,
|
||||||
Button,
|
Button,
|
||||||
|
StarButton,
|
||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import React, {Component, PureComponent, Fragment} from 'react';
|
import React, {Component, PureComponent, Fragment} from 'react';
|
||||||
import NotificationsHub from '../NotificationsHub';
|
import NotificationsHub from '../NotificationsHub';
|
||||||
import {
|
import {
|
||||||
selectPlugin,
|
selectPlugin,
|
||||||
showMoreOrLessPlugins,
|
starPlugin,
|
||||||
StaticView,
|
StaticView,
|
||||||
setStaticView,
|
setStaticView,
|
||||||
} from '../reducers/connections';
|
} from '../reducers/connections';
|
||||||
@@ -42,13 +43,12 @@ import {setActiveSheet} from '../reducers/application';
|
|||||||
import UserAccount from './UserAccount';
|
import UserAccount from './UserAccount';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {BackgroundColorProperty} from 'csstype';
|
import {BackgroundColorProperty} from 'csstype';
|
||||||
import {
|
|
||||||
MAX_MINIMUM_PLUGINS,
|
|
||||||
SHOW_REMAINING_PLUGIN_IF_LESS_THAN,
|
|
||||||
} from '../Client';
|
|
||||||
import {StyledOtherComponent} from 'create-emotion-styled';
|
import {StyledOtherComponent} from 'create-emotion-styled';
|
||||||
import SupportRequestFormManager from '../fb-stubs/SupportRequestFormManager';
|
import SupportRequestFormManager from '../fb-stubs/SupportRequestFormManager';
|
||||||
|
|
||||||
|
type FlipperPlugins = (typeof FlipperPlugin)[];
|
||||||
|
type PluginsByCategory = [string, FlipperPlugins][];
|
||||||
|
|
||||||
const ListItem = styled('div')(({active}: {active?: boolean}) => ({
|
const ListItem = styled('div')(({active}: {active?: boolean}) => ({
|
||||||
paddingLeft: 10,
|
paddingLeft: 10,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -64,19 +64,18 @@ const ListItem = styled('div')(({active}: {active?: boolean}) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const SidebarHeader = styled(FlexBox)({
|
const SidebarButton = styled(Button)(({small}: {small?: boolean}) => ({
|
||||||
display: 'block',
|
fontWeight: 'bold',
|
||||||
alignItems: 'center',
|
fontSize: small ? 11 : 14,
|
||||||
padding: 3,
|
width: '100%',
|
||||||
color: colors.macOSSidebarSectionTitle,
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: 500,
|
|
||||||
marginLeft: 7,
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
whiteSpace: 'nowrap',
|
marginTop: small ? 0 : 20,
|
||||||
flexShrink: 0,
|
pointer: 'cursor',
|
||||||
});
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
padding: 0,
|
||||||
|
justifyContent: 'left',
|
||||||
|
}));
|
||||||
|
|
||||||
const PluginShape = styled(FlexBox)(
|
const PluginShape = styled(FlexBox)(
|
||||||
({backgroundColor}: {backgroundColor?: BackgroundColorProperty}) => ({
|
({backgroundColor}: {backgroundColor?: BackgroundColorProperty}) => ({
|
||||||
@@ -130,23 +129,6 @@ const Plugins = styled(FlexColumn)({
|
|||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
});
|
});
|
||||||
|
|
||||||
const PluginDebugger = styled(FlexBox)({
|
|
||||||
color: colors.blackAlpha50,
|
|
||||||
alignItems: 'center',
|
|
||||||
padding: 10,
|
|
||||||
flexShrink: 0,
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
});
|
|
||||||
|
|
||||||
const PluginShowMoreOrLess = styled(ListItem)({
|
|
||||||
color: colors.blue,
|
|
||||||
fontSize: 10,
|
|
||||||
lineHeight: '10px',
|
|
||||||
paddingBottom: 5,
|
|
||||||
});
|
|
||||||
|
|
||||||
function PluginIcon({
|
function PluginIcon({
|
||||||
isActive,
|
isActive,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
@@ -170,9 +152,13 @@ class PluginSidebarListItem extends Component<{
|
|||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
plugin: typeof FlipperBasePlugin;
|
plugin: typeof FlipperBasePlugin;
|
||||||
app?: string | null | undefined;
|
app?: string | null | undefined;
|
||||||
|
helpRef?: any;
|
||||||
|
provided?: any;
|
||||||
|
onFavorite?: () => void;
|
||||||
|
starred?: boolean;
|
||||||
}> {
|
}> {
|
||||||
render() {
|
render() {
|
||||||
const {isActive, plugin} = this.props;
|
const {isActive, plugin, onFavorite, starred} = this.props;
|
||||||
const app = this.props.app || 'Facebook';
|
const app = this.props.app || 'Facebook';
|
||||||
let iconColor: string | undefined = (brandColors as any)[app];
|
let iconColor: string | undefined = (brandColors as any)[app];
|
||||||
|
|
||||||
@@ -201,6 +187,9 @@ class PluginSidebarListItem extends Component<{
|
|||||||
color={colors.white}
|
color={colors.white}
|
||||||
/>
|
/>
|
||||||
<PluginName>{plugin.title || plugin.id}</PluginName>
|
<PluginName>{plugin.title || plugin.id}</PluginName>
|
||||||
|
{starred !== undefined && (
|
||||||
|
<StarButton onStar={onFavorite!} starred={starred} />
|
||||||
|
)}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -230,6 +219,7 @@ type StateFromProps = {
|
|||||||
staticView: StaticView;
|
staticView: StaticView;
|
||||||
selectedPlugin: string | null | undefined;
|
selectedPlugin: string | null | undefined;
|
||||||
selectedApp: string | null | undefined;
|
selectedApp: string | null | undefined;
|
||||||
|
userStarredPlugins: Store['connections']['userStarredPlugins'];
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
client: UninitializedClient;
|
client: UninitializedClient;
|
||||||
@@ -248,16 +238,21 @@ type DispatchFromProps = {
|
|||||||
}) => void;
|
}) => void;
|
||||||
setActiveSheet: (activeSheet: ActiveSheet) => void;
|
setActiveSheet: (activeSheet: ActiveSheet) => void;
|
||||||
setStaticView: (payload: StaticView) => void;
|
setStaticView: (payload: StaticView) => void;
|
||||||
showMoreOrLessPlugins: (payload: string) => void;
|
starPlugin: typeof starPlugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = OwnProps & StateFromProps & DispatchFromProps;
|
type Props = OwnProps & StateFromProps & DispatchFromProps;
|
||||||
type State = {showSupportForm: boolean; selectedClientIndex: number};
|
type State = {
|
||||||
|
showSupportForm: boolean;
|
||||||
|
selectedClientIndex: number;
|
||||||
|
showAllPlugins: boolean;
|
||||||
|
};
|
||||||
class MainSidebar extends PureComponent<Props, State> {
|
class MainSidebar extends PureComponent<Props, State> {
|
||||||
state: State = {
|
state: State = {
|
||||||
showSupportForm: GK.get('flipper_support_requests'),
|
showSupportForm: GK.get('flipper_support_requests'),
|
||||||
// Not to be confused with selectedApp prop, this one only used to remember the client drowdown selector
|
// Not to be confused with selectedApp prop, this one only used to remember the client drowdown selector
|
||||||
selectedClientIndex: 0,
|
selectedClientIndex: 0,
|
||||||
|
showAllPlugins: false,
|
||||||
};
|
};
|
||||||
static getDerivedStateFromProps(props: Props, state: State) {
|
static getDerivedStateFromProps(props: Props, state: State) {
|
||||||
if (
|
if (
|
||||||
@@ -297,11 +292,6 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
const client: Client | null =
|
const client: Client | null =
|
||||||
clients[this.state.selectedClientIndex] || null;
|
clients[this.state.selectedClientIndex] || null;
|
||||||
|
|
||||||
const byPluginNameOrId = (
|
|
||||||
a: typeof FlipperBasePlugin,
|
|
||||||
b: typeof FlipperBasePlugin,
|
|
||||||
) => ((a.title || a.id) > (b.title || b.id) ? 1 : -1);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar
|
<Sidebar
|
||||||
position="left"
|
position="left"
|
||||||
@@ -310,60 +300,15 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
process.platform === 'darwin' && windowIsFocused ? 'transparent' : ''
|
process.platform === 'darwin' && windowIsFocused ? 'transparent' : ''
|
||||||
}>
|
}>
|
||||||
<Plugins>
|
<Plugins>
|
||||||
{!GK.get('flipper_disable_notifications') && (
|
|
||||||
<ListItem
|
|
||||||
active={selectedPlugin === 'notifications'}
|
|
||||||
onClick={() =>
|
|
||||||
selectPlugin({
|
|
||||||
selectedPlugin: 'notifications',
|
|
||||||
selectedApp: null,
|
|
||||||
deepLinkPayload: null,
|
|
||||||
})
|
|
||||||
}>
|
|
||||||
<PluginIcon
|
|
||||||
color={colors.light50}
|
|
||||||
name={
|
|
||||||
numNotifications > 0
|
|
||||||
? NotificationsHub.icon || 'bell'
|
|
||||||
: 'bell-null'
|
|
||||||
}
|
|
||||||
isActive={selectedPlugin === NotificationsHub.id}
|
|
||||||
/>
|
|
||||||
<PluginName
|
|
||||||
count={numNotifications}
|
|
||||||
isActive={selectedPlugin === NotificationsHub.id}>
|
|
||||||
{NotificationsHub.title}
|
|
||||||
</PluginName>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
{this.state.showSupportForm && (
|
|
||||||
<ListItem
|
|
||||||
active={
|
|
||||||
staticView != null && staticView === SupportRequestFormManager
|
|
||||||
}
|
|
||||||
onClick={() => setStaticView(SupportRequestFormManager)}>
|
|
||||||
<PluginIcon
|
|
||||||
color={colors.light50}
|
|
||||||
name={'app-dailies'}
|
|
||||||
isActive={
|
|
||||||
staticView != null && staticView === SupportRequestFormManager
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<PluginName
|
|
||||||
isActive={
|
|
||||||
staticView != null && staticView === SupportRequestFormManager
|
|
||||||
}>
|
|
||||||
Litho Support Request
|
|
||||||
</PluginName>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
|
||||||
{selectedDevice && (
|
{selectedDevice && (
|
||||||
<SidebarHeader>{selectedDevice.title}</SidebarHeader>
|
<ListItem>
|
||||||
|
<SidebarButton>{selectedDevice.title}</SidebarButton>
|
||||||
|
</ListItem>
|
||||||
)}
|
)}
|
||||||
{selectedDevice &&
|
{selectedDevice &&
|
||||||
Array.from(this.props.devicePlugins.values())
|
Array.from(this.props.devicePlugins.values())
|
||||||
.filter(plugin => plugin.supportsDevice(selectedDevice))
|
.filter(plugin => plugin.supportsDevice(selectedDevice))
|
||||||
.sort(byPluginNameOrId)
|
.sort(sortPluginsByName)
|
||||||
.map((plugin: typeof FlipperDevicePlugin) => (
|
.map((plugin: typeof FlipperDevicePlugin) => (
|
||||||
<PluginSidebarListItem
|
<PluginSidebarListItem
|
||||||
key={plugin.id}
|
key={plugin.id}
|
||||||
@@ -378,128 +323,248 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
plugin={plugin}
|
plugin={plugin}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<ListItem style={{marginTop: 20}}>
|
<ListItem>
|
||||||
<Button
|
<SidebarButton
|
||||||
title="Select a client to see available plugins"
|
title="Select an app to see available plugins"
|
||||||
compact={true}
|
compact={true}
|
||||||
dropdown={clients.map((c, index) => ({
|
dropdown={clients.map((c, index) => ({
|
||||||
checked: client === c,
|
checked: client === c,
|
||||||
label: c.query.app,
|
label: c.query.app,
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
click: () => this.setState({selectedClientIndex: index}),
|
click: () => this.setState({selectedClientIndex: index}),
|
||||||
}))}
|
}))}>
|
||||||
style={{
|
{clients.length === 0 ? (
|
||||||
fontSize: 11,
|
'(Not connected to app)'
|
||||||
width: '100%',
|
) : this.state.selectedClientIndex >= clients.length ? (
|
||||||
overflow: 'hidden',
|
'(Select app)'
|
||||||
}}>
|
) : (
|
||||||
{clients.length === 0
|
<>
|
||||||
? '(Not connected to client)'
|
{client.query.app}
|
||||||
: this.state.selectedClientIndex >= clients.length
|
{clients.length > 1 && (
|
||||||
? '(Select a client)'
|
<Glyph
|
||||||
: client.query.app}{' '}
|
size={12}
|
||||||
</Button>
|
name="chevron-down"
|
||||||
|
style={{marginLeft: 8}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</SidebarButton>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
{this.renderClientPlugins(client)}
|
{this.renderClientPlugins(client)}
|
||||||
{uninitializedClients.map(entry => (
|
{uninitializedClients.map(entry => (
|
||||||
<React.Fragment key={JSON.stringify(entry.client)}>
|
<ListItem key={JSON.stringify(entry.client)}>
|
||||||
<SidebarHeader>{entry.client.appName}</SidebarHeader>
|
{entry.client.appName}
|
||||||
{entry.errorMessage ? (
|
{entry.errorMessage ? (
|
||||||
<ErrorIndicator name={'mobile-cross'} size={16} />
|
<ErrorIndicator name={'mobile-cross'} size={16} />
|
||||||
) : (
|
) : (
|
||||||
<Spinner size={16} />
|
<Spinner size={16} />
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</ListItem>
|
||||||
))}
|
))}
|
||||||
</Plugins>
|
</Plugins>
|
||||||
<PluginDebugger
|
{!GK.get('flipper_disable_notifications') && (
|
||||||
|
<ListItem
|
||||||
|
active={selectedPlugin === 'notifications'}
|
||||||
|
onClick={() =>
|
||||||
|
selectPlugin({
|
||||||
|
selectedPlugin: 'notifications',
|
||||||
|
selectedApp: null,
|
||||||
|
deepLinkPayload: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
style={{
|
||||||
|
borderTop: `1px solid ${colors.blackAlpha10}`,
|
||||||
|
}}>
|
||||||
|
<PluginIcon
|
||||||
|
color={colors.light50}
|
||||||
|
name={
|
||||||
|
numNotifications > 0
|
||||||
|
? NotificationsHub.icon || 'bell'
|
||||||
|
: 'bell-null'
|
||||||
|
}
|
||||||
|
isActive={selectedPlugin === NotificationsHub.id}
|
||||||
|
/>
|
||||||
|
<PluginName
|
||||||
|
count={numNotifications}
|
||||||
|
isActive={selectedPlugin === NotificationsHub.id}>
|
||||||
|
{NotificationsHub.title}
|
||||||
|
</PluginName>
|
||||||
|
</ListItem>
|
||||||
|
)}
|
||||||
|
{this.state.showSupportForm && (
|
||||||
|
<ListItem
|
||||||
|
active={
|
||||||
|
staticView != null && staticView === SupportRequestFormManager
|
||||||
|
}
|
||||||
|
onClick={() => setStaticView(SupportRequestFormManager)}>
|
||||||
|
<PluginIcon
|
||||||
|
color={colors.light50}
|
||||||
|
name={'app-dailies'}
|
||||||
|
isActive={
|
||||||
|
staticView != null && staticView === SupportRequestFormManager
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<PluginName
|
||||||
|
isActive={
|
||||||
|
staticView != null && staticView === SupportRequestFormManager
|
||||||
|
}>
|
||||||
|
Litho Support Request
|
||||||
|
</PluginName>
|
||||||
|
</ListItem>
|
||||||
|
)}
|
||||||
|
<ListItem
|
||||||
onClick={() => this.props.setActiveSheet(ACTIVE_SHEET_PLUGINS)}>
|
onClick={() => this.props.setActiveSheet(ACTIVE_SHEET_PLUGINS)}>
|
||||||
<Glyph
|
<PluginIcon
|
||||||
name="question-circle"
|
name="question-circle"
|
||||||
size={16}
|
color={colors.light50}
|
||||||
variant="outline"
|
isActive={false}
|
||||||
color={colors.blackAlpha30}
|
|
||||||
/>
|
/>
|
||||||
Manage Plugins...
|
Manage Plugins
|
||||||
</PluginDebugger>
|
</ListItem>
|
||||||
{config.showLogin && <UserAccount />}
|
{config.showLogin && <UserAccount />}
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderPluginsByCategory(
|
||||||
|
client: Client,
|
||||||
|
plugins: FlipperPlugins,
|
||||||
|
starred: boolean,
|
||||||
|
onFavorite: (pluginId: string) => void,
|
||||||
|
) {
|
||||||
|
const {selectedPlugin, selectedApp, selectPlugin} = this.props;
|
||||||
|
return groupPluginsByCategory(plugins).map(([category, plugins]) => (
|
||||||
|
<Fragment key={category}>
|
||||||
|
{category && (
|
||||||
|
<ListItem>
|
||||||
|
<CategoryName>{category}</CategoryName>
|
||||||
|
</ListItem>
|
||||||
|
)}
|
||||||
|
{plugins.map(plugin => (
|
||||||
|
<PluginSidebarListItem
|
||||||
|
key={plugin.id}
|
||||||
|
isActive={plugin.id === selectedPlugin && selectedApp === client.id}
|
||||||
|
onClick={() =>
|
||||||
|
selectPlugin({
|
||||||
|
selectedPlugin: plugin.id,
|
||||||
|
selectedApp: client.id,
|
||||||
|
deepLinkPayload: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
plugin={plugin}
|
||||||
|
app={client.query.app}
|
||||||
|
onFavorite={() => onFavorite(plugin.id)}
|
||||||
|
starred={starred}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Fragment>
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
renderClientPlugins(client: Client | null) {
|
renderClientPlugins(client: Client | null) {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const {selectedPlugin, selectedApp, selectPlugin} = this.props;
|
const onFavorite = (plugin: string) => {
|
||||||
const plugins = Array.from(this.props.clientPlugins.values()).filter(
|
this.props.starPlugin({
|
||||||
(p: typeof FlipperPlugin) => client.plugins.indexOf(p.id) > -1,
|
selectedApp: client.id,
|
||||||
|
selectedPlugin: plugin,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const allPlugins = Array.from(this.props.clientPlugins.values());
|
||||||
|
const favoritePlugins: FlipperPlugins = getFavoritePlugins(
|
||||||
|
client,
|
||||||
|
allPlugins,
|
||||||
|
this.props.userStarredPlugins,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
const minShowPluginsCount =
|
|
||||||
plugins.length < MAX_MINIMUM_PLUGINS + SHOW_REMAINING_PLUGIN_IF_LESS_THAN
|
|
||||||
? plugins.length
|
|
||||||
: MAX_MINIMUM_PLUGINS;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={client.id}>
|
<>
|
||||||
{groupPluginsByCategory(
|
{favoritePlugins.length === 0 ? (
|
||||||
plugins
|
<ListItem>
|
||||||
.sort((a: typeof FlipperPlugin, b: typeof FlipperPlugin) =>
|
<div style={{textAlign: 'center', width: '100%'}}>
|
||||||
client.byClientLRU(plugins.length, a, b),
|
Star some plugins!
|
||||||
)
|
<hr style={{width: '100%'}} />
|
||||||
.slice(
|
</div>
|
||||||
0,
|
</ListItem>
|
||||||
client.showAllPlugins
|
) : (
|
||||||
? client.plugins.length
|
<>
|
||||||
: minShowPluginsCount,
|
{this.renderPluginsByCategory(
|
||||||
),
|
client,
|
||||||
).map(([category, plugins]) => (
|
favoritePlugins,
|
||||||
<Fragment key={category}>
|
true,
|
||||||
{category && (
|
onFavorite,
|
||||||
<ListItem>
|
|
||||||
<CategoryName>{category}</CategoryName>
|
|
||||||
</ListItem>
|
|
||||||
)}
|
)}
|
||||||
{plugins.map(plugin => (
|
<ListItem>
|
||||||
<PluginSidebarListItem
|
<SidebarButton
|
||||||
key={plugin.id}
|
small
|
||||||
isActive={
|
compact
|
||||||
plugin.id === selectedPlugin && selectedApp === client.id
|
|
||||||
}
|
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
selectPlugin({
|
this.setState(state => ({
|
||||||
selectedPlugin: plugin.id,
|
...state,
|
||||||
selectedApp: client.id,
|
showAllPlugins: !state.showAllPlugins,
|
||||||
deepLinkPayload: null,
|
}))
|
||||||
})
|
}>
|
||||||
}
|
{this.state.showAllPlugins ? 'Show less' : 'Show more'}
|
||||||
plugin={plugin}
|
<Glyph
|
||||||
app={client.query.app}
|
size={8}
|
||||||
/>
|
name={
|
||||||
))}
|
this.state.showAllPlugins ? 'chevron-up' : 'chevron-down'
|
||||||
</Fragment>
|
}
|
||||||
))}
|
style={{
|
||||||
{plugins.length > minShowPluginsCount && (
|
marginLeft: 4,
|
||||||
<PluginShowMoreOrLess
|
}}
|
||||||
onClick={() => this.props.showMoreOrLessPlugins(client.id)}>
|
/>
|
||||||
{client.showAllPlugins ? 'Show less' : 'Show more'}
|
</SidebarButton>
|
||||||
</PluginShowMoreOrLess>
|
</ListItem>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
<div
|
||||||
|
style={{
|
||||||
|
flex: 'auto' /*scroll this region, not the entire thing*/,
|
||||||
|
overflow: 'auto',
|
||||||
|
height: 'auto',
|
||||||
|
}}>
|
||||||
|
{this.state.showAllPlugins || favoritePlugins.length === 0
|
||||||
|
? this.renderPluginsByCategory(
|
||||||
|
client,
|
||||||
|
getFavoritePlugins(
|
||||||
|
client,
|
||||||
|
allPlugins,
|
||||||
|
this.props.userStarredPlugins,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
onFavorite,
|
||||||
|
)
|
||||||
|
: null}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginsByCategory = [string, (typeof FlipperPlugin)[]][];
|
function getFavoritePlugins(
|
||||||
|
client: Client,
|
||||||
|
allPlugins: FlipperPlugins,
|
||||||
|
userStarredPlugins: Props['userStarredPlugins'],
|
||||||
|
favorite: boolean,
|
||||||
|
): FlipperPlugins {
|
||||||
|
const appName = client.id;
|
||||||
|
return allPlugins.filter(plugin => {
|
||||||
|
const idx = userStarredPlugins[appName]
|
||||||
|
? userStarredPlugins[appName].indexOf(plugin.id)
|
||||||
|
: -1;
|
||||||
|
return idx === -1 ? !favorite : favorite;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function groupPluginsByCategory(
|
function groupPluginsByCategory(plugins: FlipperPlugins): PluginsByCategory {
|
||||||
plugins: (typeof FlipperPlugin)[],
|
const sortedPlugins = plugins.slice().sort(sortPluginsByName);
|
||||||
): PluginsByCategory {
|
const byCategory: {[cat: string]: FlipperPlugins} = {};
|
||||||
// Pre condition: plugins are already sorted globally
|
|
||||||
const byCategory: {[cat: string]: (typeof FlipperPlugin)[]} = {};
|
|
||||||
const res: PluginsByCategory = [];
|
const res: PluginsByCategory = [];
|
||||||
plugins.forEach(plugin => {
|
sortedPlugins.forEach(plugin => {
|
||||||
const category = plugin.category || '';
|
const category = plugin.category || '';
|
||||||
(byCategory[category] || (byCategory[category] = [])).push(plugin);
|
(byCategory[category] || (byCategory[category] = [])).push(plugin);
|
||||||
});
|
});
|
||||||
@@ -512,6 +577,13 @@ function groupPluginsByCategory(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortPluginsByName(
|
||||||
|
a: typeof FlipperBasePlugin,
|
||||||
|
b: typeof FlipperBasePlugin,
|
||||||
|
): number {
|
||||||
|
return (a.title || a.id) > (b.title || b.id) ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
||||||
({
|
({
|
||||||
application: {windowIsFocused},
|
application: {windowIsFocused},
|
||||||
@@ -519,6 +591,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
selectedDevice,
|
selectedDevice,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
selectedApp,
|
selectedApp,
|
||||||
|
userStarredPlugins,
|
||||||
clients,
|
clients,
|
||||||
uninitializedClients,
|
uninitializedClients,
|
||||||
staticView,
|
staticView,
|
||||||
@@ -537,6 +610,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
staticView,
|
staticView,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
selectedApp,
|
selectedApp,
|
||||||
|
userStarredPlugins,
|
||||||
clients,
|
clients,
|
||||||
uninitializedClients,
|
uninitializedClients,
|
||||||
devicePlugins,
|
devicePlugins,
|
||||||
@@ -546,6 +620,6 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
selectPlugin,
|
selectPlugin,
|
||||||
setStaticView,
|
setStaticView,
|
||||||
setActiveSheet,
|
setActiveSheet,
|
||||||
showMoreOrLessPlugins,
|
starPlugin,
|
||||||
},
|
},
|
||||||
)(MainSidebar);
|
)(MainSidebar);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {UninitializedClient} from '../UninitializedClient';
|
|||||||
import {isEqual} from 'lodash';
|
import {isEqual} from 'lodash';
|
||||||
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
||||||
import {performance} from 'perf_hooks';
|
import {performance} from 'perf_hooks';
|
||||||
import {SAVED_PLUGINS_COUNT} from '../Client';
|
|
||||||
import isHeadless from '../utils/isHeadless';
|
import isHeadless from '../utils/isHeadless';
|
||||||
import {Actions} from '.';
|
import {Actions} from '.';
|
||||||
const WelcomeScreen = isHeadless()
|
const WelcomeScreen = isHeadless()
|
||||||
@@ -43,7 +42,7 @@ export type State = {
|
|||||||
userPreferredDevice: null | string;
|
userPreferredDevice: null | string;
|
||||||
userPreferredPlugin: null | string;
|
userPreferredPlugin: null | string;
|
||||||
userPreferredApp: null | string;
|
userPreferredApp: null | string;
|
||||||
userLRUPlugins: {[key: string]: Array<string>};
|
userStarredPlugins: {[key: string]: Array<string>};
|
||||||
errors: FlipperError[];
|
errors: FlipperError[];
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
@@ -116,11 +115,6 @@ export type Action =
|
|||||||
type: 'CLIENT_SETUP_ERROR';
|
type: 'CLIENT_SETUP_ERROR';
|
||||||
payload: {client: UninitializedClient; error: FlipperError};
|
payload: {client: UninitializedClient; error: FlipperError};
|
||||||
}
|
}
|
||||||
| {
|
|
||||||
type: 'CLIENT_SHOW_MORE_OR_LESS';
|
|
||||||
payload: string;
|
|
||||||
}
|
|
||||||
| {type: 'CLEAR_LRU_PLUGINS_HISTORY'}
|
|
||||||
| {
|
| {
|
||||||
type: 'SET_STATIC_VIEW';
|
type: 'SET_STATIC_VIEW';
|
||||||
payload: StaticView;
|
payload: StaticView;
|
||||||
@@ -128,6 +122,13 @@ export type Action =
|
|||||||
| {
|
| {
|
||||||
type: 'DISMISS_ERROR';
|
type: 'DISMISS_ERROR';
|
||||||
payload: number;
|
payload: number;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: 'STAR_PLUGIN';
|
||||||
|
payload: {
|
||||||
|
selectedPlugin: string;
|
||||||
|
selectedApp: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_PLUGIN = 'DeviceLogs';
|
const DEFAULT_PLUGIN = 'DeviceLogs';
|
||||||
@@ -141,7 +142,7 @@ const INITAL_STATE: State = {
|
|||||||
userPreferredDevice: null,
|
userPreferredDevice: null,
|
||||||
userPreferredPlugin: null,
|
userPreferredPlugin: null,
|
||||||
userPreferredApp: null,
|
userPreferredApp: null,
|
||||||
userLRUPlugins: {},
|
userStarredPlugins: {},
|
||||||
errors: [],
|
errors: [],
|
||||||
clients: [],
|
clients: [],
|
||||||
uninitializedClients: [],
|
uninitializedClients: [],
|
||||||
@@ -259,45 +260,43 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userPreferredApp = selectedApp || state.userPreferredApp;
|
const userPreferredApp = selectedApp || state.userPreferredApp;
|
||||||
const selectedAppName = extractAppNameFromAppId(userPreferredApp);
|
|
||||||
// Need to recreate an array to make sure that it doesn't refer to the
|
|
||||||
// array that is showed in on the screen and the array that is kept for
|
|
||||||
// least recently used plugins reference
|
|
||||||
const LRUPlugins = [
|
|
||||||
...((selectedAppName && state.userLRUPlugins[selectedAppName]) || []),
|
|
||||||
];
|
|
||||||
const idxLRU =
|
|
||||||
(selectedPlugin && LRUPlugins.indexOf(selectedPlugin)) || -1;
|
|
||||||
if (idxLRU >= 0) {
|
|
||||||
LRUPlugins.splice(idxLRU, 1);
|
|
||||||
}
|
|
||||||
selectedPlugin && LRUPlugins.unshift(selectedPlugin);
|
|
||||||
LRUPlugins.splice(SAVED_PLUGINS_COUNT);
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
...payload,
|
...payload,
|
||||||
staticView: null,
|
staticView: null,
|
||||||
userPreferredApp: userPreferredApp,
|
userPreferredApp: userPreferredApp,
|
||||||
userPreferredPlugin: selectedPlugin,
|
userPreferredPlugin: selectedPlugin,
|
||||||
userLRUPlugins: selectedAppName
|
|
||||||
? {
|
|
||||||
...state.userLRUPlugins,
|
|
||||||
[selectedAppName]: LRUPlugins,
|
|
||||||
}
|
|
||||||
: {...state.userLRUPlugins},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case 'STAR_PLUGIN': {
|
||||||
|
const {selectedPlugin, selectedApp} = action.payload;
|
||||||
|
const starredPluginsForApp = [
|
||||||
|
...(state.userStarredPlugins[selectedApp] || []),
|
||||||
|
];
|
||||||
|
const idx = starredPluginsForApp.indexOf(selectedPlugin);
|
||||||
|
if (idx === -1) {
|
||||||
|
starredPluginsForApp.push(selectedPlugin);
|
||||||
|
} else {
|
||||||
|
starredPluginsForApp.splice(idx, 1);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
userStarredPlugins: {
|
||||||
|
...state.userStarredPlugins,
|
||||||
|
[selectedApp]: starredPluginsForApp,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
||||||
const {payload} = action;
|
const {payload} = action;
|
||||||
return {...state, userPreferredPlugin: payload};
|
return {...state, userPreferredPlugin: payload};
|
||||||
}
|
}
|
||||||
case 'NEW_CLIENT': {
|
case 'NEW_CLIENT': {
|
||||||
const {payload} = action;
|
const {payload} = action;
|
||||||
const {userPreferredApp, userPreferredPlugin, userLRUPlugins} = state;
|
const {userPreferredApp, userPreferredPlugin} = state;
|
||||||
let {selectedApp, selectedPlugin} = state;
|
let {selectedApp, selectedPlugin} = state;
|
||||||
|
|
||||||
const appName = extractAppNameFromAppId(payload.id);
|
|
||||||
payload.lessPlugins = (appName && userLRUPlugins[appName]) || [];
|
|
||||||
if (
|
if (
|
||||||
userPreferredApp &&
|
userPreferredApp &&
|
||||||
userPreferredPlugin &&
|
userPreferredPlugin &&
|
||||||
@@ -317,10 +316,6 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
c.client.appName !== payload.query.app
|
c.client.appName !== payload.query.app
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
userLRUPlugins: {
|
|
||||||
...state.userLRUPlugins,
|
|
||||||
[payload.id]: payload.lessPlugins,
|
|
||||||
},
|
|
||||||
selectedApp,
|
selectedApp,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
};
|
};
|
||||||
@@ -420,33 +415,6 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'CLIENT_SHOW_MORE_OR_LESS': {
|
|
||||||
const {payload} = action;
|
|
||||||
const appName = extractAppNameFromAppId(payload);
|
|
||||||
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
clients: state.clients.map((client: Client) => {
|
|
||||||
if (appName && extractAppNameFromAppId(client.id) === appName) {
|
|
||||||
client.showAllPlugins = !client.showAllPlugins;
|
|
||||||
client.lessPlugins = state.userLRUPlugins[appName] || [];
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case 'CLEAR_LRU_PLUGINS_HISTORY': {
|
|
||||||
const clearLRUPlugins: {[key: string]: Array<string>} = {};
|
|
||||||
Object.keys(state.userLRUPlugins).forEach((key: string) => {
|
|
||||||
if (key !== null) {
|
|
||||||
clearLRUPlugins[key] = [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
userLRUPlugins: clearLRUPlugins,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case 'DISMISS_ERROR': {
|
case 'DISMISS_ERROR': {
|
||||||
const errors = state.errors.slice();
|
const errors = state.errors.slice();
|
||||||
errors.splice(action.payload, 1);
|
errors.splice(action.payload, 1);
|
||||||
@@ -531,8 +499,11 @@ export const selectPlugin = (payload: {
|
|||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const showMoreOrLessPlugins = (payload: string): Action => ({
|
export const starPlugin = (payload: {
|
||||||
type: 'CLIENT_SHOW_MORE_OR_LESS',
|
selectedPlugin: string;
|
||||||
|
selectedApp: string;
|
||||||
|
}): Action => ({
|
||||||
|
type: 'STAR_PLUGIN',
|
||||||
payload,
|
payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export default combineReducers<State, Actions>({
|
|||||||
'userPreferredDevice',
|
'userPreferredDevice',
|
||||||
'userPreferredPlugin',
|
'userPreferredPlugin',
|
||||||
'userPreferredApp',
|
'userPreferredApp',
|
||||||
'userLRUPlugins',
|
'userStarredPlugins',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
connections,
|
connections,
|
||||||
|
|||||||
@@ -43,12 +43,13 @@ function ColoredIcon(
|
|||||||
size?: number;
|
size?: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
glyphColor?: string;
|
glyphColor?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const {color = context.glyphColor, name, size = 16, src} = props;
|
const {color = context.glyphColor, name, size = 16, src, style} = props;
|
||||||
|
|
||||||
const isBlack =
|
const isBlack =
|
||||||
color == null ||
|
color == null ||
|
||||||
@@ -63,6 +64,7 @@ function ColoredIcon(
|
|||||||
src={src}
|
src={src}
|
||||||
size={size}
|
size={size}
|
||||||
className={props.className}
|
className={props.className}
|
||||||
|
style={style}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -72,6 +74,7 @@ function ColoredIcon(
|
|||||||
size={size}
|
size={size}
|
||||||
src={src}
|
src={src}
|
||||||
className={props.className}
|
className={props.className}
|
||||||
|
style={style}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -87,9 +90,10 @@ export default class Glyph extends React.PureComponent<{
|
|||||||
variant?: 'filled' | 'outline';
|
variant?: 'filled' | 'outline';
|
||||||
className?: string;
|
className?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
}> {
|
}> {
|
||||||
render() {
|
render() {
|
||||||
const {name, size = 16, variant, color, className} = this.props;
|
const {name, size = 16, variant, color, className, style} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ColoredIcon
|
<ColoredIcon
|
||||||
@@ -102,6 +106,7 @@ export default class Glyph extends React.PureComponent<{
|
|||||||
size,
|
size,
|
||||||
typeof window !== 'undefined' ? window.devicePixelRatio : 1,
|
typeof window !== 'undefined' ? window.devicePixelRatio : 1,
|
||||||
)}
|
)}
|
||||||
|
style={style}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/ui/components/StarButton.tsx
Normal file
62
src/ui/components/StarButton.tsx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, {useState, useCallback} from 'react';
|
||||||
|
import {colors} from './colors';
|
||||||
|
import Glyph from './Glyph';
|
||||||
|
import styled from 'react-emotion';
|
||||||
|
|
||||||
|
const DownscaledGlyph = styled(Glyph)({
|
||||||
|
maskSize: '12px 12px',
|
||||||
|
WebkitMaskSize: '12px 12px',
|
||||||
|
height: 12,
|
||||||
|
width: 12,
|
||||||
|
});
|
||||||
|
|
||||||
|
export function StarButton({
|
||||||
|
starred,
|
||||||
|
onStar,
|
||||||
|
}: {
|
||||||
|
starred: boolean;
|
||||||
|
onStar: () => void;
|
||||||
|
}) {
|
||||||
|
const [hovered, setHovered] = useState(false);
|
||||||
|
const handleClick = useCallback(
|
||||||
|
(e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
onStar();
|
||||||
|
},
|
||||||
|
[onStar],
|
||||||
|
);
|
||||||
|
const handleMouseEnter = useCallback(setHovered.bind(null, true), []);
|
||||||
|
const handleMouseLeave = useCallback(setHovered.bind(null, false), []);
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
style={{
|
||||||
|
border: 'none',
|
||||||
|
background: 'none',
|
||||||
|
cursor: 'pointer',
|
||||||
|
padding: 0,
|
||||||
|
paddingLeft: 4,
|
||||||
|
flex: 0,
|
||||||
|
}}
|
||||||
|
onClick={handleClick}
|
||||||
|
onMouseEnter={handleMouseEnter}
|
||||||
|
onMouseLeave={handleMouseLeave}>
|
||||||
|
<DownscaledGlyph
|
||||||
|
size={
|
||||||
|
16 /* the icons used below are not available in smaller sizes :-/ */
|
||||||
|
}
|
||||||
|
name={hovered ? (starred ? 'star-slash' : 'life-event-major') : 'star'}
|
||||||
|
color={hovered ? colors.lemonDark1 : colors.macOSTitleBarIconBlur}
|
||||||
|
variant={hovered || starred ? 'filled' : 'outline'}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -175,3 +175,4 @@ export {InspectorSidebar} from './components/elements-inspector/sidebar';
|
|||||||
export {Console} from './components/console';
|
export {Console} from './components/console';
|
||||||
|
|
||||||
export {default as Sheet} from './components/Sheet';
|
export {default as Sheet} from './components/Sheet';
|
||||||
|
export {StarButton} from './components/StarButton';
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ const ICONS = {
|
|||||||
'caution-octagon': [16],
|
'caution-octagon': [16],
|
||||||
'caution-triangle': [16],
|
'caution-triangle': [16],
|
||||||
'chevron-down-outline': [10],
|
'chevron-down-outline': [10],
|
||||||
'chevron-down': [8],
|
'chevron-down': [8, 12],
|
||||||
|
'chevron-up': [8, 12],
|
||||||
'chevron-right': [8],
|
'chevron-right': [8],
|
||||||
'dots-3-circle-outline': [16],
|
'dots-3-circle-outline': [16],
|
||||||
'info-circle': [16],
|
'info-circle': [16],
|
||||||
@@ -52,6 +53,8 @@ const ICONS = {
|
|||||||
rocket: [20],
|
rocket: [20],
|
||||||
settings: [12],
|
settings: [12],
|
||||||
star: [16, 24],
|
star: [16, 24],
|
||||||
|
'star-slash': [16],
|
||||||
|
'life-event-major': [16],
|
||||||
target: [12, 16],
|
target: [12, 16],
|
||||||
tools: [20],
|
tools: [20],
|
||||||
};
|
};
|
||||||
@@ -77,7 +80,12 @@ function buildLocalIconPath(name, size, density) {
|
|||||||
// $FlowFixMe not using flow in this file
|
// $FlowFixMe not using flow in this file
|
||||||
function buildIconURL(name, size, density) {
|
function buildIconURL(name, size, density) {
|
||||||
const icon = getIconPartsFromName(name);
|
const icon = getIconPartsFromName(name);
|
||||||
const url = `https://external.xx.fbcdn.net/assets/?name=${icon.trimmedName}&variant=${icon.variant}&size=${size}&set=facebook_icons&density=${density}x`;
|
// eslint-disable-next-line prettier/prettier
|
||||||
|
const url = `https://external.xx.fbcdn.net/assets/?name=${
|
||||||
|
icon.trimmedName
|
||||||
|
}&variant=${
|
||||||
|
icon.variant
|
||||||
|
}&size=${size}&set=facebook_icons&density=${density}x`;
|
||||||
if (
|
if (
|
||||||
typeof window !== 'undefined' &&
|
typeof window !== 'undefined' &&
|
||||||
(!ICONS[name] || !ICONS[name].includes(size))
|
(!ICONS[name] || !ICONS[name].includes(size))
|
||||||
|
|||||||
Reference in New Issue
Block a user