-
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 7f311a1
Showing
11 changed files
with
165 additions
and
11 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,23 @@ | ||
interface DLL { | ||
(moduleId: "tYg3"): { | ||
developHelper: { | ||
getAllContextValues(options: { | ||
tplContextId?: string; | ||
}): Map<string, { value: unknown }>; | ||
}; | ||
}; | ||
} | ||
|
||
export function getContext( | ||
tplContextId?: string | ||
): Record<string, unknown> | null { | ||
const { dll } = (window as unknown) as { dll?: DLL }; | ||
if (typeof dll === "function") { | ||
return Object.fromEntries( | ||
[...dll("tYg3").developHelper.getAllContextValues({ tplContextId })] | ||
.map(([key, { value }]) => [key, value]) | ||
.sort(([k1], [k2]) => (k1 > k2 ? 1 : -1)) | ||
); | ||
} | ||
return null; | ||
} |
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,59 @@ | ||
import React from "react"; | ||
import { InspectContextSelector } from "./InspectContextSelector"; | ||
import { PanelSelector } from "./PanelSelector"; | ||
import { HOOK_NAME } 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]); | ||
|
||
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} /> | ||
) : ( | ||
<p className="error-message">Inspect context failed</p> | ||
)} | ||
</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
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