Skip to content

Commit ede471a

Browse files
committed
feat(reactotron-app): Each client now has an explicit list of plugins.
Developers can now toggle interface features based on what plugins the user has installed and active within their ecosystem. Part of this was updating each library to have a `name` property. See example in the sidebar component for conditionally showing the Apollo sidebar button.
1 parent 4a81d87 commit ede471a

File tree

24 files changed

+84
-18
lines changed

24 files changed

+84
-18
lines changed

apps/reactotron-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"react-motion": "0.5.2",
6565
"react-router-dom": "^6.22.0",
6666
"react-tooltip": "4.5.1",
67+
"react-transition-group": "^4.4.5",
6768
"reactotron-core-contract": "workspace:*",
6869
"reactotron-core-server": "workspace:*",
6970
"reactotron-core-ui": "workspace:*",

apps/reactotron-app/src/renderer/components/SideBar/Sidebar.tsx

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import styled from "styled-components"
1515
import SideBarButton from "../SideBarButton"
1616
import { reactotronLogo } from "../../images"
1717
import { ServerStatus } from "../../contexts/Standalone/useStandalone"
18+
import {
19+
Transition,
20+
CSSTransition,
21+
SwitchTransition,
22+
TransitionGroup,
23+
} from "react-transition-group"
1824

1925
interface SideBarContainerProps {
2026
$isOpen: boolean
@@ -34,7 +40,20 @@ const Spacer = styled.div`
3440
flex: 1;
3541
`
3642

37-
function SideBar({ isOpen, serverStatus }: { isOpen: boolean; serverStatus: ServerStatus }) {
43+
const transitionStyles = {
44+
entering: { opacity: 0 },
45+
entered: { opacity: 1 },
46+
exiting: { opacity: 1 },
47+
exited: { opacity: 0 },
48+
}
49+
50+
interface SideBarProps {
51+
isOpen: boolean
52+
serverStatus: ServerStatus
53+
plugins: string[]
54+
}
55+
56+
function SideBar({ isOpen, serverStatus, plugins }: SideBarProps) {
3857
let serverIcon = MdMobiledataOff
3958
let iconColor
4059
let serverText = "Stopped"
@@ -55,6 +74,11 @@ function SideBar({ isOpen, serverStatus }: { isOpen: boolean; serverStatus: Serv
5574
}
5675
}
5776

77+
const hasApolloClient = React.useMemo(
78+
() => plugins.find((plugin) => plugin === "apollo-client"),
79+
[plugins]
80+
)
81+
5882
return (
5983
<SideBarContainer $isOpen={isOpen}>
6084
<SideBarButton image={reactotronLogo} path="/" text="Home" hideTopBar />
@@ -73,12 +97,24 @@ function SideBar({ isOpen, serverStatus }: { isOpen: boolean; serverStatus: Serv
7397
/>
7498
<SideBarButton icon={FaMagic} path="/customCommands" text="Custom Commands" iconSize={25} />
7599

76-
<SideBarButton
77-
icon={SiApollographql}
78-
path="/apolloClient/cache"
79-
matchPath="/apolloClient"
80-
text="Apollo Client"
81-
/>
100+
<Transition in={hasApolloClient} timeout={300}>
101+
{(state) => (
102+
<div
103+
style={{
104+
transition: `opacity 300ms ease-in-out`,
105+
opacity: 0,
106+
...transitionStyles[state],
107+
}}
108+
>
109+
<SideBarButton
110+
icon={SiApollographql}
111+
path="/apolloClient/queries"
112+
matchPath="/apolloClient"
113+
text="Apollo Client"
114+
/>
115+
</div>
116+
)}
117+
</Transition>
82118

83119
<Spacer />
84120

apps/reactotron-app/src/renderer/components/SideBar/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ import SidebarStateless from "./Sidebar"
66

77
function SideBar() {
88
const { isSideBarOpen } = useContext(LayoutContext)
9-
const { serverStatus } = useContext(StandaloneContext)
109

11-
return <SidebarStateless isOpen={isSideBarOpen} serverStatus={serverStatus} />
10+
const standaloneContext = useContext(StandaloneContext)
11+
const { serverStatus, selectedConnection } = standaloneContext
12+
13+
return (
14+
<SidebarStateless
15+
isOpen={isSideBarOpen}
16+
serverStatus={serverStatus}
17+
plugins={selectedConnection?.plugins || []}
18+
/>
19+
)
1220
}
1321

1422
export default SideBar

apps/reactotron-app/src/renderer/contexts/Standalone/useStandalone.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ReactotronConnection {
2626
platformVersion?: string
2727
osRelease?: string
2828
userAgent?: string
29+
plugins: string[]
2930
}
3031

3132
export interface Connection extends ReactotronConnection {

lib/reactotron-apollo-client/src/reactotron-apollo-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export const apolloPlugin =
304304
// --- Reactotron plugin interface ---------------------------------
305305

306306
return {
307+
name: "apollo-client",
307308
// Fires when we receive a command from the Reactotron app.
308309
onCommand,
309310

lib/reactotron-core-client/src/plugins/api-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ReactotronCore, Plugin } from "../reactotron-core-client"
55
*/
66
const apiResponse = () => (reactotron: ReactotronCore) => {
77
return {
8+
name: "api-response",
89
features: {
910
apiResponse: (request: { status: number }, response: any, duration: number) => {
1011
const ok =

lib/reactotron-core-client/src/plugins/benchmark.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const benchmark = () => (reactotron: ReactotronCore) => {
2323
}
2424

2525
return {
26+
name: "benchmark",
2627
features: { benchmark },
2728
} satisfies Plugin<ReactotronCore>
2829
}

lib/reactotron-core-client/src/plugins/clear.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ReactotronCore, Plugin } from "../reactotron-core-client"
55
*/
66
const clear = () => (reactotron: ReactotronCore) => {
77
return {
8+
name: "clear",
89
features: {
910
clear: () => reactotron.send("clear"),
1011
},

lib/reactotron-core-client/src/plugins/image.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ImagePayload {
1414
*/
1515
const image = () => (reactotron: ReactotronCore) => {
1616
return {
17+
name: "image",
1718
features: {
1819
// expanded just to show the specs
1920
image: (payload: ImagePayload) => {

lib/reactotron-core-client/src/plugins/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ReactotronCore, Plugin, InferFeatures } from "../reactotron-core-c
55
*/
66
const logger = () => (reactotron: ReactotronCore) => {
77
return {
8+
name: "logger",
89
features: {
910
log: (...args) => {
1011
const content = args && args.length === 1 ? args[0] : args

0 commit comments

Comments
 (0)