PromucFlow_constructor/app/client/src/reducers/uiReducers/apiPaneReducer.ts

239 lines
6.0 KiB
TypeScript
Raw Normal View History

2022-08-04 05:40:44 +00:00
import { createReducer } from "utils/ReducerUtils";
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 { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
2019-11-13 07:34:59 +00:00
import {
ReduxActionTypes,
ReduxActionErrorTypes,
} from "@appsmith/constants/ReduxActionConstants";
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 { Action } from "entities/Action";
import type { UpdateActionPropertyActionPayload } from "actions/pluginActionActions";
2019-11-13 07:34:59 +00:00
const initialState: ApiPaneReduxState = {
isCreating: false,
2019-11-13 07:34:59 +00:00
isFetching: false,
2019-12-11 15:14:38 +00:00
isRunning: {},
isSaving: {},
isDeleting: {},
isDirty: {},
currentCategory: "",
extraformData: {},
selectedConfigTabIndex: 0,
selectedResponseTab: "",
2019-11-13 07:34:59 +00:00
};
2020-06-18 14:16:49 +00:00
2019-11-13 07:34:59 +00:00
export interface ApiPaneReduxState {
isCreating: boolean; // RR
isFetching: boolean; // RR
2019-12-11 15:14:38 +00:00
isRunning: Record<string, boolean>;
isSaving: Record<string, boolean>; // RN
2019-12-11 15:14:38 +00:00
isDeleting: Record<string, boolean>;
isDirty: Record<string, boolean>;
currentCategory: string;
extraformData: Record<string, any>;
selectedConfigTabIndex: number;
selectedResponseTab: string;
feat: [epic] appsmith design system version 2 deduplication (#22030) ## Description ### Fixes - [x] https://github.com/appsmithorg/appsmith/issues/19383 - [x] https://github.com/appsmithorg/appsmith/issues/19384 - [x] https://github.com/appsmithorg/appsmith/issues/19385 - [x] https://github.com/appsmithorg/appsmith/issues/19386 - [x] https://github.com/appsmithorg/appsmith/issues/19387 - [x] https://github.com/appsmithorg/appsmith/issues/19388 - [x] https://github.com/appsmithorg/appsmith/issues/19389 - [x] https://github.com/appsmithorg/appsmith/issues/19390 - [x] https://github.com/appsmithorg/appsmith/issues/19391 - [x] https://github.com/appsmithorg/appsmith/issues/19392 - [x] https://github.com/appsmithorg/appsmith/issues/19393 - [x] https://github.com/appsmithorg/appsmith/issues/19394 - [x] https://github.com/appsmithorg/appsmith/issues/19395 - [x] https://github.com/appsmithorg/appsmith/issues/19396 - [x] https://github.com/appsmithorg/appsmith/issues/19397 - [x] https://github.com/appsmithorg/appsmith/issues/19398 - [x] https://github.com/appsmithorg/appsmith/issues/19399 - [x] https://github.com/appsmithorg/appsmith/issues/19400 - [x] https://github.com/appsmithorg/appsmith/issues/19401 - [x] https://github.com/appsmithorg/appsmith/issues/19402 - [x] https://github.com/appsmithorg/appsmith/issues/19403 - [x] https://github.com/appsmithorg/appsmith/issues/19404 - [x] https://github.com/appsmithorg/appsmith/issues/19405 - [x] https://github.com/appsmithorg/appsmith/issues/19406 - [x] https://github.com/appsmithorg/appsmith/issues/19407 - [x] https://github.com/appsmithorg/appsmith/issues/19408 - [x] https://github.com/appsmithorg/appsmith/issues/19409 Fixes # (issue) > if no issue exists, please create an issue and ask the maintainers about this first Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - 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 - [ ] 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 - [ ] 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: Ankita Kinger <ankita@appsmith.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvi@appsmith.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in> Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local> Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com> Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com> Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com> Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
2023-05-19 18:37:06 +00:00
selectedRightPaneTab?: string;
2019-11-13 07:34:59 +00:00
}
const apiPaneReducer = createReducer(initialState, {
[ReduxActionTypes.FETCH_ACTIONS_INIT]: (state: ApiPaneReduxState) => ({
...state,
isFetching: true,
}),
[ReduxActionTypes.FETCH_ACTIONS_SUCCESS]: (state: ApiPaneReduxState) => ({
...state,
isFetching: false,
}),
[ReduxActionErrorTypes.FETCH_ACTIONS_ERROR]: (state: ApiPaneReduxState) => ({
...state,
isFetching: false,
}),
[ReduxActionTypes.CREATE_ACTION_INIT]: (
state: ApiPaneReduxState,
): ApiPaneReduxState => ({
...state,
isCreating: true,
}),
[ReduxActionTypes.CREATE_ACTION_SUCCESS]: (
state: ApiPaneReduxState,
): ApiPaneReduxState => ({
...state,
isCreating: false,
}),
[ReduxActionErrorTypes.CREATE_ACTION_ERROR]: (
state: ApiPaneReduxState,
): ApiPaneReduxState => ({
...state,
isCreating: false,
}),
[ReduxActionTypes.RUN_ACTION_REQUEST]: (
2019-12-11 15:14:38 +00:00
state: ApiPaneReduxState,
2020-02-13 11:38:34 +00:00
action: ReduxAction<{ id: string }>,
2019-12-11 15:14:38 +00:00
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isRunning: {
...state.isRunning,
2020-02-13 11:38:34 +00:00
[action.payload.id]: true,
2019-12-11 15:14:38 +00:00
},
2019-11-13 07:34:59 +00:00
}),
[ReduxActionTypes.RUN_ACTION_SUCCESS]: (
2019-12-11 15:14:38 +00:00
state: ApiPaneReduxState,
action: ReduxAction<{ [id: string]: any }>,
) => {
const actionId = Object.keys(action.payload)[0];
return {
...state,
isRunning: {
...state.isRunning,
[actionId]: false,
},
};
},
[ReduxActionErrorTypes.RUN_ACTION_ERROR]: (
2019-12-11 15:14:38 +00:00
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isRunning: {
...state.isRunning,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
[ReduxActionTypes.RUN_ACTION_CANCELLED]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
): ApiPaneReduxState => ({
...state,
isRunning: {
...state.isRunning,
[action.payload.id]: false,
},
}),
[ReduxActionTypes.UPDATE_ACTION_PROPERTY]: (
state: ApiPaneReduxState,
action: ReduxAction<UpdateActionPropertyActionPayload>,
) => ({
...state,
isDirty: {
...state.isDirty,
[action.payload.id]: true,
},
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.UPDATE_ACTION_INIT]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
2019-12-11 15:14:38 +00:00
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.id]: true,
2019-12-11 15:14:38 +00:00
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.UPDATE_ACTION_SUCCESS]: (
state: ApiPaneReduxState,
action: ReduxAction<{ data: Action }>,
2019-12-11 15:14:38 +00:00
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.data.id]: false,
},
isDirty: {
...state.isDirty,
[action.payload.data.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionErrorTypes.UPDATE_ACTION_ERROR]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isSaving: {
...state.isSaving,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.DELETE_ACTION_INIT]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: true,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionTypes.DELETE_ACTION_SUCCESS]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
2019-12-11 15:14:38 +00:00
[ReduxActionErrorTypes.DELETE_ACTION_ERROR]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string }>,
) => ({
2019-11-13 07:34:59 +00:00
...state,
2019-12-11 15:14:38 +00:00
isDeleting: {
...state.isDeleting,
[action.payload.id]: false,
},
2019-11-13 07:34:59 +00:00
}),
[ReduxActionTypes.SET_CURRENT_CATEGORY]: (
state: ApiPaneReduxState,
action: ReduxAction<{ category: string }>,
) => ({
...state,
currentCategory: action.payload.category,
}),
feat: Support body in GET API requests (#7127) * WIP * Refactoring HTTP Method & Content Type to be objects instead of arrays TODO: 1. Set the default content-type for Get request to "None". Currently, it's raw 2. For None content-type, don't send the body field in the API request * Almost working implementation for the None type Currently, the body still gets sent in non-GET requests even if the None tab is selected. * Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM * WIP: Using enum & const for ts autocomplete * working implementation for NONE type, apiContentType prop added to API actions * WIP * Refactoring HTTP Method & Content Type to be objects instead of arrays TODO: 1. Set the default content-type for Get request to "None". Currently, it's raw 2. For None content-type, don't send the body field in the API request * Almost working implementation for the None type Currently, the body still gets sent in non-GET requests even if the None tab is selected. * Adding object.freeze to prevent any modifications to HTTP_METHOD_ENUM * WIP: Using enum & const for ts autocomplete * working implementation for NONE type, apiContentType prop added to API actions * adds apiContentType to actionConfiguration.formData object * Handling apiContentType property in Rest API formData * change apiContentType when user types content-type value and switches http method * makes api editor as similar as possible to postman, project postman. * Correcting the import in ApiEditorConstants * Resolved all merge conflicts * replay DSL functtionality * removes unneccessary files from worker * Fixes type declarations, naming e.t.c. * fix server side merge conflicts * fix client side merge conflicts * fix failing cypress tests Co-authored-by: Irongade <adeoluayangade@yahoo.com> Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
2022-02-15 11:13:48 +00:00
/**
* This redux action sets the extraformData field for an action. This is used to select the
* appropriate body type tab selection in the Rest API plugin based on the content-type.
* This redux action can be extended to other functionalities as well in the future.
*
* @param {ApiPaneReduxState} state
* @param {ReduxAction} action
* @returns {ApiPaneReduxState}
*/
[ReduxActionTypes.SET_EXTRA_FORMDATA]: (
state: ApiPaneReduxState,
action: ReduxAction<{ id: string; values: Record<string, unknown> }>,
) => {
const { id, values } = action.payload;
return {
...state,
extraformData: {
...state.extraformData,
[id]: values,
},
};
},
[ReduxActionTypes.SET_API_PANE_CONFIG_SELECTED_TAB]: (
state: ApiPaneReduxState,
action: ReduxAction<{ selectedTabIndex: number }>,
) => {
const { selectedTabIndex } = action.payload;
return {
...state,
selectedConfigTabIndex: selectedTabIndex,
};
},
[ReduxActionTypes.SET_API_RIGHT_PANE_SELECTED_TAB]: (
state: ApiPaneReduxState,
action: ReduxAction<{ selectedTab: number }>,
) => {
const { selectedTab } = action.payload;
return {
...state,
selectedRightPaneTab: selectedTab,
};
},
2019-11-13 07:34:59 +00:00
});
export default apiPaneReducer;