PromucFlow_constructor/app/client/src/pages/common/PageHeader.tsx
Valera Melnikov 42debc6d11
chore: rename ADS package (#35583)
## 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
2024-08-09 17:20:29 +03:00

136 lines
4.4 KiB
TypeScript

import React, { useEffect } from "react";
import { useRouteMatch } from "react-router-dom";
import { connect, useDispatch, useSelector } from "react-redux";
import { getCurrentUser } from "selectors/usersSelectors";
import styled from "styled-components";
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
import type { AppState } from "ee/reducers";
import type { User } from "constants/userConstants";
import { useIsMobileDevice } from "utils/hooks/useDeviceDetect";
import { getTemplateNotificationSeenAction } from "actions/templateActions";
import { shouldShowLicenseBanner } from "ee/selectors/tenantSelectors";
import { Banner } from "ee/utils/licenseHelpers";
import bootIntercom from "utils/bootIntercom";
import EntitySearchBar from "pages/common/SearchBar/EntitySearchBar";
import { Switch, Tooltip } from "@appsmith/ads";
import { getIsAnvilLayoutEnabled } from "layoutSystems/anvil/integrations/selectors";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { setFeatureFlagOverrideValues } from "utils/storage";
import { updateFeatureFlagOverrideAction } from "actions/featureFlagActions";
const StyledPageHeader = styled(StyledHeader)<{
hideShadow?: boolean;
isMobile?: boolean;
showSeparator?: boolean;
isBannerVisible?: boolean;
}>`
justify-content: space-between;
background: var(--ads-v2-color-bg);
height: 48px;
color: var(--ads-v2-color-bg);
position: fixed;
top: 0;
z-index: var(--ads-v2-z-index-9);
border-bottom: 1px solid var(--ads-v2-color-border);
${({ isMobile }) =>
isMobile &&
`
padding: 0 12px;
padding-left: 10px;
`};
${({ isBannerVisible, isMobile }) =>
isBannerVisible ? (isMobile ? `top: 70px;` : `top: 40px;`) : ""};
/* intentionally "hacky" approach to show the Anvil toggle in the header. This will be removed once all features work well with Anvil */
& .ads-v2-switch {
display: block;
width: 100%;
position: absolute;
left: 175px;
top: 12px;
width: 30px;
& > label {
min-width: 0;
flex-direction: row-reverse;
}
}
`;
interface PageHeaderProps {
user?: User;
hideShadow?: boolean;
showSeparator?: boolean;
hideEditProfileLink?: boolean;
}
export function PageHeader(props: PageHeaderProps) {
const { user } = props;
const dispatch = useDispatch();
const isMobile = useIsMobileDevice();
useEffect(() => {
dispatch(getTemplateNotificationSeenAction());
}, []);
useEffect(() => {
bootIntercom(user);
}, [user?.email]);
const showBanner = useSelector(shouldShowLicenseBanner);
const isHomePage = useRouteMatch("/applications")?.isExact;
const isLicensePage = useRouteMatch("/license")?.isExact;
const isAnvilEnabled = useSelector(getIsAnvilLayoutEnabled);
const shouldShowAnvilToggle = useFeatureFlag(
FEATURE_FLAG.release_anvil_toggle_enabled,
);
/*
If Anvil toggle is enabled, the switch allows us to enable or disable Anvil
We pass the anvil feature's value via the toggle. We also passthrough the original
anvil toggle feature flag value as-is.
*/
function handleAnvilToggle(isSelected: boolean) {
const featureFlags = {
release_anvil_enabled: isSelected,
release_anvil_toggle_enabled: shouldShowAnvilToggle,
};
dispatch(updateFeatureFlagOverrideAction(featureFlags));
setFeatureFlagOverrideValues(featureFlags);
}
return (
<>
<Banner />
<StyledPageHeader
data-testid="t--appsmith-page-header"
hideShadow={props.hideShadow || false}
isBannerVisible={showBanner && (isHomePage || isLicensePage)}
isMobile={isMobile}
showSeparator={props.showSeparator || false}
>
{
// Based on a feature flag, show the switch that enables/disables Anvil
shouldShowAnvilToggle && (
<Switch isSelected={isAnvilEnabled} onChange={handleAnvilToggle}>
<Tooltip content="Toggles Anvil Layout System" trigger="hover">
<b>&alpha;</b>
</Tooltip>
</Switch>
)
}
<EntitySearchBar user={user} />
</StyledPageHeader>
</>
);
}
const mapStateToProps = (state: AppState) => ({
user: getCurrentUser(state),
hideShadow: state.ui.theme.hideHeaderShadow,
showSeparator: state.ui.theme.showHeaderSeparator,
});
export default connect(mapStateToProps)(PageHeader);