Expose isConnected and currentUser
Summary: Requested by antonk52 and MSYS team Reviewed By: passy Differential Revision: D44662243 fbshipit-source-id: 2bace476c4e79b6a05bfb89ddc3e6acb437c6c3b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f8a1f38c0a
commit
7f111a11de
@@ -249,8 +249,17 @@ test('log listeners are resumed and suspended automatically - 1', async () => {
|
||||
},
|
||||
});
|
||||
|
||||
const baseFlipperLib = baseFlipperLibImplementation(
|
||||
getRenderHostInstance(),
|
||||
getLogger(),
|
||||
);
|
||||
_setFlipperLibImplementation({
|
||||
...baseFlipperLibImplementation(getRenderHostInstance(), getLogger()),
|
||||
...baseFlipperLib,
|
||||
intern: {
|
||||
...baseFlipperLib.intern,
|
||||
currentUser: jest.fn(),
|
||||
isConnected: jest.fn(),
|
||||
},
|
||||
createPaste: jest.fn(),
|
||||
enableMenuEntries: jest.fn(),
|
||||
selectPlugin: jest.fn(),
|
||||
@@ -328,8 +337,17 @@ test('log listeners are resumed and suspended automatically - 2', async () => {
|
||||
|
||||
const client = new TestClient(device, [Plugin]);
|
||||
|
||||
const baseFlipperLib = baseFlipperLibImplementation(
|
||||
getRenderHostInstance(),
|
||||
getLogger(),
|
||||
);
|
||||
_setFlipperLibImplementation({
|
||||
...baseFlipperLibImplementation(getRenderHostInstance(), getLogger()),
|
||||
...baseFlipperLib,
|
||||
intern: {
|
||||
...baseFlipperLib.intern,
|
||||
currentUser: jest.fn(),
|
||||
isConnected: jest.fn(),
|
||||
},
|
||||
createPaste: jest.fn(),
|
||||
enableMenuEntries: jest.fn(),
|
||||
selectPlugin: jest.fn(),
|
||||
|
||||
@@ -26,8 +26,12 @@ export function baseFlipperLibImplementation(
|
||||
logger: Logger,
|
||||
): Omit<
|
||||
FlipperLib,
|
||||
'enableMenuEntries' | 'selectPlugin' | 'showNotification' | 'createPaste'
|
||||
> {
|
||||
| 'enableMenuEntries'
|
||||
| 'selectPlugin'
|
||||
| 'showNotification'
|
||||
| 'createPaste'
|
||||
| 'intern'
|
||||
> & {intern: Omit<FlipperLib['intern'], 'currentUser' | 'isConnected'>} {
|
||||
return {
|
||||
isFB: !constants.IS_PUBLIC_BUILD,
|
||||
logger,
|
||||
|
||||
@@ -27,8 +27,10 @@ import {
|
||||
FSStatsLike,
|
||||
FlipperServerCommands,
|
||||
ENVIRONMENT_VARIABLES,
|
||||
User,
|
||||
} from 'flipper-common';
|
||||
import {CreatePasteArgs, CreatePasteResult} from './Paste';
|
||||
import {Atom} from '../state/atom';
|
||||
|
||||
export type FileEncoding = 'utf-8' | 'base64';
|
||||
|
||||
@@ -213,6 +215,8 @@ interface InternAPI {
|
||||
* @deprecated
|
||||
*/
|
||||
isLoggedIn: FlipperServerCommands['is-logged-in'];
|
||||
currentUser: () => Atom<User | null>;
|
||||
isConnected: () => Atom<boolean>;
|
||||
}
|
||||
|
||||
export let flipperLibInstance: FlipperLib | undefined;
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
FlipperPluginModule,
|
||||
SandyPluginDefinition,
|
||||
} from '../plugin/SandyPluginDefinition';
|
||||
import {createState} from '../state/atom';
|
||||
import {stubLogger} from '../utils/Logger';
|
||||
|
||||
declare const process: any;
|
||||
@@ -80,6 +81,8 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
||||
graphGet: createStubFunction(),
|
||||
graphPost: createStubFunction(),
|
||||
isLoggedIn: createStubFunction(),
|
||||
currentUser: () => createState(null),
|
||||
isConnected: () => createState(true),
|
||||
},
|
||||
remoteServerContext: {
|
||||
childProcess: {
|
||||
|
||||
@@ -7,15 +7,27 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Logger, _setFlipperLibImplementation} from 'flipper-plugin-core';
|
||||
import {
|
||||
createState,
|
||||
Logger,
|
||||
_setFlipperLibImplementation,
|
||||
} from 'flipper-plugin-core';
|
||||
import {baseFlipperLibImplementation, RenderHost} from 'flipper-frontend-core';
|
||||
|
||||
export function initializeFlipperLibImplementation(
|
||||
renderHost: RenderHost,
|
||||
logger: Logger,
|
||||
) {
|
||||
const base = baseFlipperLibImplementation(renderHost, logger);
|
||||
_setFlipperLibImplementation({
|
||||
...baseFlipperLibImplementation(renderHost, logger),
|
||||
...base,
|
||||
intern: {
|
||||
...base.intern,
|
||||
// TODO: Implement me
|
||||
currentUser: () => createState(null),
|
||||
// TODO: Implement me
|
||||
isConnected: () => createState(true),
|
||||
},
|
||||
enableMenuEntries() {},
|
||||
createPaste() {
|
||||
// TODO: Implement me
|
||||
|
||||
@@ -17,14 +17,21 @@ import {addNotification} from '../../reducers/notifications';
|
||||
import {deconstructPluginKey} from 'flipper-common';
|
||||
import {RenderHost} from 'flipper-frontend-core';
|
||||
import {setMenuEntries} from '../../reducers/connections';
|
||||
import {currentUser, isConnected} from '../../fb-stubs/user';
|
||||
|
||||
export function initializeFlipperLibImplementation(
|
||||
renderHost: RenderHost,
|
||||
store: Store,
|
||||
logger: Logger,
|
||||
) {
|
||||
const base = baseFlipperLibImplementation(renderHost, logger);
|
||||
_setFlipperLibImplementation({
|
||||
...baseFlipperLibImplementation(renderHost, logger),
|
||||
...base,
|
||||
intern: {
|
||||
...base.intern,
|
||||
currentUser,
|
||||
isConnected,
|
||||
},
|
||||
enableMenuEntries(entries) {
|
||||
store.dispatch(setMenuEntries(entries));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user