Skip to content

Commit

Permalink
Merge pull request #89 from easyops-cn/steve/refresh-brick-info
Browse files Browse the repository at this point in the history
fix: refresh brick info
  • Loading branch information
weareoutman committed Oct 10, 2023
2 parents ff5c436 + fda903d commit b33e0aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/panel/components/PropView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function PropView(): React.ReactElement {
<PropList
list={brickInfo[key]}
overrideProps={overrideProps}
editable={key !== "events"}
editable={key !== "events" && key !== "tplState"}
/>
</div>
</React.Fragment>
Expand Down
19 changes: 16 additions & 3 deletions src/panel/components/SelectedBrickToolbar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { useSelectedBrickContext } from "../libs/SelectedBrickContext";

jest.mock("../libs/SelectedBrickContext");

(useSelectedBrickContext as jest.Mock).mockReturnValue({ selectedBrick: null });
const setSelectedBrick = jest.fn();
(useSelectedBrickContext as jest.Mock).mockReturnValue({
selectedBrick: null,
setSelectedBrick,
});

const mockEval = jest.fn();

Expand All @@ -33,20 +37,29 @@ describe("SelectedBrickToolbar", () => {
uid: 1,
tagName: "your.awesome-brick",
};
(useSelectedBrickContext as jest.Mock).mockReturnValue({ selectedBrick });
(useSelectedBrickContext as jest.Mock).mockReturnValue({
selectedBrick,
setSelectedBrick,
});

const wrapper = shallow(<SelectedBrickToolbar />);

expect(wrapper.find(".brick-title").text()).toBe("your.awesome-brick");

wrapper.find(Button).at(0).invoke("onClick")(null);
expect(setSelectedBrick).toBeCalledWith({
uid: 1,
tagName: "your.awesome-brick",
});

wrapper.find(Button).at(1).invoke("onClick")(null);
expect(mockEval).toHaveBeenNthCalledWith(
1,
"inspect(window.__BRICK_NEXT_DEVTOOLS_HOOK__.getBrickByUid(1));",
{}
);

wrapper.find(Button).at(1).invoke("onClick")(null);
wrapper.find(Button).at(2).invoke("onClick")(null);
expect(mockEval).toHaveBeenNthCalledWith(
2,
"inspect(window.__BRICK_NEXT_DEVTOOLS_HOOK__.getBrickByUid(1).constructor);",
Expand Down
9 changes: 8 additions & 1 deletion src/panel/components/SelectedBrickToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSelectedBrickContext } from "../libs/SelectedBrickContext";
import { useEvalOptions } from "../libs/useEvalOptions";

export function SelectedBrickToolbar(): React.ReactElement {
const { selectedBrick } = useSelectedBrickContext();
const { selectedBrick, setSelectedBrick } = useSelectedBrickContext();
const evalOptions = useEvalOptions();

const handleInspectElement = React.useCallback((): void => {
Expand All @@ -23,6 +23,10 @@ export function SelectedBrickToolbar(): React.ReactElement {
);
}, [evalOptions, selectedBrick]);

const handleRefreshBrickInfo = React.useCallback(() => {
setSelectedBrick({ ...selectedBrick });
}, [selectedBrick, setSelectedBrick]);

return (
<div className="selected-brick-toolbar">
{selectedBrick && (
Expand All @@ -36,6 +40,9 @@ export function SelectedBrickToolbar(): React.ReactElement {
{selectedBrick.tagName}
</span>
<ButtonGroup>
<Tooltip content="Refresh brick info" hoverOpenDelay={300}>
<Button icon="refresh" minimal onClick={handleRefreshBrickInfo} />
</Tooltip>
<Tooltip content="Inspect the brick element" hoverOpenDelay={300}>
<Button icon="eye-open" minimal onClick={handleInspectElement} />
</Tooltip>
Expand Down

0 comments on commit b33e0aa

Please sign in to comment.