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

258 lines
6.7 KiB
TypeScript
Raw Normal View History

import React from "react";
import {
deleteWorkspaceLogo,
saveWorkspace,
uploadWorkspaceLogo,
} from "@appsmith/actions/workspaceActions";
import { SaveWorkspaceRequest } from "@appsmith/api/WorkspaceApi";
import { debounce } from "lodash";
feat: Renamed design system package (#19854) ## Description This PR includes changes for renaming design system package. Since we are building new package for the refactored design system components, the old package is renaming to design-system-old. Fixes #19536 ## Type of change - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## How Has This Been Tested? - Manual - Jest - Cypress ### 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 - [x] 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 - [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-01-23 03:50:47 +00:00
import {
TextInput,
emailValidator,
notEmptyValidator,
} from "design-system-old";
import { useSelector, useDispatch } from "react-redux";
import {
getCurrentError,
getCurrentWorkspace,
getWorkspaceLoadingStates,
} from "@appsmith/selectors/workspaceSelectors";
import { useParams } from "react-router-dom";
import styled from "styled-components";
import {
chore: migrate toast (#17208) * Refactor toast to be passed the dispatch hook externally * Add comments explaining dilemma * use store.dispatch instead of a hook * use alpha version * Change imports * Refactor DebugButton out * update release * fix issue with incorrectly merged package.lock * fix syntax of alpha version * bump ds vesion * copy lock from release * update lock to have alpha * make changes * delete Toast * DS package version updated * import change from release * use new alpha version * update ds version * update ds version * chore: migrate editable text and friends (#17285) * Delete empty components * use alpha for ds * Deleted EditableTextSubComponent, import changes * Delete EditableText, import changes * use ds alpha 10 * Delete EditableTextWrapper.tsx * update ds to use next minor version * use new alpha * fix issue with merge Co-authored-by: Albin <albin@appsmith.com> * chore: migrate file picker v2 (#17308) * use alpha ds * Delete FilePickerV2, import changes * Delete FilePicker, change imports * update alpha version * chore: move copy url form into setting components (#17322) * move CopyUrlForm to src/pages/settings/formgroup * update ds version to use next minor release * feat: Migrate table component to design system (#17329) * feat: Migrate table component to design system * removed commented code in ads index file * fix: table no data hover effect removed Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Banner message component migrated to design system (#17327) * feat: Banner image component migrated to design system * Version update for design system package * design system version updated Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Tabs component migrated to design system (#17321) * feat: Tabs component migrated to design system * design system package version updated * Update app/client/src/components/editorComponents/form/FormDialogComponent.tsx * Update app/client/src/pages/Editor/PropertyPane/PropertyPaneTab.tsx * Tab component expand issue fix Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Albin <albin@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
2022-10-13 20:13:44 +00:00
FilePickerV2,
FileType,
SetProgress,
chore: migrate toast (#17208) * Refactor toast to be passed the dispatch hook externally * Add comments explaining dilemma * use store.dispatch instead of a hook * use alpha version * Change imports * Refactor DebugButton out * update release * fix issue with incorrectly merged package.lock * fix syntax of alpha version * bump ds vesion * copy lock from release * update lock to have alpha * make changes * delete Toast * DS package version updated * import change from release * use new alpha version * update ds version * update ds version * chore: migrate editable text and friends (#17285) * Delete empty components * use alpha for ds * Deleted EditableTextSubComponent, import changes * Delete EditableText, import changes * use ds alpha 10 * Delete EditableTextWrapper.tsx * update ds to use next minor version * use new alpha * fix issue with merge Co-authored-by: Albin <albin@appsmith.com> * chore: migrate file picker v2 (#17308) * use alpha ds * Delete FilePickerV2, import changes * Delete FilePicker, change imports * update alpha version * chore: move copy url form into setting components (#17322) * move CopyUrlForm to src/pages/settings/formgroup * update ds version to use next minor release * feat: Migrate table component to design system (#17329) * feat: Migrate table component to design system * removed commented code in ads index file * fix: table no data hover effect removed Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Banner message component migrated to design system (#17327) * feat: Banner image component migrated to design system * Version update for design system package * design system version updated Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Tabs component migrated to design system (#17321) * feat: Tabs component migrated to design system * design system package version updated * Update app/client/src/components/editorComponents/form/FormDialogComponent.tsx * Update app/client/src/pages/Editor/PropertyPane/PropertyPaneTab.tsx * Tab component expand issue fix Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Albin <albin@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
2022-10-13 20:13:44 +00:00
Text,
TextType,
UploadCallback,
feat: Renamed design system package (#19854) ## Description This PR includes changes for renaming design system package. Since we are building new package for the refactored design system components, the old package is renaming to design-system-old. Fixes #19536 ## Type of change - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## How Has This Been Tested? - Manual - Jest - Cypress ### 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 - [x] 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 - [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-01-23 03:50:47 +00:00
} from "design-system-old";
chore: migrate toast (#17208) * Refactor toast to be passed the dispatch hook externally * Add comments explaining dilemma * use store.dispatch instead of a hook * use alpha version * Change imports * Refactor DebugButton out * update release * fix issue with incorrectly merged package.lock * fix syntax of alpha version * bump ds vesion * copy lock from release * update lock to have alpha * make changes * delete Toast * DS package version updated * import change from release * use new alpha version * update ds version * update ds version * chore: migrate editable text and friends (#17285) * Delete empty components * use alpha for ds * Deleted EditableTextSubComponent, import changes * Delete EditableText, import changes * use ds alpha 10 * Delete EditableTextWrapper.tsx * update ds to use next minor version * use new alpha * fix issue with merge Co-authored-by: Albin <albin@appsmith.com> * chore: migrate file picker v2 (#17308) * use alpha ds * Delete FilePickerV2, import changes * Delete FilePicker, change imports * update alpha version * chore: move copy url form into setting components (#17322) * move CopyUrlForm to src/pages/settings/formgroup * update ds version to use next minor release * feat: Migrate table component to design system (#17329) * feat: Migrate table component to design system * removed commented code in ads index file * fix: table no data hover effect removed Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Banner message component migrated to design system (#17327) * feat: Banner image component migrated to design system * Version update for design system package * design system version updated Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> * feat: Tabs component migrated to design system (#17321) * feat: Tabs component migrated to design system * design system package version updated * Update app/client/src/components/editorComponents/form/FormDialogComponent.tsx * Update app/client/src/pages/Editor/PropertyPane/PropertyPaneTab.tsx * Tab component expand issue fix Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Albin <albin@appsmith.com> Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
2022-10-13 20:13:44 +00:00
import { Classes } from "@blueprintjs/core";
import { getIsFetchingApplications } from "selectors/applicationSelectors";
import { useMediaQuery } from "react-responsive";
2021-06-16 18:36:34 +00:00
// trigger tests
const GeneralWrapper = styled.div<{
isMobile?: boolean;
isPortrait?: boolean;
}>`
width: ${(props) => (props.isPortrait ? "336px" : "383px")};
margin: ${(props) =>
props.isMobile ? (props.isPortrait ? "auto" : "120px") : null};
padding: 0 20px;
`;
2021-06-16 18:36:34 +00:00
const InputLabelWrapper = styled.div`
display: flex;
align-items: center;
margin-bottom: 8px;
`;
const SettingWrapper = styled.div`
width: 100%;
display: flex;
margin-bottom: 15px;
`;
export const SettingsHeading = styled(Text)`
2020-12-24 04:32:25 +00:00
color: ${(props) => props.theme.colors.settingHeading};
display: inline-block;
margin-top: 25px;
margin-bottom: 10px;
`;
const Loader = styled.div`
height: 38px;
width: 320px;
border-radius: 0;
`;
const FilePickerLoader = styled.div`
height: 190px;
width: 333px;
border-radius: 0;
`;
// testing
export const Row = styled.div`
width: 100%;
margin: 0;
padding: 0;
display: flex;
`;
export const Col = styled.div`
width: 100%;
margin: 0;
padding: 0;
`;
export function GeneralSettings() {
const { workspaceId } = useParams<{ workspaceId: string }>();
const dispatch = useDispatch();
const currentWorkspace = useSelector(getCurrentWorkspace).filter(
(el) => el.id === workspaceId,
)[0];
function saveChanges(settings: SaveWorkspaceRequest) {
dispatch(saveWorkspace(settings));
}
const timeout = 1000;
const onWorkspaceNameChange = debounce((newName: string) => {
saveChanges({
id: workspaceId as string,
name: newName,
});
}, timeout);
const onWebsiteChange = debounce((newWebsite: string) => {
saveChanges({
id: workspaceId as string,
website: newWebsite,
});
}, timeout);
const onEmailChange = debounce((newEmail: string) => {
saveChanges({
id: workspaceId as string,
email: newEmail,
});
}, timeout);
const { isFetchingWorkspace } = useSelector(getWorkspaceLoadingStates);
const logoUploadError = useSelector(getCurrentError);
const FileUploader = (
file: File,
setProgress: SetProgress,
onUpload: UploadCallback,
) => {
const progress = (progressEvent: ProgressEvent) => {
const uploadPercentage = Math.round(
(progressEvent.loaded / progressEvent.total) * 100,
);
if (uploadPercentage === 100) {
onUpload(currentWorkspace.logoUrl || "");
}
setProgress(uploadPercentage);
};
dispatch(
uploadWorkspaceLogo({
id: workspaceId as string,
logo: file,
progress: progress,
}),
);
};
const DeleteLogo = () => {
dispatch(deleteWorkspaceLogo(workspaceId));
};
const isFetchingApplications = useSelector(getIsFetchingApplications);
const isMobile: boolean = useMediaQuery({ maxWidth: 767 });
const isPortrait: boolean = useMediaQuery({
query: "(orientation: portrait)",
});
return (
<GeneralWrapper isMobile={isMobile} isPortrait={isPortrait}>
<SettingsHeading type={TextType.H1}>
<Row>
<Col>General Settings</Col>
</Row>
</SettingsHeading>
<SettingWrapper>
<Row>
<Col>
<InputLabelWrapper>
2022-07-20 11:54:16 +00:00
<Text type={TextType.P1}>Workspace Name</Text>
</InputLabelWrapper>
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
{!isFetchingApplications && (
<TextInput
cypressSelector="t--workspace-name-input"
defaultValue={currentWorkspace && currentWorkspace.name}
fill
onChange={onWorkspaceNameChange}
2022-07-20 11:54:16 +00:00
placeholder="Workspace Name"
validator={notEmptyValidator}
/>
)}
</Col>
</Row>
</SettingWrapper>
<SettingWrapper>
<Row className="t--workspace-settings-filepicker">
<Col>
<InputLabelWrapper>
<Text type={TextType.P1}>Upload Logo</Text>
</InputLabelWrapper>
{isFetchingWorkspace && (
<FilePickerLoader className={Classes.SKELETON} />
)}
{!isFetchingWorkspace && (
<FilePickerV2
Feature/import applications (#4483) * Added export option to app menu. TODO: call api to download app file * Added checkbox component and removed unused code * Added import app without filepicker. Opens modal * added ability to fetch the exported app * can download exported application as a json file * Updated the file picker component to accept other file formats * WIP import app * Added functionality to import application json file * minor fixes * Made the file type prop mandatory for file picker * added a test suite for export app * Test added to check if on import application click, it open a modal * added a dummy application file for cypress testing * Added end to end integration test suite to verify import app feature * added test to verify the export api status and download file. * added a linked btn to carry exporting. - according to latest BE changes * Removed old redux and saga mechanism for app export * updated cypress test to validate new flow * fixed minor linting errors * updated test case title * updated the test cases for import/export app feat * review changes * added prop to facilitate delayed upload * added new application file to fixtures. Minor fix to take care of loading state. * Removed export app modal. Added one click action, to download the file. * Updated File picker to work with all other files acc to the design. * Updated the import modal * updated the import application test * Added remove upload tooltip * updated the icons for import/export actions * removed unused logs * added hard coded feature flag to hide/show import export feature Co-authored-by: Pranav Kanade <pranav@appsmith.com>
2021-06-03 06:18:08 +00:00
fileType={FileType.IMAGE}
fileUploader={FileUploader}
logoUploadError={logoUploadError.message}
onFileRemoved={DeleteLogo}
url={currentWorkspace && currentWorkspace.logoUrl}
/>
)}
</Col>
</Row>
</SettingWrapper>
<SettingWrapper>
<Row>
<Col>
<InputLabelWrapper>
<Text type={TextType.P1}>Website</Text>
</InputLabelWrapper>
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
{!isFetchingApplications && (
<TextInput
cypressSelector="t--workspace-website-input"
defaultValue={
(currentWorkspace && currentWorkspace.website) || ""
}
fill
onChange={onWebsiteChange}
placeholder="Your website"
/>
)}
</Col>
</Row>
</SettingWrapper>
<SettingWrapper>
<Row>
<Col>
<InputLabelWrapper>
<Text type={TextType.P1}>Email</Text>
</InputLabelWrapper>
{isFetchingApplications && <Loader className={Classes.SKELETON} />}
{!isFetchingApplications && (
<TextInput
cypressSelector="t--workspace-email-input"
defaultValue={
(currentWorkspace && currentWorkspace.email) || ""
}
fill
onChange={onEmailChange}
placeholder="Email"
validator={emailValidator}
/>
)}
</Col>
</Row>
</SettingWrapper>
</GeneralWrapper>
);
}