-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inspect page context and template state
- Loading branch information
1 parent
bc5c287
commit 23cc256
Showing
11 changed files
with
198 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
interface Window { | ||
/** A map of versions of core packages. */ | ||
BRICK_NEXT_VERSIONS?: Record<string, string>; | ||
|
||
/** Declare supported features currently. */ | ||
BRICK_NEXT_FEATURES?: string[]; | ||
|
||
/** For brick next devtools only */ | ||
__dev_only_getAllContextValues(options: { | ||
tplStateStoreId?: string; | ||
}): Record<string, unknown>; | ||
|
||
/** V2 DLL */ | ||
dll?: DLL; | ||
} | ||
|
||
interface DLL { | ||
(moduleId: "tYg3"): { | ||
developHelper: { | ||
getAllContextValues(options: { | ||
tplContextId?: string; | ||
}): Map<string, { value: unknown }>; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from "react"; | ||
import { shallow } from "enzyme"; | ||
import { ContextPanel } from "./ContextPanel"; | ||
|
||
describe("ContextPanel", () => { | ||
it("should work", () => { | ||
const wrapper = shallow(<ContextPanel />); | ||
expect(wrapper.hasClass("context-panel")).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from "react"; | ||
import { InspectContextSelector } from "./InspectContextSelector"; | ||
import { PanelSelector } from "./PanelSelector"; | ||
import { HOOK_NAME, MESSAGE_SOURCE_HOOK } from "../../shared/constants"; | ||
import { useEvalOptions } from "../libs/useEvalOptions"; | ||
import { PropList } from "./PropList"; | ||
import { Button, ButtonGroup, Tooltip } from "@blueprintjs/core"; | ||
|
||
export function ContextPanel(): React.ReactElement { | ||
const [values, setValues] = React.useState<Record<string, unknown> | null>( | ||
{} | ||
); | ||
const evalOptions = useEvalOptions(); | ||
|
||
const handleRefresh = React.useCallback(() => { | ||
chrome.devtools.inspectedWindow.eval( | ||
`window.${HOOK_NAME} && window.${HOOK_NAME}.getContext()`, | ||
evalOptions, | ||
function (result: Record<string, unknown>, error) { | ||
// istanbul ignore if | ||
if (error) { | ||
console.error("getContext()", error); | ||
setValues(null); | ||
} else { | ||
setValues(result); | ||
} | ||
} | ||
); | ||
}, [evalOptions]); | ||
|
||
React.useEffect(() => { | ||
handleRefresh(); | ||
}, [handleRefresh]); | ||
|
||
React.useEffect(() => { | ||
function onMessage(event: MessageEvent): void { | ||
if ( | ||
event.data?.source === MESSAGE_SOURCE_HOOK && | ||
event.data.payload?.type === "rendered" | ||
) { | ||
handleRefresh(); | ||
} | ||
} | ||
window.addEventListener("message", onMessage); | ||
return (): void => window.removeEventListener("message", onMessage); | ||
}, [handleRefresh]); | ||
|
||
return ( | ||
<div className="panel context-panel"> | ||
<div className="context-toolbar"> | ||
<div className="toolbar-group"> | ||
<InspectContextSelector /> | ||
<PanelSelector /> | ||
<ButtonGroup> | ||
<Tooltip content="Refresh context" hoverOpenDelay={300}> | ||
<Button icon="refresh" minimal onClick={handleRefresh} /> | ||
</Tooltip> | ||
</ButtonGroup> | ||
</div> | ||
</div> | ||
<div className="context-view source-code"> | ||
<div className="scroll-container"> | ||
{values && <PropList list={values} />} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.