## Description Rename `design-system` package to `@appsmith/ads` ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10319507327> > Commit: 65d9664dd75b750496458a6e1652e0da858e1fc6 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10319507327&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Fri, 09 Aug 2024 13:47:50 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import React, { useCallback } from "react";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { Tooltip, ToggleButton } from "@appsmith/ads";
|
|
|
|
import type { AppState } from "ee/reducers";
|
|
import { APP_MODE } from "entities/App";
|
|
|
|
import { getAppMode } from "ee/selectors/applicationSelectors";
|
|
import { setPreviewModeInitAction } from "actions/editorActions";
|
|
import { previewModeSelector } from "selectors/editorSelectors";
|
|
|
|
import { createMessage, EDITOR_HEADER } from "ee/constants/messages";
|
|
import { altText } from "../../utils/helpers";
|
|
|
|
function ToggleModeButton() {
|
|
const dispatch = useDispatch();
|
|
const isPreviewMode = useSelector(previewModeSelector);
|
|
const appMode = useSelector(getAppMode);
|
|
|
|
const mode = useSelector((state: AppState) => state.entities.app.mode);
|
|
const isViewMode = mode === APP_MODE.PUBLISHED;
|
|
|
|
const onClickPreviewModeButton = useCallback(() => {
|
|
dispatch(setPreviewModeInitAction(!isPreviewMode));
|
|
}, [dispatch, setPreviewModeInitAction, isPreviewMode]);
|
|
|
|
if (isViewMode) return null;
|
|
|
|
return (
|
|
<Tooltip
|
|
content={
|
|
<>
|
|
{createMessage(EDITOR_HEADER.previewTooltip.text)}
|
|
<span style={{ marginLeft: 20 }}>
|
|
{`${altText()} ${createMessage(
|
|
EDITOR_HEADER.previewTooltip.shortcut,
|
|
)}`}
|
|
</span>
|
|
</>
|
|
}
|
|
isDisabled={appMode !== APP_MODE.EDIT}
|
|
placement="bottom"
|
|
>
|
|
<ToggleButton
|
|
data-testid={`${isPreviewMode ? "preview" : "edit"}-mode`}
|
|
icon="play-line"
|
|
isSelected={isPreviewMode}
|
|
onClick={onClickPreviewModeButton}
|
|
size="md"
|
|
/>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
export default ToggleModeButton;
|