@samitouri / QOS-React-2 / commits / 9a05e0b600

Disable view-source button in standalone mode if no project roots are provided

Brian Vaughn committed Jul 24, 2019 at 13:36 UTC 9a05e0b600df6a7a5097a6998bcd2d1d95da062d
5 files changed +28 -23
packages/react-devtools-core/src/standalone.js
+4 -2
@@ -85,7 +85,6 @@ function reload() {
85 root.render(
86 createElement(DevTools, {
87 bridge: ((bridge: any): FrontendBridge),
88 - isBrowserMode: false,
88 showTabBar: true,
89 store: ((store: any): Store),
90 warnIfLegacyBackendDetected: true,
@@ -172,7 +171,10 @@ function initialize(socket: WebSocket) {
171 socket.close();
172 });
173
175 - store = new Store(bridge, { supportsNativeInspection: false });
174 + store = new Store(bridge, {
175 + supportsNativeInspection: false,
176 + supportsViewSource: projectRoots.length > 0,
177 + });
178
179 log('Connected');
180 reload();
src/devtools/store.js
+8
@@ -49,6 +49,7 @@ type Config = {|
49 supportsNativeInspection?: boolean,
50 supportsReloadAndProfile?: boolean,
51 supportsProfiling?: boolean,
52 + supportsViewSource?: boolean,
53 |};
54
55 export type Capabilities = {|
@@ -124,6 +125,7 @@ export default class Store extends EventEmitter<{|
125 _supportsNativeInspection: boolean = false;
126 _supportsProfiling: boolean = false;
127 _supportsReloadAndProfile: boolean = false;
128 + _supportsViewSource: boolean = true;
129
130 // Total number of visible elements (within all roots).
131 // Used for windowing purposes.
@@ -155,6 +157,7 @@ export default class Store extends EventEmitter<{|
157 supportsNativeInspection,
158 supportsProfiling,
159 supportsReloadAndProfile,
160 + supportsViewSource,
161 } = config;
162 if (supportsCaptureScreenshots) {
163 this._supportsCaptureScreenshots = true;
@@ -162,6 +165,7 @@ export default class Store extends EventEmitter<{|
165 localStorageGetItem(LOCAL_STORAGE_CAPTURE_SCREENSHOTS_KEY) === 'true';
166 }
167 this._supportsNativeInspection = supportsNativeInspection !== false;
168 + this._supportsViewSource = supportsViewSource !== false;
169 if (supportsProfiling) {
170 this._supportsProfiling = true;
171 }
@@ -361,6 +365,10 @@ export default class Store extends EventEmitter<{|
365 return this._supportsReloadAndProfile && this._isBackendStorageAPISupported;
366 }
367
368 + get supportsViewSource(): boolean {
369 + return this._supportsViewSource;
370 + }
371 +
372 containsElement(id: number): boolean {
373 return this._idToElement.get(id) != null;
374 }
src/devtools/views/Components/Components.js
+2 -2
@@ -13,7 +13,7 @@ import { SettingsModalContextController } from 'src/devtools/views/Settings/Sett
13
14 import styles from './Components.css';
15
16 -function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) {
16 +function Components(_: {||}) {
17 // TODO Flex wrappers below should be user resizable.
18 return (
19 <SettingsModalContextController>
@@ -26,7 +26,7 @@ function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) {
26 <div className={styles.SelectedElementWrapper}>
27 <NativeStyleContextController>
28 <Suspense fallback={<Loading />}>
29 - <SelectedElement isBrowserMode={isBrowserMode} />
29 + <SelectedElement />
30 </Suspense>
31 </NativeStyleContextController>
32 </div>
src/devtools/views/Components/SelectedElement.js
+13 -13
@@ -30,11 +30,9 @@ import type { GetInspectedElementPath } from './InspectedElementContext';
30 import type { Element, InspectedElement } from './types';
31 import type { ElementType } from 'src/types';
32
33 -export type Props = {|
34 - isBrowserMode?: boolean,
35 -|};
33 +export type Props = {||};
34
37 -export default function SelectedElement({ isBrowserMode }: Props) {
35 +export default function SelectedElement(_: Props) {
36 const { inspectedElementID } = useContext(TreeStateContext);
37 const dispatch = useContext(TreeDispatcherContext);
38 const { isFileLocationRequired, viewElementSourceFunction } = useContext(
@@ -188,7 +186,7 @@ export default function SelectedElement({ isBrowserMode }: Props) {
186 <ButtonIcon type="suspend" />
187 </Toggle>
188 )}
191 - {isBrowserMode && (
189 + {store.supportsNativeInspection && (
190 <Button
191 className={styles.IconButton}
192 onClick={highlightElement}
@@ -204,14 +202,16 @@ export default function SelectedElement({ isBrowserMode }: Props) {
202 >
203 <ButtonIcon type="log-data" />
204 </Button>
207 - <Button
208 - className={styles.IconButton}
209 - disabled={!canViewSource}
210 - onClick={viewSource}
211 - title="View source for this element"
212 - >
213 - <ButtonIcon type="view-source" />
214 - </Button>
205 + {store.supportsViewSource && (
206 + <Button
207 + className={styles.IconButton}
208 + disabled={!canViewSource}
209 + onClick={viewSource}
210 + title="View source for this element"
211 + >
212 + <ButtonIcon type="view-source" />
213 + </Button>
214 + )}
215 </div>
216
217 {inspectedElement === null && (
src/devtools/views/DevTools.js
+1 -6
@@ -37,7 +37,6 @@ export type Props = {|
37 bridge: FrontendBridge,
38 browserTheme?: BrowserTheme,
39 defaultTab?: TabID,
40 - isBrowserMode?: boolean,
40 showTabBar?: boolean,
41 store: Store,
42 warnIfLegacyBackendDetected?: boolean,
@@ -78,7 +77,6 @@ export default function DevTools({
77 browserTheme = 'light',
78 defaultTab = 'components',
79 componentsPortalContainer,
81 - isBrowserMode = true,
80 overrideTab,
81 profilerPortalContainer,
82 settingsPortalContainer,
@@ -135,10 +133,7 @@ export default function DevTools({
133 className={styles.TabContent}
134 hidden={tab !== 'components'}
135 >
138 - <Components
139 - isBrowserMode={isBrowserMode}
140 - portalContainer={componentsPortalContainer}
141 - />
136 + <Components portalContainer={componentsPortalContainer} />
137 </div>
138 <div
139 className={styles.TabContent}