2022-03-03 10:56:53 +00:00
|
|
|
import React, { useState, useMemo, useEffect } from "react";
|
2023-10-15 08:16:58 +00:00
|
|
|
import { Link, useLocation, useRouteMatch } from "react-router-dom";
|
2022-04-07 17:57:32 +00:00
|
|
|
import { connect, useDispatch, useSelector } from "react-redux";
|
2023-06-27 10:45:33 +00:00
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
2022-03-03 10:56:53 +00:00
|
|
|
import styled from "styled-components";
|
2019-12-23 12:16:33 +00:00
|
|
|
import StyledHeader from "components/designSystems/appsmith/StyledHeader";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] 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
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { AppState } from "@appsmith/reducers";
|
|
|
|
|
import type { User } from "constants/userConstants";
|
|
|
|
|
import { ANONYMOUS_USERNAME } from "constants/userConstants";
|
2022-03-03 10:56:53 +00:00
|
|
|
import {
|
|
|
|
|
AUTH_LOGIN_URL,
|
|
|
|
|
APPLICATIONS_URL,
|
|
|
|
|
matchApplicationPath,
|
|
|
|
|
matchTemplatesPath,
|
2022-03-25 10:43:26 +00:00
|
|
|
TEMPLATES_PATH,
|
2022-03-03 10:56:53 +00:00
|
|
|
TEMPLATES_ID_PATH,
|
|
|
|
|
matchTemplatesIdPath,
|
|
|
|
|
} from "constants/routes";
|
2020-08-03 14:18:48 +00:00
|
|
|
import history from "utils/history";
|
2023-05-19 18:37:06 +00:00
|
|
|
import EditorButton from "components/editorComponents/Button";
|
2020-09-22 11:56:11 +00:00
|
|
|
import ProfileDropdown from "./ProfileDropdown";
|
2022-02-17 16:38:36 +00:00
|
|
|
import { useIsMobileDevice } from "utils/hooks/useDeviceDetect";
|
|
|
|
|
import MobileSideBar from "./MobileSidebar";
|
2022-03-03 10:56:53 +00:00
|
|
|
import { getTemplateNotificationSeenAction } from "actions/templateActions";
|
2023-10-15 08:16:58 +00:00
|
|
|
import {
|
|
|
|
|
getTenantConfig,
|
|
|
|
|
shouldShowLicenseBanner,
|
|
|
|
|
} from "@appsmith/selectors/tenantSelectors";
|
2023-02-28 10:13:23 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { Button } from "design-system";
|
2023-03-23 11:41:58 +00:00
|
|
|
import { getSelectedAppTheme } from "selectors/appThemingSelectors";
|
|
|
|
|
import { getCurrentApplication } from "selectors/editorSelectors";
|
|
|
|
|
import { get } from "lodash";
|
|
|
|
|
import { NAVIGATION_SETTINGS } from "constants/AppConstants";
|
2023-04-10 07:02:31 +00:00
|
|
|
import { getAssetUrl, isAirgapped } from "@appsmith/utils/airgapHelpers";
|
2023-10-15 08:16:58 +00:00
|
|
|
import { Banner } from "@appsmith/utils/licenseHelpers";
|
2021-06-09 14:32:17 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const StyledPageHeader = styled(StyledHeader)<{
|
|
|
|
|
hideShadow?: boolean;
|
2022-02-17 16:38:36 +00:00
|
|
|
isMobile?: boolean;
|
2021-10-04 15:34:37 +00:00
|
|
|
showSeparator?: boolean;
|
2022-03-03 10:56:53 +00:00
|
|
|
showingTabs: boolean;
|
2023-10-15 08:16:58 +00:00
|
|
|
isBannerVisible?: boolean;
|
2021-10-04 15:34:37 +00:00
|
|
|
}>`
|
2022-03-03 10:56:53 +00:00
|
|
|
justify-content: normal;
|
2023-05-19 18:37:06 +00:00
|
|
|
background: var(--ads-v2-color-bg);
|
2020-08-18 06:40:11 +00:00
|
|
|
height: 48px;
|
2023-05-19 18:37:06 +00:00
|
|
|
color: var(--ads-v2-color-bg);
|
2020-09-16 11:50:47 +00:00
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
2023-05-19 18:37:06 +00:00
|
|
|
z-index: var(--ads-v2-z-index-9);
|
|
|
|
|
border-bottom: 1px solid var(--ads-v2-color-border);
|
2022-02-17 16:38:36 +00:00
|
|
|
${({ isMobile }) =>
|
|
|
|
|
isMobile &&
|
|
|
|
|
`
|
|
|
|
|
padding: 0 12px;
|
|
|
|
|
padding-left: 10px;
|
2022-03-03 10:56:53 +00:00
|
|
|
`};
|
2023-10-15 08:16:58 +00:00
|
|
|
${({ isBannerVisible }) => isBannerVisible && `top: 40px;`};
|
2020-08-18 06:40:11 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const HeaderSection = styled.div`
|
2020-06-17 10:19:56 +00:00
|
|
|
display: flex;
|
2020-08-18 06:40:11 +00:00
|
|
|
align-items: center;
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
.t--appsmith-logo {
|
|
|
|
|
svg {
|
|
|
|
|
max-width: 110px;
|
|
|
|
|
width: 110px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
const Tabs = styled.div`
|
|
|
|
|
display: flex;
|
2023-05-19 18:37:06 +00:00
|
|
|
font-size: 14px;
|
|
|
|
|
line-height: 16px;
|
2022-03-03 10:56:53 +00:00
|
|
|
box-sizing: border-box;
|
|
|
|
|
margin-left: ${(props) => props.theme.spaces[16]}px;
|
|
|
|
|
height: 100%;
|
|
|
|
|
flex: 1;
|
|
|
|
|
`;
|
2023-05-19 18:37:06 +00:00
|
|
|
const TabsList = styled.div`
|
2022-03-03 10:56:53 +00:00
|
|
|
display: flex;
|
2023-05-19 18:37:06 +00:00
|
|
|
display: flex;
|
|
|
|
|
gap: var(--ads-v2-spaces-4);
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: var(--ads-v2-spaces-1) var(--ads-v2-spaces-1) 0
|
|
|
|
|
var(--ads-v2-spaces-1);
|
|
|
|
|
`;
|
|
|
|
|
const Tab = styled.div<{ isSelected: boolean }>`
|
|
|
|
|
--tab-color: ${(props) =>
|
|
|
|
|
props.isSelected
|
|
|
|
|
? "var(--ads-v2-color-fg)"
|
|
|
|
|
: "var(--ads-v2-color-fg-muted)"};
|
|
|
|
|
--tab-selection-color: transparent;
|
|
|
|
|
appearance: none;
|
|
|
|
|
position: relative;
|
2022-03-03 10:56:53 +00:00
|
|
|
cursor: pointer;
|
2023-05-19 18:37:06 +00:00
|
|
|
padding: var(--ads-v2-spaces-2);
|
|
|
|
|
padding-bottom: var(--ads-v2-spaces-3);
|
|
|
|
|
background-color: var(--ads-v2-color-bg);
|
|
|
|
|
border: none; // get rid of button styles
|
|
|
|
|
color: var(--tab-color);
|
|
|
|
|
min-width: fit-content;
|
|
|
|
|
border-radius: var(--ads-v2-border-radius);
|
|
|
|
|
margin-bottom: 2px;
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
|
content: "";
|
|
|
|
|
height: 2px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: -2px;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
background-color: ${(props) =>
|
|
|
|
|
props.isSelected
|
|
|
|
|
? `var(--ads-v2-color-border-brand)`
|
|
|
|
|
: `var(--tab-selection-color)`};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--ads-v2-spaces-3);
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
--tab-selection-color: var(--ads-v2-color-border-emphasis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&:focus-visible {
|
|
|
|
|
--tab-color: var(--ads-v2-color-fg);
|
|
|
|
|
outline: var(--ads-v2-border-width-outline) solid
|
|
|
|
|
var(--ads-v2-color-outline);
|
|
|
|
|
outline-offset: var(--ads-v2-offset-outline);
|
|
|
|
|
}
|
2022-03-03 10:56:53 +00:00
|
|
|
`;
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface PageHeaderProps {
|
2019-12-23 12:16:33 +00:00
|
|
|
user?: User;
|
2021-10-04 15:34:37 +00:00
|
|
|
hideShadow?: boolean;
|
|
|
|
|
showSeparator?: boolean;
|
2023-01-19 06:06:45 +00:00
|
|
|
hideEditProfileLink?: boolean;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function PageHeader(props: PageHeaderProps) {
|
2020-08-03 14:18:48 +00:00
|
|
|
const { user } = props;
|
|
|
|
|
const location = useLocation();
|
2022-03-03 10:56:53 +00:00
|
|
|
const dispatch = useDispatch();
|
2020-08-03 14:18:48 +00:00
|
|
|
const queryParams = new URLSearchParams(location.search);
|
2022-02-17 16:38:36 +00:00
|
|
|
const isMobile = useIsMobileDevice();
|
|
|
|
|
const [isMobileSidebarOpen, setIsMobileSidebarOpen] = useState(false);
|
2022-12-09 14:43:47 +00:00
|
|
|
const tenantConfig = useSelector(getTenantConfig);
|
2020-08-03 14:18:48 +00:00
|
|
|
let loginUrl = AUTH_LOGIN_URL;
|
2021-01-06 11:24:16 +00:00
|
|
|
if (queryParams.has("redirectUrl")) {
|
2021-03-04 09:37:02 +00:00
|
|
|
loginUrl += `?redirectUrl
|
|
|
|
|
=${queryParams.get("redirectUrl")}`;
|
2020-08-03 14:18:48 +00:00
|
|
|
}
|
2023-03-23 11:41:58 +00:00
|
|
|
const selectedTheme = useSelector(getSelectedAppTheme);
|
|
|
|
|
const currentApplicationDetails = useSelector(getCurrentApplication);
|
|
|
|
|
const navColorStyle =
|
|
|
|
|
currentApplicationDetails?.applicationDetail?.navigationSetting
|
|
|
|
|
?.colorStyle || NAVIGATION_SETTINGS.COLOR_STYLE.LIGHT;
|
|
|
|
|
const primaryColor = get(
|
|
|
|
|
selectedTheme,
|
|
|
|
|
"properties.colors.primaryColor",
|
|
|
|
|
"inherit",
|
|
|
|
|
);
|
2020-07-08 10:14:03 +00:00
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(getTemplateNotificationSeenAction());
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const tabs = [
|
|
|
|
|
{
|
|
|
|
|
title: "Apps",
|
|
|
|
|
path: APPLICATIONS_URL,
|
|
|
|
|
matcher: matchApplicationPath,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "Templates",
|
2022-03-25 10:43:26 +00:00
|
|
|
path: TEMPLATES_PATH,
|
2022-03-03 10:56:53 +00:00
|
|
|
matcher: matchTemplatesPath,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "Templates id",
|
|
|
|
|
path: TEMPLATES_ID_PATH,
|
|
|
|
|
matcher: matchTemplatesIdPath,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const showTabs = useMemo(() => {
|
2022-04-15 09:28:27 +00:00
|
|
|
return tabs.some((tab) => tab.matcher(location.pathname));
|
2023-06-27 10:45:33 +00:00
|
|
|
}, [location.pathname]);
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2023-04-10 07:02:31 +00:00
|
|
|
const isAirgappedInstance = isAirgapped();
|
2023-10-15 08:16:58 +00:00
|
|
|
const showBanner = useSelector(shouldShowLicenseBanner);
|
|
|
|
|
const isHomePage = useRouteMatch("/applications")?.isExact;
|
|
|
|
|
const isLicensePage = useRouteMatch("/license")?.isExact;
|
2023-04-10 07:02:31 +00:00
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
2023-10-15 08:16:58 +00:00
|
|
|
<>
|
|
|
|
|
<Banner />
|
|
|
|
|
<StyledPageHeader
|
|
|
|
|
data-testid="t--appsmith-page-header"
|
|
|
|
|
hideShadow={props.hideShadow || false}
|
|
|
|
|
isBannerVisible={showBanner && (isHomePage || isLicensePage)}
|
|
|
|
|
isMobile={isMobile}
|
|
|
|
|
showSeparator={props.showSeparator || false}
|
|
|
|
|
showingTabs={showTabs}
|
|
|
|
|
>
|
|
|
|
|
<HeaderSection>
|
|
|
|
|
{tenantConfig.brandLogoUrl && (
|
|
|
|
|
<Link className="t--appsmith-logo" to={APPLICATIONS_URL}>
|
|
|
|
|
<img
|
|
|
|
|
alt="Logo"
|
|
|
|
|
className="h-6"
|
|
|
|
|
src={getAssetUrl(tenantConfig.brandLogoUrl)}
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
</HeaderSection>
|
|
|
|
|
<Tabs>
|
|
|
|
|
{showTabs && !isMobile && (
|
|
|
|
|
<TabsList>
|
2023-05-19 18:37:06 +00:00
|
|
|
<Tab
|
2023-10-15 08:16:58 +00:00
|
|
|
className="t--apps-tab"
|
|
|
|
|
isSelected={matchApplicationPath(location.pathname)}
|
|
|
|
|
onClick={() => history.push(APPLICATIONS_URL)}
|
2023-04-10 07:02:31 +00:00
|
|
|
>
|
2023-10-15 08:16:58 +00:00
|
|
|
<div>Apps</div>
|
2023-05-19 18:37:06 +00:00
|
|
|
</Tab>
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2023-10-15 08:16:58 +00:00
|
|
|
{!isAirgappedInstance && (
|
|
|
|
|
<Tab
|
|
|
|
|
className="t--templates-tab"
|
|
|
|
|
isSelected={
|
|
|
|
|
matchTemplatesPath(location.pathname) ||
|
|
|
|
|
matchTemplatesIdPath(location.pathname)
|
|
|
|
|
}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
AnalyticsUtil.logEvent("TEMPLATES_TAB_CLICK");
|
|
|
|
|
history.push(TEMPLATES_PATH);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div>Templates</div>
|
|
|
|
|
</Tab>
|
|
|
|
|
)}
|
|
|
|
|
</TabsList>
|
2022-08-03 07:02:49 +00:00
|
|
|
)}
|
2023-10-15 08:16:58 +00:00
|
|
|
</Tabs>
|
|
|
|
|
|
|
|
|
|
{user && !isMobile && (
|
|
|
|
|
<div>
|
|
|
|
|
{user.username === ANONYMOUS_USERNAME ? (
|
|
|
|
|
<EditorButton
|
|
|
|
|
filled
|
|
|
|
|
intent={"primary"}
|
|
|
|
|
onClick={() => history.push(loginUrl)}
|
|
|
|
|
size="small"
|
|
|
|
|
text="Sign In"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<ProfileDropdown
|
|
|
|
|
hideEditProfileLink={props.hideEditProfileLink}
|
|
|
|
|
name={user.name}
|
|
|
|
|
navColorStyle={navColorStyle}
|
|
|
|
|
photoId={user?.photoId}
|
|
|
|
|
primaryColor={primaryColor}
|
|
|
|
|
userName={user.username}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{isMobile && !isMobileSidebarOpen && (
|
|
|
|
|
<Button
|
|
|
|
|
isIconButton
|
|
|
|
|
kind="tertiary"
|
|
|
|
|
onClick={() => setIsMobileSidebarOpen(true)}
|
|
|
|
|
size={"md"}
|
|
|
|
|
startIcon="hamburger"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{isMobile && isMobileSidebarOpen && (
|
|
|
|
|
<Button
|
|
|
|
|
isIconButton
|
|
|
|
|
kind="tertiary"
|
|
|
|
|
onClick={() => setIsMobileSidebarOpen(false)}
|
|
|
|
|
size="sm"
|
|
|
|
|
startIcon="close-x"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{isMobile && user && (
|
|
|
|
|
<MobileSideBar
|
|
|
|
|
isOpen={isMobileSidebarOpen}
|
|
|
|
|
name={user.name}
|
|
|
|
|
userName={user.username}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</StyledPageHeader>
|
|
|
|
|
</>
|
2019-12-23 12:16:33 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
const mapStateToProps = (state: AppState) => ({
|
|
|
|
|
user: getCurrentUser(state),
|
2021-10-04 15:34:37 +00:00
|
|
|
hideShadow: state.ui.theme.hideHeaderShadow,
|
|
|
|
|
showSeparator: state.ui.theme.showHeaderSeparator,
|
2019-12-23 12:16:33 +00:00
|
|
|
});
|
|
|
|
|
|
2020-08-03 14:18:48 +00:00
|
|
|
export default connect(mapStateToProps)(PageHeader);
|