2022-03-03 10:56:53 +00:00
|
|
|
import React, { useState, useMemo, useEffect } from "react";
|
2020-08-03 14:18:48 +00:00
|
|
|
import { Link, useLocation } from "react-router-dom";
|
2022-04-07 17:57:32 +00:00
|
|
|
import { connect, useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { getCurrentUser, selectFeatureFlags } 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";
|
2022-03-03 10:56:53 +00:00
|
|
|
import Button 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 { Colors } from "constants/Colors";
|
|
|
|
|
import { useIsMobileDevice } from "utils/hooks/useDeviceDetect";
|
|
|
|
|
import { ReactComponent as TwoLineHamburger } from "assets/icons/ads/two-line-hamburger.svg";
|
|
|
|
|
import MobileSideBar from "./MobileSidebar";
|
|
|
|
|
import { Indices } from "constants/Layers";
|
2023-01-23 03:50:47 +00:00
|
|
|
import { Icon, IconSize } from "design-system-old";
|
2022-03-03 10:56:53 +00:00
|
|
|
import { getTemplateNotificationSeenAction } from "actions/templateActions";
|
2022-12-09 14:43:47 +00:00
|
|
|
import { getTenantConfig } from "@appsmith/selectors/tenantSelectors";
|
2023-02-28 10:13:23 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
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";
|
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;
|
2021-10-04 15:34:37 +00:00
|
|
|
}>`
|
2022-12-09 14:43:47 +00:00
|
|
|
box-shadow: none;
|
2022-03-03 10:56:53 +00:00
|
|
|
justify-content: normal;
|
2021-10-04 15:34:37 +00:00
|
|
|
background: white;
|
2020-08-18 06:40:11 +00:00
|
|
|
height: 48px;
|
|
|
|
|
color: white;
|
2020-09-16 11:50:47 +00:00
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
2022-02-17 16:38:36 +00:00
|
|
|
z-index: ${Indices.Layer9};
|
2022-12-09 14:43:47 +00:00
|
|
|
box-shadow: 0px 1px 0px ${Colors.GALLERY_2};
|
2022-02-17 16:38:36 +00:00
|
|
|
${({ isMobile }) =>
|
|
|
|
|
isMobile &&
|
|
|
|
|
`
|
|
|
|
|
padding: 0 12px;
|
|
|
|
|
padding-left: 10px;
|
2022-03-03 10:56:53 +00:00
|
|
|
`};
|
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
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const StyledDropDownContainer = styled.div``;
|
|
|
|
|
|
2022-02-17 16:38:36 +00:00
|
|
|
const StyledTwoLineHamburger = styled(TwoLineHamburger)`
|
|
|
|
|
fill: ${Colors.BLACK};
|
|
|
|
|
width: 22px;
|
|
|
|
|
height: 22px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
const Tabs = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
line-height: 24px;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
margin-left: ${(props) => props.theme.spaces[16]}px;
|
|
|
|
|
height: 100%;
|
|
|
|
|
gap: ${(props) => `${props.theme.spaces[0]}px ${props.theme.spaces[12]}px`};
|
|
|
|
|
flex: 1;
|
|
|
|
|
padding-top: ${(props) => props.theme.spaces[1]}px;
|
|
|
|
|
`;
|
|
|
|
|
const TabName = styled.div<{ isSelected: boolean }>`
|
|
|
|
|
color: ${Colors.GRAY};
|
|
|
|
|
border-bottom: 2px solid transparent;
|
|
|
|
|
text-align: center;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
${(props) =>
|
|
|
|
|
props.isSelected &&
|
2022-12-09 14:43:47 +00:00
|
|
|
`border-bottom: 2px solid var(--ads-color-brand);
|
2022-03-03 10:56:53 +00:00
|
|
|
color: ${Colors.COD_GRAY};`}
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
`;
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
type PageHeaderProps = {
|
|
|
|
|
user?: User;
|
2021-10-04 15:34:37 +00:00
|
|
|
hideShadow?: boolean;
|
|
|
|
|
showSeparator?: boolean;
|
2023-01-19 06:06:45 +00:00
|
|
|
hideEditProfileLink?: boolean;
|
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-04-07 17:57:32 +00:00
|
|
|
const featureFlags = useSelector(selectFeatureFlags);
|
|
|
|
|
|
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));
|
2022-04-07 17:57:32 +00:00
|
|
|
}, [featureFlags, location.pathname]);
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
2021-10-04 15:34:37 +00:00
|
|
|
<StyledPageHeader
|
2022-04-05 12:30:57 +00:00
|
|
|
data-testid="t--appsmith-page-header"
|
2021-10-04 15:34:37 +00:00
|
|
|
hideShadow={props.hideShadow || false}
|
2022-02-17 16:38:36 +00:00
|
|
|
isMobile={isMobile}
|
2021-10-04 15:34:37 +00:00
|
|
|
showSeparator={props.showSeparator || false}
|
2022-03-03 10:56:53 +00:00
|
|
|
showingTabs={showTabs}
|
2021-10-04 15:34:37 +00:00
|
|
|
>
|
2020-08-18 06:40:11 +00:00
|
|
|
<HeaderSection>
|
2022-12-09 14:43:47 +00:00
|
|
|
{tenantConfig.brandLogoUrl && (
|
|
|
|
|
<Link className="t--appsmith-logo" to={APPLICATIONS_URL}>
|
|
|
|
|
<img alt="Logo" className="h-6" src={tenantConfig.brandLogoUrl} />
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
2020-08-18 06:40:11 +00:00
|
|
|
</HeaderSection>
|
2022-03-03 10:56:53 +00:00
|
|
|
|
|
|
|
|
<Tabs>
|
|
|
|
|
{showTabs && !isMobile && (
|
|
|
|
|
<>
|
|
|
|
|
<TabName
|
2022-12-09 14:43:47 +00:00
|
|
|
className="t--apps-tab"
|
2022-03-03 10:56:53 +00:00
|
|
|
isSelected={matchApplicationPath(location.pathname)}
|
|
|
|
|
onClick={() => history.push(APPLICATIONS_URL)}
|
|
|
|
|
>
|
|
|
|
|
<div>Apps</div>
|
|
|
|
|
</TabName>
|
2022-09-30 13:41:04 +00:00
|
|
|
|
|
|
|
|
<TabName
|
|
|
|
|
className="t--templates-tab"
|
|
|
|
|
isSelected={
|
|
|
|
|
matchTemplatesPath(location.pathname) ||
|
|
|
|
|
matchTemplatesIdPath(location.pathname)
|
|
|
|
|
}
|
2023-02-28 10:13:23 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
AnalyticsUtil.logEvent("TEMPLATES_TAB_CLICK");
|
|
|
|
|
history.push(TEMPLATES_PATH);
|
|
|
|
|
}}
|
2022-09-30 13:41:04 +00:00
|
|
|
>
|
|
|
|
|
<div>Templates</div>
|
|
|
|
|
</TabName>
|
2022-03-03 10:56:53 +00:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Tabs>
|
|
|
|
|
|
2022-02-17 16:38:36 +00:00
|
|
|
{user && !isMobile && (
|
2022-08-03 07:02:49 +00:00
|
|
|
<StyledDropDownContainer>
|
|
|
|
|
{user.username === ANONYMOUS_USERNAME ? (
|
|
|
|
|
<Button
|
|
|
|
|
filled
|
|
|
|
|
intent={"primary"}
|
|
|
|
|
onClick={() => history.push(loginUrl)}
|
|
|
|
|
size="small"
|
|
|
|
|
text="Sign In"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<ProfileDropdown
|
2023-01-19 06:06:45 +00:00
|
|
|
hideEditProfileLink={props.hideEditProfileLink}
|
2022-08-03 07:02:49 +00:00
|
|
|
name={user.name}
|
2023-03-23 11:41:58 +00:00
|
|
|
navColorStyle={navColorStyle}
|
2022-08-03 07:02:49 +00:00
|
|
|
photoId={user?.photoId}
|
2023-03-23 11:41:58 +00:00
|
|
|
primaryColor={primaryColor}
|
2022-08-03 07:02:49 +00:00
|
|
|
userName={user.username}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</StyledDropDownContainer>
|
2020-08-03 14:18:48 +00:00
|
|
|
)}
|
2022-02-17 16:38:36 +00:00
|
|
|
{isMobile && !isMobileSidebarOpen && (
|
|
|
|
|
<StyledTwoLineHamburger onClick={() => setIsMobileSidebarOpen(true)} />
|
|
|
|
|
)}
|
|
|
|
|
{isMobile && isMobileSidebarOpen && (
|
|
|
|
|
<Icon
|
|
|
|
|
fillColor={Colors.CRUSTA}
|
|
|
|
|
name="close-x"
|
|
|
|
|
onClick={() => setIsMobileSidebarOpen(false)}
|
|
|
|
|
size={IconSize.XXXXL}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-02-21 11:15:11 +00:00
|
|
|
{isMobile && user && (
|
2022-02-17 16:38:36 +00:00
|
|
|
<MobileSideBar
|
|
|
|
|
isOpen={isMobileSidebarOpen}
|
2022-02-21 11:15:11 +00:00
|
|
|
name={user.name}
|
|
|
|
|
userName={user.username}
|
2022-02-17 16:38:36 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
2019-12-23 12:16:33 +00:00
|
|
|
</StyledPageHeader>
|
|
|
|
|
);
|
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);
|