PromucFlow_constructor/app/client/src/ce/pages/Applications/EmbedSnippetTab.tsx
Ankita Kinger 0d1d9c6781
fix: Updating the to function in embed snippet tab component (#23831)
## Description

Updating the to function in embed snippet tab component

#### PR fixes following issue(s)
Fixes # (issue number)

#### Type of change
- Bug fix (non-breaking change which fixes an issue)

## Testing
>
#### How Has This Been Tested?
- [x] Manual
- [ ] Jest
- [x] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-05-29 16:48:36 +05:30

208 lines
5.7 KiB
TypeScript

import React from "react";
import { useSelector } from "react-redux";
import styled from "styled-components";
import { Switch, Icon, Tooltip, Link, Text } from "design-system";
import useUpdateEmbedSnippet from "pages/Applications/EmbedSnippet/useUpdateEmbedSnippet";
import EmbedCodeSnippet from "pages/Applications/EmbedSnippet/Snippet";
import {
createMessage,
IN_APP_EMBED_SETTING,
} from "@appsmith/constants/messages";
import { getCurrentApplication } from "selectors/editorSelectors";
import PrivateEmbeddingContent from "pages/Applications/EmbedSnippet/PrivateEmbeddingContent";
import PropertyHelpLabel from "pages/Editor/PropertyPane/PropertyHelpLabel";
import { ADMIN_SETTINGS_PATH } from "constants/routes";
import _ from "lodash";
export const StyledPropertyHelpLabel = styled(PropertyHelpLabel)`
.bp3-popover-content > div {
text-align: center;
max-height: 44px;
display: flex;
align-items: center;
}
`;
export const BottomWrapper = styled.div`
border-top: 1px solid var(--ads-v2-color-border);
`;
export const EmbedWrapper = styled.div`
svg {
path {
fill: var(--ads-v2-color-fg-muted);
}
&:hover {
path {
fill: var(--ads-v2-color-fg);
}
}
}
`;
export function EmbedSnippetTab({
changeTab,
isAppSettings,
}: {
changeTab?: () => void;
isAppSettings?: boolean;
}) {
const currentApplicationDetails = useSelector(getCurrentApplication);
const isPublicApp = currentApplicationDetails?.isPublic || false;
if (!isPublicApp) {
return (
<PrivateEmbeddingContent
changeTab={changeTab}
isAppSettings={isAppSettings}
userAppPermissions={currentApplicationDetails?.userPermissions ?? []}
/>
);
}
if (isAppSettings) return <AppSettings />;
return <ShareModal />;
}
// get only the part of the url after the domain name
export const to = (url: string) => {
const path = _.drop(
url
.toString()
.replace(/([a-z])?:\/\//, "$1")
.split("/"),
).join("/");
return `/${path}`;
};
function ShareModal() {
const embedSnippet = useUpdateEmbedSnippet();
return (
<div className="flex flex-col gap-6">
{embedSnippet.isSuperUser && (
<div className="flex justify-between">
<div className="flex gap-1" data-testid="frame-ancestors-setting">
<Icon
className="icon"
name={embedSnippet.embedSettingContent.icon}
size="md"
/>
<Text>{embedSnippet.embedSettingContent.label}</Text>
<Tooltip
content={embedSnippet.embedSettingContent.tooltip}
placement="top"
>
<Icon
className="ml-1 cursor-pointer"
name="question-line"
size="md"
/>
</Tooltip>
</div>
<Link
data-testid="t--change-embedding-restriction"
target="_self"
to={ADMIN_SETTINGS_PATH}
>
{createMessage(IN_APP_EMBED_SETTING.change)}
</Link>
</div>
)}
<Switch
data-testid={"show-navigation-bar-toggle"}
defaultSelected={embedSnippet.currentEmbedSetting?.showNavigationBar}
onChange={() =>
embedSnippet.onChange({
showNavigationBar:
!embedSnippet.currentEmbedSetting.showNavigationBar,
})
}
>
{createMessage(IN_APP_EMBED_SETTING.showNavigationBar)}
</Switch>
<EmbedCodeSnippet
isAppSettings={false}
snippet={embedSnippet.appViewEndPoint}
/>
<BottomWrapper className={`flex justify-end pt-5`}>
<Link
className="flex gap-1 items-center self-end"
data-testid="preview-embed"
endIcon="share-box-line"
target={"_blank"}
to={to(embedSnippet.appViewEndPoint)}
>
{createMessage(IN_APP_EMBED_SETTING.previewEmbeddedApp)}
</Link>
</BottomWrapper>
</div>
);
}
function AppSettings() {
const embedSnippet = useUpdateEmbedSnippet();
return (
<EmbedWrapper className="px-4">
<Text className="pt-3 pb-3" kind="heading-xs" renderAs="p">
{createMessage(IN_APP_EMBED_SETTING.embed)}
</Text>
<div className="flex flex-col gap-6">
{embedSnippet.isSuperUser && (
<div className="flex justify-between">
<div className="flex gap-1" data-testid="frame-ancestors-setting">
<Icon
className="icon"
name={embedSnippet.embedSettingContent.icon}
size="md"
/>
<StyledPropertyHelpLabel
label={embedSnippet.embedSettingContent.label}
lineHeight="1.17"
maxWidth="217px"
tooltip={embedSnippet.embedSettingContent.tooltip}
/>
</div>
<Link
data-testid="t--change-embedding-restriction"
endIcon="pencil-line"
target="_self"
to={ADMIN_SETTINGS_PATH}
>
{""}
</Link>
</div>
)}
<Switch
data-testid={"show-navigation-bar-toggle"}
defaultSelected={embedSnippet.currentEmbedSetting?.showNavigationBar}
onChange={() =>
embedSnippet.onChange({
showNavigationBar:
!embedSnippet.currentEmbedSetting.showNavigationBar,
})
}
>
{createMessage(IN_APP_EMBED_SETTING.showNavigationBar)}
</Switch>
<EmbedCodeSnippet
isAppSettings
snippet={embedSnippet.appViewEndPoint}
/>
</div>
</EmbedWrapper>
);
}
export default EmbedSnippetTab;