Avoid using electron directly for writing to clipboard

Summary: Similarly to previous stack, remove the need to import Electron to write things to clipboard. Introduced linter to prevent future use.

Reviewed By: timur-valiev

Differential Revision: D29661777

fbshipit-source-id: 7bc67ede40b65c5f232b69128f3a423e232ddc1b
This commit is contained in:
Michel Weststrate
2021-07-15 01:51:58 -07:00
committed by Facebook GitHub Bot
parent 5dbd3bd414
commit 9b9f5d15a1
2 changed files with 9 additions and 3 deletions

View File

@@ -86,6 +86,11 @@ module.exports = {
message: message:
"Direct imports from 'flipper' are deprecated. Import from 'flipper-plugin' instead, which can be tested and distributed stand-alone. See https://fbflipper.com/docs/extending/sandy-migration for more details.", "Direct imports from 'flipper' are deprecated. Import from 'flipper-plugin' instead, which can be tested and distributed stand-alone. See https://fbflipper.com/docs/extending/sandy-migration for more details.",
}, },
{
name: 'electron',
message:
"Direct imports from 'electron' are deprecated. Most functions can be found in getFlipperLib() from flipper-plugin package instead.",
},
], ],
// additional rules for this project // additional rules for this project

View File

@@ -22,7 +22,7 @@ import React from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import AutoSizer from 'react-virtualized-auto-sizer'; import AutoSizer from 'react-virtualized-auto-sizer';
import {VariableSizeList as List} from 'react-window'; import {VariableSizeList as List} from 'react-window';
import {clipboard, MenuItemConstructorOptions} from 'electron'; import {MenuItemConstructorOptions} from 'electron';
import TableHead from './TableHead'; import TableHead from './TableHead';
import TableRow from './TableRow'; import TableRow from './TableRow';
import ContextMenu from '../ContextMenu'; import ContextMenu from '../ContextMenu';
@@ -33,6 +33,7 @@ import {debounce} from 'lodash';
import {DEFAULT_ROW_HEIGHT} from './types'; import {DEFAULT_ROW_HEIGHT} from './types';
import textContent from '../../../utils/textContent'; import textContent from '../../../utils/textContent';
import {notNull} from '../../../utils/typeUtils'; import {notNull} from '../../../utils/typeUtils';
import {getFlipperLib} from 'flipper-plugin';
const EMPTY_OBJECT = {}; const EMPTY_OBJECT = {};
Object.freeze(EMPTY_OBJECT); Object.freeze(EMPTY_OBJECT);
@@ -319,7 +320,7 @@ export class ManagedTable extends React.Component<
}; };
onCopy = (withHeader: boolean) => { onCopy = (withHeader: boolean) => {
clipboard.writeText( getFlipperLib().writeTextToClipboard(
[ [
...(withHeader ? [this.getHeaderText()] : []), ...(withHeader ? [this.getHeaderText()] : []),
this.getSelectedText(), this.getSelectedText(),
@@ -520,7 +521,7 @@ export class ManagedTable extends React.Component<
onCopyCell = (rowId: string, index: number) => { onCopyCell = (rowId: string, index: number) => {
const cellText = this.getTextContentOfRow(rowId)[index]; const cellText = this.getTextContentOfRow(rowId)[index];
clipboard.writeText(cellText); getFlipperLib().writeTextToClipboard(cellText);
}; };
buildContextMenuItems: () => Array<MenuItemConstructorOptions> = () => { buildContextMenuItems: () => Array<MenuItemConstructorOptions> = () => {