Skip to content

Minimize rerendering #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
minimize /permission requests
  • Loading branch information
raheeliftikhar5 committed Sep 2, 2024
commit 031ac84a246985b7cdcc2d96306be5c7bce2bcad
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SHARE_TITLE } from "../../constants/apiConstants";
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
import { default as Divider } from "antd/es/divider";

export const AppPermissionDialog = (props: {
export const AppPermissionDialog = React.memo((props: {
applicationId: string;
visible: boolean;
onVisibleChange: (visible: boolean) => void;
Expand Down Expand Up @@ -148,7 +148,7 @@ export const AppPermissionDialog = (props: {
}
/>
);
};
});

const InviteInputBtn = styled.div`
display: flex;
Expand Down
125 changes: 66 additions & 59 deletions client/packages/lowcoder/src/pages/common/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "lowcoder-design";
import { trans } from "i18n";
import dayjs from "dayjs";
import { useContext, useState } from "react";
import { useContext, useEffect, useMemo, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import {
publishApplication,
Expand Down Expand Up @@ -453,67 +453,74 @@ export default function Header(props: HeaderProps) {
</>
);

const headerEnd = showAppSnapshot ? (
<HeaderProfile user={user} />
) : (
<>
{applicationId && (
<AppPermissionDialog
applicationId={applicationId}
visible={permissionDialogVisible}
onVisibleChange={(visible) =>
!visible && setPermissionDialogVisible(false)
}
/>
)}
{canManageApp(user, application) && (
<GrayBtn onClick={() => setPermissionDialogVisible(true)}>
{SHARE_TITLE}
</GrayBtn>
)}
<PreviewBtn buttonType="primary" onClick={() => preview(applicationId)}>
{trans("header.preview")}
</PreviewBtn>

<Dropdown
className="cypress-header-dropdown"
placement="bottomRight"
trigger={["click"]}
dropdownRender={() => (
<DropdownMenuStyled
style={{ minWidth: "110px", borderRadius: "4px" }}
onClick={(e) => {
if (e.key === "deploy") {
dispatch(publishApplication({ applicationId }));
} else if (e.key === "snapshot") {
dispatch(setShowAppSnapshot(true));
}
}}
items={[
{
key: "deploy",
label: (
<CommonTextLabel>{trans("header.deploy")}</CommonTextLabel>
),
},
{
key: "snapshot",
label: (
<CommonTextLabel>{trans("header.snapshot")}</CommonTextLabel>
),
},
]}
const headerEnd = useMemo(() => {
return showAppSnapshot ? (
<HeaderProfile user={user} />
) : (
<>
{applicationId && (
<AppPermissionDialog
applicationId={applicationId}
visible={permissionDialogVisible}
onVisibleChange={(visible) =>
!visible && setPermissionDialogVisible(false)
}
/>
)}
>
<PackUpBtn buttonType="primary">
<PackUpIcon />
</PackUpBtn>
</Dropdown>
{canManageApp(user, application) && (
<GrayBtn onClick={() => setPermissionDialogVisible(true)}>
{SHARE_TITLE}
</GrayBtn>
)}
<PreviewBtn buttonType="primary" onClick={() => preview(applicationId)}>
{trans("header.preview")}
</PreviewBtn>

<Dropdown
className="cypress-header-dropdown"
placement="bottomRight"
trigger={["click"]}
dropdownRender={() => (
<DropdownMenuStyled
style={{ minWidth: "110px", borderRadius: "4px" }}
onClick={(e) => {
if (e.key === "deploy") {
dispatch(publishApplication({ applicationId }));
} else if (e.key === "snapshot") {
dispatch(setShowAppSnapshot(true));
}
}}
items={[
{
key: "deploy",
label: (
<CommonTextLabel>{trans("header.deploy")}</CommonTextLabel>
),
},
{
key: "snapshot",
label: (
<CommonTextLabel>{trans("header.snapshot")}</CommonTextLabel>
),
},
]}
/>
)}
>
<PackUpBtn buttonType="primary">
<PackUpIcon />
</PackUpBtn>
</Dropdown>

<HeaderProfile user={user} />
</>
);
<HeaderProfile user={user} />
</>
);
}, [
user,
showAppSnapshot,
applicationId,
permissionDialogVisible,
]);

return (
<LayoutHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export default function EditorSkeletonView() {
return (
<>
<Height100Div>
<Header
{/* <Header
panelStatus={panelStatus}
togglePanel={_.noop}
editorModeStatus={editorModeStatus}
toggleEditorModeStatus={_.noop}
/>
/> */}
<Body>
<SiderStyled />
{panelStatus.left && (
Expand Down