2022-08-22 17:57:07 +00:00
|
|
|
import React, { useCallback, useEffect, useState } from "react";
|
2020-09-24 16:05:18 +00:00
|
|
|
import {
|
|
|
|
|
useRouteMatch,
|
|
|
|
|
useLocation,
|
|
|
|
|
useParams,
|
|
|
|
|
Route,
|
2022-08-22 17:57:07 +00:00
|
|
|
useHistory,
|
2020-09-24 16:05:18 +00:00
|
|
|
} from "react-router-dom";
|
2022-06-15 15:37:41 +00:00
|
|
|
import { getCurrentWorkspace } from "@appsmith/selectors/workspaceSelectors";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { useSelector, useDispatch } from "react-redux";
|
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 { MenuItemProps, TabProp } from "design-system-old";
|
|
|
|
|
import { TabComponent } from "design-system-old";
|
2020-06-17 10:19:56 +00:00
|
|
|
import styled from "styled-components";
|
2020-07-08 10:14:03 +00:00
|
|
|
|
2022-11-03 16:39:51 +00:00
|
|
|
import MemberSettings from "@appsmith/pages/workspace/Members";
|
2020-08-28 18:51:16 +00:00
|
|
|
import { GeneralSettings } from "./General";
|
2020-09-24 16:05:18 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2023-03-29 17:07:06 +00:00
|
|
|
import { getAllApplications } from "@appsmith/actions/applicationActions";
|
2021-10-04 15:34:37 +00:00
|
|
|
import { useMediaQuery } from "react-responsive";
|
2022-08-27 14:27:10 +00:00
|
|
|
import { BackButton, StickyHeader } from "components/utils/helperComponents";
|
2022-08-22 17:57:07 +00:00
|
|
|
import { debounce } from "lodash";
|
|
|
|
|
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
|
2022-09-02 17:15:08 +00:00
|
|
|
import WorkspaceInviteUsersForm from "@appsmith/pages/workspace/WorkspaceInviteUsersForm";
|
2022-08-22 17:57:07 +00:00
|
|
|
import { SettingsPageHeader } from "./SettingsPageHeader";
|
2022-09-02 17:15:08 +00:00
|
|
|
import { navigateToTab } from "@appsmith/pages/workspace/helpers";
|
2022-12-07 05:37:59 +00:00
|
|
|
import {
|
|
|
|
|
isPermitted,
|
|
|
|
|
PERMISSION_TYPE,
|
|
|
|
|
} from "@appsmith/utils/permissionHelpers";
|
2022-12-20 06:49:57 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
INVITE_USERS_PLACEHOLDER,
|
2023-03-14 06:11:52 +00:00
|
|
|
SEARCH_USERS,
|
2022-12-20 06:49:57 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2022-12-23 04:31:46 +00:00
|
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
2023-03-31 11:37:09 +00:00
|
|
|
import { APPLICATIONS_URL } from "constants/routes";
|
2022-12-23 04:31:46 +00:00
|
|
|
|
|
|
|
|
const { cloudHosting } = getAppsmithConfigs();
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2020-09-24 16:05:18 +00:00
|
|
|
const SentryRoute = Sentry.withSentryRouting(Route);
|
2020-06-17 10:19:56 +00:00
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const SettingsWrapper = styled.div<{
|
|
|
|
|
isMobile?: boolean;
|
|
|
|
|
}>`
|
|
|
|
|
width: ${(props) => (props.isMobile ? "345px" : "916px")};
|
2020-09-16 11:50:47 +00:00
|
|
|
margin: 0 auto;
|
2022-08-27 14:27:10 +00:00
|
|
|
height: 100%;
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
|
width: 0px;
|
|
|
|
|
}
|
|
|
|
|
.tabs-wrapper {
|
|
|
|
|
height: 100%;
|
|
|
|
|
${({ isMobile }) =>
|
|
|
|
|
!isMobile &&
|
|
|
|
|
`
|
|
|
|
|
padding: 104px 0 0;
|
|
|
|
|
`}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledStickyHeader = styled(StickyHeader)<{ isMobile?: boolean }>`
|
2022-08-22 17:57:07 +00:00
|
|
|
padding-top: 24px;
|
2022-08-27 14:27:10 +00:00
|
|
|
${({ isMobile }) =>
|
|
|
|
|
!isMobile &&
|
|
|
|
|
`
|
|
|
|
|
top: 48px;
|
|
|
|
|
position: fixed;
|
|
|
|
|
width: 916px;
|
|
|
|
|
`}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
export const TabsWrapper = styled.div`
|
|
|
|
|
.react-tabs {
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
}
|
|
|
|
|
.react-tabs__tab-list {
|
|
|
|
|
border-bottom: 1px solid var(--appsmith-color-black-200);
|
|
|
|
|
padding: 36px 0 0;
|
|
|
|
|
width: 908px;
|
|
|
|
|
}
|
|
|
|
|
.react-tabs__tab-panel {
|
|
|
|
|
height: calc(100% - 76px);
|
|
|
|
|
}
|
2020-09-16 11:50:47 +00:00
|
|
|
`;
|
2022-08-22 17:57:07 +00:00
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
enum TABS {
|
|
|
|
|
GENERAL = "general",
|
|
|
|
|
MEMBERS = "members",
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
export default function Settings() {
|
2022-06-15 15:37:41 +00:00
|
|
|
const { workspaceId } = useParams<{ workspaceId: string }>();
|
|
|
|
|
const currentWorkspace = useSelector(getCurrentWorkspace).filter(
|
|
|
|
|
(el) => el.id === workspaceId,
|
2020-11-25 12:24:14 +00:00
|
|
|
)[0];
|
2020-08-28 18:51:16 +00:00
|
|
|
const { path } = useRouteMatch();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const dispatch = useDispatch();
|
2022-08-22 17:57:07 +00:00
|
|
|
|
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
|
|
|
|
const [searchValue, setSearchValue] = useState("");
|
|
|
|
|
|
|
|
|
|
const [pageTitle, setPageTitle] = useState<string>("");
|
|
|
|
|
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const currentTab = location.pathname.split("/").pop();
|
|
|
|
|
|
2022-08-22 17:57:07 +00:00
|
|
|
const onButtonClick = () => {
|
|
|
|
|
setShowModal(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-03-31 11:37:09 +00:00
|
|
|
const hasManageWorkspacePermissions = isPermitted(
|
|
|
|
|
currentWorkspace?.userPermissions,
|
|
|
|
|
PERMISSION_TYPE.MANAGE_WORKSPACE,
|
|
|
|
|
);
|
|
|
|
|
const canInviteToWorkspace = isPermitted(
|
|
|
|
|
currentWorkspace?.userPermissions,
|
|
|
|
|
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
|
|
|
|
|
);
|
|
|
|
|
if (!hasManageWorkspacePermissions || !canInviteToWorkspace) {
|
|
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
}
|
2022-08-22 17:57:07 +00:00
|
|
|
if (currentWorkspace) {
|
2022-12-22 17:40:56 +00:00
|
|
|
setPageTitle(`${currentWorkspace?.name}`);
|
2022-08-22 17:57:07 +00:00
|
|
|
}
|
|
|
|
|
}, [currentWorkspace]);
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
useEffect(() => {
|
2022-06-15 15:37:41 +00:00
|
|
|
if (!currentWorkspace) {
|
2020-11-25 12:24:14 +00:00
|
|
|
dispatch(getAllApplications());
|
|
|
|
|
}
|
2022-06-15 15:37:41 +00:00
|
|
|
}, [dispatch, currentWorkspace]);
|
2020-08-28 18:51:16 +00:00
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const GeneralSettingsComponent = (
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={GeneralSettings}
|
|
|
|
|
location={location}
|
|
|
|
|
path={`${path}/general`}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const MemberSettingsComponent = (
|
|
|
|
|
<SentryRoute
|
|
|
|
|
component={useCallback(
|
|
|
|
|
(props: any) => (
|
|
|
|
|
<MemberSettings {...props} searchValue={searchValue} />
|
|
|
|
|
),
|
|
|
|
|
[location, searchValue],
|
|
|
|
|
)}
|
|
|
|
|
location={location}
|
|
|
|
|
path={`${path}/members`}
|
|
|
|
|
/>
|
2020-07-08 10:14:03 +00:00
|
|
|
);
|
|
|
|
|
|
2022-08-22 17:57:07 +00:00
|
|
|
const onSearch = debounce((search: string) => {
|
|
|
|
|
if (search.trim().length > 0) {
|
|
|
|
|
setSearchValue(search);
|
|
|
|
|
} else {
|
|
|
|
|
setSearchValue("");
|
|
|
|
|
}
|
|
|
|
|
}, 300);
|
|
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const isMemberofTheWorkspace = isPermitted(
|
|
|
|
|
currentWorkspace?.userPermissions || [],
|
|
|
|
|
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
|
|
|
|
|
);
|
|
|
|
|
|
2020-08-28 18:51:16 +00:00
|
|
|
const tabArr: TabProp[] = [
|
2022-12-07 05:37:59 +00:00
|
|
|
isMemberofTheWorkspace && {
|
2022-08-22 17:57:07 +00:00
|
|
|
key: "members",
|
|
|
|
|
title: "Members",
|
2022-12-07 05:37:59 +00:00
|
|
|
panelComponent: MemberSettingsComponent,
|
2022-08-22 17:57:07 +00:00
|
|
|
// icon: "gear",
|
|
|
|
|
// iconSize: IconSize.XL,
|
2020-06-17 10:19:56 +00:00
|
|
|
},
|
2020-06-25 18:48:07 +00:00
|
|
|
{
|
2022-08-22 17:57:07 +00:00
|
|
|
key: "general",
|
|
|
|
|
title: "General Settings",
|
2022-12-07 05:37:59 +00:00
|
|
|
panelComponent: GeneralSettingsComponent,
|
2022-08-22 17:57:07 +00:00
|
|
|
// icon: "user-2",
|
|
|
|
|
// iconSize: IconSize.XL,
|
2020-06-25 18:48:07 +00:00
|
|
|
},
|
2022-12-07 05:37:59 +00:00
|
|
|
].filter(Boolean) as TabProp[];
|
2022-08-22 17:57:07 +00:00
|
|
|
|
|
|
|
|
const pageMenuItems: MenuItemProps[] = [
|
|
|
|
|
{
|
|
|
|
|
icon: "book-line",
|
|
|
|
|
className: "documentation-page-menu-item",
|
|
|
|
|
onSelect: () => {
|
|
|
|
|
/*console.log("hello onSelect")*/
|
|
|
|
|
},
|
|
|
|
|
text: "Documentation",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2022-12-07 05:37:59 +00:00
|
|
|
const isMembersPage = tabArr.length > 1 && currentTab === TABS.MEMBERS;
|
|
|
|
|
const isGeneralPage = tabArr.length === 1 && currentTab === TABS.GENERAL;
|
|
|
|
|
|
2021-10-04 15:34:37 +00:00
|
|
|
const isMobile: boolean = useMediaQuery({ maxWidth: 767 });
|
2019-12-23 12:16:33 +00:00
|
|
|
return (
|
2022-08-22 17:57:07 +00:00
|
|
|
<>
|
|
|
|
|
<SettingsWrapper data-testid="t--settings-wrapper" isMobile={isMobile}>
|
2022-08-27 14:27:10 +00:00
|
|
|
<StyledStickyHeader isMobile={isMobile}>
|
|
|
|
|
<BackButton goTo="/applications" />
|
|
|
|
|
<SettingsPageHeader
|
|
|
|
|
buttonText="Add users"
|
|
|
|
|
onButtonClick={onButtonClick}
|
|
|
|
|
onSearch={onSearch}
|
|
|
|
|
pageMenuItems={pageMenuItems}
|
2023-03-14 06:11:52 +00:00
|
|
|
searchPlaceholder={createMessage(SEARCH_USERS, cloudHosting)}
|
2022-08-27 14:27:10 +00:00
|
|
|
showMoreOptions={false}
|
2022-12-22 17:40:56 +00:00
|
|
|
showSearchNButton={isMembersPage}
|
2022-08-27 14:27:10 +00:00
|
|
|
title={pageTitle}
|
|
|
|
|
/>
|
|
|
|
|
</StyledStickyHeader>
|
|
|
|
|
<TabsWrapper
|
|
|
|
|
className="tabs-wrapper"
|
|
|
|
|
data-testid="t--user-edit-tabs-wrapper"
|
|
|
|
|
>
|
2022-08-22 17:57:07 +00:00
|
|
|
<TabComponent
|
|
|
|
|
onSelect={(index: number) =>
|
|
|
|
|
navigateToTab(tabArr[index].key, location, history)
|
|
|
|
|
}
|
2022-12-07 05:37:59 +00:00
|
|
|
selectedIndex={isMembersPage ? 0 : isGeneralPage ? 0 : 1}
|
2022-08-22 17:57:07 +00:00
|
|
|
tabs={tabArr}
|
|
|
|
|
/>
|
|
|
|
|
</TabsWrapper>
|
|
|
|
|
</SettingsWrapper>
|
|
|
|
|
<FormDialogComponent
|
|
|
|
|
Form={WorkspaceInviteUsersForm}
|
|
|
|
|
canOutsideClickClose
|
|
|
|
|
isOpen={showModal}
|
|
|
|
|
onClose={() => setShowModal(false)}
|
2022-12-23 04:31:46 +00:00
|
|
|
placeholder={createMessage(INVITE_USERS_PLACEHOLDER, cloudHosting)}
|
2022-08-22 17:57:07 +00:00
|
|
|
title={`Invite Users to ${currentWorkspace?.name}`}
|
|
|
|
|
trigger
|
|
|
|
|
workspaceId={workspaceId}
|
2021-04-28 10:28:39 +00:00
|
|
|
/>
|
2022-08-22 17:57:07 +00:00
|
|
|
</>
|
2019-12-23 12:16:33 +00:00
|
|
|
);
|
2020-08-28 18:51:16 +00:00
|
|
|
}
|