Skip to content

Commit

Permalink
πŸ“¦ [RUMF-1162] update developer-extension (#1379)
Browse files Browse the repository at this point in the history
* πŸ“¦ [RUMF-1162] replace bumbag with mantine

* πŸ“¦ [RUMF-1162] update react

* 🚨 [RUMF-1162] work around strict null check

* 🏷️  [RUMF-1162] update @types

* 🚨 fix lint
  • Loading branch information
BenoitZugmeyer authored Mar 8, 2022
1 parent 50f3844 commit 275f807
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 419 deletions.
3 changes: 0 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ updates:
# update jasmine: RUMF-1161
- dependency-name: '*jasmine*'
- dependency-name: '*sinon*'
# update extension: RUMF-1162
- dependency-name: '*react*'
- dependency-name: 'bumbag'
# update ajv: RUMF-1164
- dependency-name: 'ajv'
update-types: ['version-update:semver-major']
Expand Down
3 changes: 2 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ file,pako,MIT,(C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
file,rrweb,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors) and SmartX Inc.
file,rrweb-snapshot,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb-snapshot/graphs/contributors) and SmartX Inc.
file,tracekit,MIT,Copyright 2013 Onur Can Cakmak and all TraceKit contributors
prod,bumbag,MIT,Copyright (c) 2020 Bumbag Enterprises
prod,@mantine/core,MIT,Copyright (c) 2021 Vitaly Rtishchev
prod,@mantine/hooks,MIT,Copyright (c) 2021 Vitaly Rtishchev
prod,react,MIT,Copyright (c) Facebook, Inc. and its affiliates.
prod,react-dom,MIT,Copyright (c) Facebook, Inc. and its affiliates.
dev,@jsdevtools/coverage-istanbul-loader,MIT,Copyright (c) 2015 James Messinger
Expand Down
11 changes: 6 additions & 5 deletions developer-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
},
"devDependencies": {
"@types/chrome": "0.0.179",
"@types/react": "16",
"@types/react-dom": "16",
"@types/react": "17.0.39",
"@types/react-dom": "17.0.13",
"copy-webpack-plugin": "8.1.0",
"html-webpack-plugin": "5.3.1",
"webpack": "5.28.0",
"webpack-webextension-plugin": "0.4.1"
},
"dependencies": {
"bumbag": "1.6.12",
"react": "16.14.0",
"react-dom": "16.14.0"
"@mantine/core": "3.6.14",
"@mantine/hooks": "3.6.14",
"react": "17.0.2",
"react-dom": "17.0.2"
}
}
2 changes: 1 addition & 1 deletion developer-extension/src/background/domain/flushEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { evaluateCodeInActiveTab } from '../utils'
listenAction('flushEvents', () =>
// Simulates a brief page visibility change (visible > hide > visible)
evaluateCodeInActiveTab(() => {
const descriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState')
const descriptor = Object.getOwnPropertyDescriptor(Document.prototype, 'visibilityState')!
Object.defineProperty(Document.prototype, 'visibilityState', { value: 'hidden' })
document.dispatchEvent(new Event('visibilitychange', { bubbles: true }))
Object.defineProperty(Document.prototype, 'visibilityState', descriptor)
Expand Down
4 changes: 3 additions & 1 deletion developer-extension/src/background/domain/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ listenAction('getConfig', (type) => {
})

listenAction('configReceived', ({ type, config }, tabId) => {
setLocalStore(type === 'rum' ? { rumConfig: config } : { logsConfig: config }, tabId)
if (tabId) {
setLocalStore(type === 'rum' ? { rumConfig: config } : { logsConfig: config }, tabId)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ chrome.webRequest.onBeforeRequest.addListener(
if (!intake) {
return
}
if (!info.requestBody.raw) {
if (!info.requestBody!.raw) {
return
}

for (const rawBody of info.requestBody.raw) {
for (const rawBody of info.requestBody!.raw) {
if (rawBody.bytes) {
const decodedBody = decoder.decode(rawBody.bytes)
for (const rawEvent of decodedBody.split('\n')) {
Expand Down
9 changes: 6 additions & 3 deletions developer-extension/src/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ type Message<Actions extends { [key: string]: any }> = ValueOf<{
}>

export function createListenAction<Actions>() {
function listenAction<K extends keyof Actions>(action: K, callback: (payload: Actions[K], tabId: number) => void) {
function listenAction<K extends keyof Actions>(
action: K,
callback: (payload: Actions[K], tabId: number | undefined) => void
) {
const listener = (message: Message<Actions>, sender: chrome.runtime.MessageSender) => {
if (message.action === action) {
callback((message as Message<Pick<Actions, K>>).payload, sender?.tab?.id)
callback((message as Message<Pick<Actions, K>>).payload, sender.tab?.id)
}
}
chrome.runtime.onMessage.addListener(listener)
Expand All @@ -32,7 +35,7 @@ export function createSendAction<Actions>() {
error.message !== 'Could not establish connection. Receiving end does not exist.' &&
error.message !== 'The message port closed before a response was received.'
) {
console.error(`sendAction error: ${error.message}`)
console.error(`sendAction error: ${String(error.message)}`)
}
})
}
Expand Down
33 changes: 12 additions & 21 deletions developer-extension/src/panel/app.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
import { Provider as BumbagProvider, Box, css } from 'bumbag'
import { MantineProvider } from '@mantine/core'
import { useColorScheme } from '@mantine/hooks'
import React, { Suspense } from 'react'

import { Panel } from './panel'

const theme = {
global: {
fontSize: 14,
styles: {
base: css`
body {
min-height: 100vh;
}
`,
},
},
modes: {
enableLocalStorage: false,
useSystemColorMode: true,
},
}

export function App() {
const colorScheme = useColorScheme()

return (
<BumbagProvider theme={theme}>
<Suspense fallback={<Box padding="major-4" />}>
<MantineProvider
theme={{
colorScheme,
}}
withGlobalStyles
>
<Suspense fallback={<></>}>
<Panel />
</Suspense>
</BumbagProvider>
</MantineProvider>
)
}
31 changes: 17 additions & 14 deletions developer-extension/src/panel/panel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Tabs } from 'bumbag'
import React from 'react'
import { Tabs } from '@mantine/core'
import React, { useState } from 'react'
import { ActionsTab } from './tabs/actionsTab'
import { ConfigTab } from './tabs/configTab'
import { sendAction } from './actions'

const enum PanelTabs {
Actions,
RumConfig,
LogsConfig,
}

export function Panel() {
setInterval(() => {
sendAction('getConfig', 'rum')
Expand All @@ -14,22 +20,19 @@ export function Panel() {
sendAction('getConfig', 'rum')
sendAction('getConfig', 'logs')
})
const [activeTab, setActiveTab] = useState(PanelTabs.Actions)

return (
<Tabs>
<Tabs.List>
<Tabs.Tab tabId="tab1">Actions</Tabs.Tab>
<Tabs.Tab tabId="tab2">RUM Config</Tabs.Tab>
<Tabs.Tab tabId="tab3">Logs Config</Tabs.Tab>
</Tabs.List>
<Tabs.Panel tabId="tab1" padding="major-2">
<Tabs active={activeTab} onTabChange={setActiveTab}>
<Tabs.Tab label="Actions">
<ActionsTab />
</Tabs.Panel>
<Tabs.Panel tabId="tab2" padding="major-2">
</Tabs.Tab>
<Tabs.Tab label="RUM Config">
<ConfigTab product={'rum'} />
</Tabs.Panel>
<Tabs.Panel tabId="tab3" padding="major-2">
</Tabs.Tab>
<Tabs.Tab label="Logs Config">
<ConfigTab product={'logs'} />
</Tabs.Panel>
</Tabs.Tab>
</Tabs>
)
}
20 changes: 12 additions & 8 deletions developer-extension/src/panel/tabs/actionsTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, Checkbox, Badge, Button } from 'bumbag'
import { Group, Checkbox, Badge, Button } from '@mantine/core'
import React from 'react'
import { sendAction } from '../actions'
import { useStore } from '../useStore'
Expand All @@ -7,17 +7,21 @@ export function ActionsTab() {
const [{ useDevBundles, useRumSlim, logEventsFromRequests, devServerStatus, blockIntakeRequests }, setStore] =
useStore()
return (
<Stack alignY="top" padding="major-2" spacing="major-2">
<Stack orientation="horizontal" verticalBelow="0" spacing="major-2" alignX="left" alignY="center">
<Group direction="column" spacing="md" align="flex-start">
<Group spacing="md" align="center">
<Checkbox
label="Use dev bundles"
checked={useDevBundles}
onChange={(e) => setStore({ useDevBundles: isChecked(e.target) })}
/>
<Badge
palette={devServerStatus === 'available' ? 'success' : devServerStatus === 'checking' ? 'warning' : 'danger'}
/>
</Stack>
{devServerStatus === 'available' ? (
<Badge color="green">Available</Badge>
) : devServerStatus === 'checking' ? (
<Badge color="yellow">Checking...</Badge>
) : (
<Badge color="red">Unavailable</Badge>
)}
</Group>

<Checkbox
label="Use RUM Slim"
Expand All @@ -40,7 +44,7 @@ export function ActionsTab() {
<Button onClick={() => sendAction('flushEvents', undefined)}>Flush buffered events</Button>

<Button onClick={() => sendAction('endSession', undefined)}>End current session</Button>
</Stack>
</Group>
)
}

Expand Down
28 changes: 14 additions & 14 deletions developer-extension/src/panel/tabs/configTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Table } from 'bumbag'
import { Table } from '@mantine/core'
import React from 'react'
import { useStore } from '../useStore'

Expand All @@ -7,21 +7,21 @@ export function ConfigTab(props: { product: string }) {
const currentTabStore = local[chrome.devtools.inspectedWindow.tabId]
const config = props.product === 'rum' ? currentTabStore?.rumConfig : currentTabStore?.logsConfig
return config ? (
<Table isStriped>
<Table.Head>
<Table.Row>
<Table.HeadCell>Attribute</Table.HeadCell>
<Table.HeadCell>Value</Table.HeadCell>
</Table.Row>
</Table.Head>
<Table.Body>
<Table striped>
<thead>
<tr>
<th>Attribute</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{Object.entries(config).map(([attribute, value]) => (
<Table.Row key={attribute}>
<Table.Cell>{attribute}</Table.Cell>
<Table.Cell>{JSON.stringify(value)}</Table.Cell>
</Table.Row>
<tr key={attribute}>
<td>{attribute}</td>
<td>{JSON.stringify(value)}</td>
</tr>
))}
</Table.Body>
</tbody>
</Table>
) : null
}
2 changes: 1 addition & 1 deletion developer-extension/src/panel/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const storeLoadingPromise = new Promise((resolve) => {
sendAction('getStore', undefined)
listenAction('newStore', (newStore) => {
store = newStore
storeListeners.forEach((listener) => listener(store))
storeListeners.forEach((listener) => listener(store!))
resolve(undefined)
})
})
Expand Down
5 changes: 1 addition & 4 deletions developer-extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"module": "ES6",
"jsx": "react",
"lib": ["ES2019", "DOM"],
"types": ["chrome", "react", "react-dom"],

// See https://github.com/bumbag/bumbag-ui/issues/97
"strictNullChecks": false
"types": ["chrome", "react", "react-dom"]
}
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
"webpack-dev-middleware": "4.1.0"
},
"resolutions": {
"**/bumbag/lodash": "4.17.21",
"**/bumbag/reakit": "1.3.11",
"ansi-regex": "5.0.1"
}
}
Loading

0 comments on commit 275f807

Please sign in to comment.