PromucFlow_constructor/app/client/src/pages/workspace/settings.tsx

232 lines
6.2 KiB
TypeScript
Raw Normal View History

import React, { useCallback, useEffect, useState } from "react";
import {
useRouteMatch,
useLocation,
useParams,
Route,
useHistory,
} from "react-router-dom";
import { getCurrentWorkspace } from "@appsmith/selectors/workspaceSelectors";
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";
import styled from "styled-components";
import MemberSettings from "@appsmith/pages/workspace/Members";
import { GeneralSettings } from "./General";
import * as Sentry from "@sentry/react";
import { getAllApplications } from "actions/applicationActions";
import { useMediaQuery } from "react-responsive";
import { BackButton, StickyHeader } from "components/utils/helperComponents";
import { debounce } from "lodash";
import FormDialogComponent from "components/editorComponents/form/FormDialogComponent";
import WorkspaceInviteUsersForm from "@appsmith/pages/workspace/WorkspaceInviteUsersForm";
import { SettingsPageHeader } from "./SettingsPageHeader";
import { navigateToTab } from "@appsmith/pages/workspace/helpers";
import {
isPermitted,
PERMISSION_TYPE,
} from "@appsmith/utils/permissionHelpers";
import {
createMessage,
INVITE_USERS_PLACEHOLDER,
fix: Adding a fix for copy clipboard URL not working on HTTP domain (#21313) ## Description > Adding a fix for copy clipboard URL not working on HTTP domain. > Adding Javascript origin and redirect URLs on the google auth settings page for better UX. > Removing the upgrade button on the Appsmith watermark setting. > Updating the placeholder for search input on members page. Fixes #20574 #21170 ## Type of change - Bug fix (non-breaking change which fixes an issue) - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? > Tested all the above points manually and it all works fine. - Manual ## 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: - [ ] 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
2023-03-14 06:11:52 +00:00
SEARCH_USERS,
} from "@appsmith/constants/messages";
import { getAppsmithConfigs } from "@appsmith/configs";
const { cloudHosting } = getAppsmithConfigs();
const SentryRoute = Sentry.withSentryRouting(Route);
const SettingsWrapper = styled.div<{
isMobile?: boolean;
}>`
width: ${(props) => (props.isMobile ? "345px" : "916px")};
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
margin: 0 auto;
height: 100%;
&::-webkit-scrollbar {
width: 0px;
}
.tabs-wrapper {
height: 100%;
${({ isMobile }) =>
!isMobile &&
`
padding: 104px 0 0;
`}
}
`;
const StyledStickyHeader = styled(StickyHeader)<{ isMobile?: boolean }>`
padding-top: 24px;
${({ 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);
}
Homepage redesign with themes (#482) * Updating homepage body color * WIP: Fixing scrolls and adding anchors * Removing divider from bottom of the page. * Adding hover background color to app card * Changing edit and launch icons. * Fixing app name paddding in card. * Fixing workspaces overflow * Adding right padding to applications view * Adding share icon to share btn * Fixing Application card styles. * Fixing text decoration in button. * Adding new workspace button * Fixing new workspace and new app styles. * Adding icon sizes. * Fixing Org Name and Org settings menu. * Application menu working * Fixing overlay visibility on app card * Fixing settings page content width. * Fixing workspace icon * Changing app card colors. * Removing debugger * Adding app icon. * Fixing the spaces in application card * Adding storybook-static folder to gitignore. * Adding other storybook files. * Adding menu items for app * Removing cypress selector from text. * Menu width issue fixed * Default app icon color added * Removing hardcoded colors * Removing hardcoded colors. * Light Mode on! * Showing correct icon and color in menu * Update color working properly. * Updating appIcon * Editable text working. * Adding validator * Adding edit permissions to menu * Removing box shadow on app card. * Fixing context menu fill color * Fixing Menu hover issues. * Fixing menu open close hover issues. * Fixing settings pages * Changed Workspace to org. * Fix: State management in EditableText Component (#540) * Error state height is fixed as per design * savingState prop condition fixed * Fixing createnew. * Fixing saving state for application card. * Fixed application card editable text error. * Fixing issue caused during merge. * Fixing tests in create org. * Removing commented code. * Removing unwanted vars. * Fixing delete duplicate tests. * Latest color palette. * Fixing form and table widget. * Removing switcher from header * Removing unused files * Fixing app card context dropdown * Show overlay fix * Adding localStorage support to theme. * Making dark mode the default. Co-authored-by: Rohit Kumawat <rohit.kumawat@primathon.in>
2020-09-16 11:50:47 +00:00
`;
enum TABS {
GENERAL = "general",
MEMBERS = "members",
}
export default function Settings() {
const { workspaceId } = useParams<{ workspaceId: string }>();
const currentWorkspace = useSelector(getCurrentWorkspace).filter(
(el) => el.id === workspaceId,
)[0];
const { path } = useRouteMatch();
const location = useLocation();
const dispatch = useDispatch();
const [showModal, setShowModal] = useState(false);
const [searchValue, setSearchValue] = useState("");
const [pageTitle, setPageTitle] = useState<string>("");
const history = useHistory();
const currentTab = location.pathname.split("/").pop();
const onButtonClick = () => {
setShowModal(true);
};
useEffect(() => {
if (currentWorkspace) {
setPageTitle(`${currentWorkspace?.name}`);
}
}, [currentWorkspace]);
useEffect(() => {
if (!currentWorkspace) {
dispatch(getAllApplications());
}
}, [dispatch, currentWorkspace]);
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`}
/>
);
const onSearch = debounce((search: string) => {
if (search.trim().length > 0) {
setSearchValue(search);
} else {
setSearchValue("");
}
}, 300);
const isMemberofTheWorkspace = isPermitted(
currentWorkspace?.userPermissions || [],
PERMISSION_TYPE.INVITE_USER_TO_WORKSPACE,
);
const tabArr: TabProp[] = [
isMemberofTheWorkspace && {
key: "members",
title: "Members",
panelComponent: MemberSettingsComponent,
// icon: "gear",
// iconSize: IconSize.XL,
},
{
key: "general",
title: "General Settings",
panelComponent: GeneralSettingsComponent,
// icon: "user-2",
// iconSize: IconSize.XL,
},
].filter(Boolean) as TabProp[];
const pageMenuItems: MenuItemProps[] = [
{
icon: "book-line",
className: "documentation-page-menu-item",
onSelect: () => {
/*console.log("hello onSelect")*/
},
text: "Documentation",
},
];
const isMembersPage = tabArr.length > 1 && currentTab === TABS.MEMBERS;
const isGeneralPage = tabArr.length === 1 && currentTab === TABS.GENERAL;
const isMobile: boolean = useMediaQuery({ maxWidth: 767 });
return (
<>
<SettingsWrapper data-testid="t--settings-wrapper" isMobile={isMobile}>
<StyledStickyHeader isMobile={isMobile}>
<BackButton goTo="/applications" />
<SettingsPageHeader
buttonText="Add users"
onButtonClick={onButtonClick}
onSearch={onSearch}
pageMenuItems={pageMenuItems}
fix: Adding a fix for copy clipboard URL not working on HTTP domain (#21313) ## Description > Adding a fix for copy clipboard URL not working on HTTP domain. > Adding Javascript origin and redirect URLs on the google auth settings page for better UX. > Removing the upgrade button on the Appsmith watermark setting. > Updating the placeholder for search input on members page. Fixes #20574 #21170 ## Type of change - Bug fix (non-breaking change which fixes an issue) - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? > Tested all the above points manually and it all works fine. - Manual ## 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: - [ ] 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
2023-03-14 06:11:52 +00:00
searchPlaceholder={createMessage(SEARCH_USERS, cloudHosting)}
showMoreOptions={false}
showSearchNButton={isMembersPage}
title={pageTitle}
/>
</StyledStickyHeader>
<TabsWrapper
className="tabs-wrapper"
data-testid="t--user-edit-tabs-wrapper"
>
<TabComponent
onSelect={(index: number) =>
navigateToTab(tabArr[index].key, location, history)
}
selectedIndex={isMembersPage ? 0 : isGeneralPage ? 0 : 1}
tabs={tabArr}
/>
</TabsWrapper>
</SettingsWrapper>
<FormDialogComponent
Form={WorkspaceInviteUsersForm}
canOutsideClickClose
isOpen={showModal}
onClose={() => setShowModal(false)}
placeholder={createMessage(INVITE_USERS_PLACEHOLDER, cloudHosting)}
title={`Invite Users to ${currentWorkspace?.name}`}
trigger
workspaceId={workspaceId}
/>
</>
);
}