From 266c41fde355721f6ffec35b4e50b6daaea199f9 Mon Sep 17 00:00:00 2001 From: Ankita Kinger Date: Sat, 30 Sep 2023 11:58:05 +0530 Subject: [PATCH] chore: Optimizing code-split for mapStateToProps and mapDispatchToProps (#27726) ## Description Optimizing code-split for mapStateToProps and mapDispatchToProps #### PR fixes following issue(s) Fixes [#27727](https://github.com/appsmithorg/appsmith/issues/27727) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [ ] Jest - [x] Cypress ## 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: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- app/client/src/ce/AppRouter.tsx | 4 +- .../src/ce/pages/Applications/index.tsx | 4 +- .../workspace/WorkspaceInviteUsersForm.tsx | 37 +++++++++++-------- app/client/src/components/common/Card.tsx | 7 +++- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/app/client/src/ce/AppRouter.tsx b/app/client/src/ce/AppRouter.tsx index 628d1654a4..cbfd14f1ef 100644 --- a/app/client/src/ce/AppRouter.tsx +++ b/app/client/src/ce/AppRouter.tsx @@ -204,12 +204,12 @@ function AppRouter(props: { ); } -const mapStateToProps = (state: AppState) => ({ +export const mapStateToProps = (state: AppState) => ({ safeCrash: getSafeCrash(state), safeCrashCode: getSafeCrashCode(state), }); -const mapDispatchToProps = (dispatch: any) => ({ +export const mapDispatchToProps = (dispatch: any) => ({ getCurrentUser: () => dispatch(getCurrentUser()), getFeatureFlags: () => dispatch(fetchFeatureFlagsInit()), getCurrentTenant: () => dispatch(getCurrentTenant(false)), diff --git a/app/client/src/ce/pages/Applications/index.tsx b/app/client/src/ce/pages/Applications/index.tsx index 902cd592c0..78afbd51d6 100644 --- a/app/client/src/ce/pages/Applications/index.tsx +++ b/app/client/src/ce/pages/Applications/index.tsx @@ -849,7 +849,7 @@ export class Applications< } } -const mapStateToProps = (state: AppState) => ({ +export const mapStateToProps = (state: AppState) => ({ applicationList: getApplicationList(state), isFetchingApplications: getIsFetchingApplications(state), isCreatingApplication: getIsCreatingApplication(state), @@ -860,7 +860,7 @@ const mapStateToProps = (state: AppState) => ({ searchKeyword: getApplicationSearchKeyword(state), }); -const mapDispatchToProps = (dispatch: any) => ({ +export const mapDispatchToProps = (dispatch: any) => ({ getAllApplication: () => { dispatch({ type: ReduxActionTypes.GET_ALL_APPLICATION_INIT }); }, diff --git a/app/client/src/ce/pages/workspace/WorkspaceInviteUsersForm.tsx b/app/client/src/ce/pages/workspace/WorkspaceInviteUsersForm.tsx index 1723a63bfe..5524d86097 100644 --- a/app/client/src/ce/pages/workspace/WorkspaceInviteUsersForm.tsx +++ b/app/client/src/ce/pages/workspace/WorkspaceInviteUsersForm.tsx @@ -718,23 +718,28 @@ function WorkspaceInviteUsersForm(props: any) { ); } +export const mapStateToProps = ( + state: AppState, + { formName }: { formName?: string }, +) => ({ + roles: getRolesForField(state), + allUsers: getAllUsers(state), + isLoading: state.ui.workspaces.loadingStates.isFetchAllUsers, + form: formName || INVITE_USERS_TO_WORKSPACE_FORM, +}); + +export const mapDispatchToProps = (dispatch: any) => ({ + fetchAllRoles: (workspaceId: string) => + dispatch(fetchRolesForWorkspace(workspaceId)), + fetchCurrentWorkspace: (workspaceId: string) => + dispatch(fetchWorkspace(workspaceId)), + fetchUser: (workspaceId: string) => + dispatch(fetchUsersForWorkspace(workspaceId)), +}); + export default connect( - (state: AppState, { formName }: { formName?: string }) => { - return { - roles: getRolesForField(state), - allUsers: getAllUsers(state), - isLoading: state.ui.workspaces.loadingStates.isFetchAllUsers, - form: formName || INVITE_USERS_TO_WORKSPACE_FORM, - }; - }, - (dispatch: any) => ({ - fetchAllRoles: (workspaceId: string) => - dispatch(fetchRolesForWorkspace(workspaceId)), - fetchCurrentWorkspace: (workspaceId: string) => - dispatch(fetchWorkspace(workspaceId)), - fetchUser: (workspaceId: string) => - dispatch(fetchUsersForWorkspace(workspaceId)), - }), + mapStateToProps, + mapDispatchToProps, )( reduxForm< InviteUsersToWorkspaceFormValues, diff --git a/app/client/src/components/common/Card.tsx b/app/client/src/components/common/Card.tsx index 0a1a50dff1..663c29aaa0 100644 --- a/app/client/src/components/common/Card.tsx +++ b/app/client/src/components/common/Card.tsx @@ -102,7 +102,12 @@ const CircleAppIcon = styled(AppIcon)` const NameWrapper = styled((props: HTMLDivProps & NameWrapperProps) => (
))` .bp3-card {