2022-10-26 10:00:55 +00:00
|
|
|
import { call, put, select } from "redux-saga/effects";
|
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,
|
|
|
|
|
ReduxActionWithPromise,
|
2025-01-10 04:51:54 +00:00
|
|
|
} from "actions/ReduxActionTypes";
|
2019-12-23 12:16:33 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
ReduxActionErrorTypes,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/ReduxActionConstants";
|
2020-02-03 10:37:03 +00:00
|
|
|
import {
|
|
|
|
|
validateResponse,
|
|
|
|
|
callAPI,
|
|
|
|
|
getResponseErrorMessage,
|
|
|
|
|
} from "sagas/ErrorSagas";
|
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 {
|
2022-06-15 15:37:41 +00:00
|
|
|
SaveWorkspaceRequest,
|
|
|
|
|
FetchWorkspaceRequest,
|
|
|
|
|
FetchWorkspaceResponse,
|
|
|
|
|
CreateWorkspaceRequest,
|
2020-06-17 10:19:56 +00:00
|
|
|
FetchAllUsersResponse,
|
|
|
|
|
FetchAllUsersRequest,
|
|
|
|
|
FetchAllRolesResponse,
|
2022-06-15 15:37:41 +00:00
|
|
|
DeleteWorkspaceUserRequest,
|
2020-06-17 10:19:56 +00:00
|
|
|
ChangeUserRoleRequest,
|
2020-08-12 11:41:56 +00:00
|
|
|
FetchAllRolesRequest,
|
2022-06-15 15:37:41 +00:00
|
|
|
SaveWorkspaceLogo,
|
2024-01-25 13:41:48 +00:00
|
|
|
FetchWorkspacesResponse,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/api/WorkspaceApi";
|
|
|
|
|
import WorkspaceApi from "ee/api/WorkspaceApi";
|
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 { ApiResponse } from "api/ApiResponses";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getFetchedWorkspaces } from "ee/selectors/workspaceSelectors";
|
2021-06-03 18:36:34 +00:00
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { Workspace } from "ee/constants/workspaceConstants";
|
2021-01-21 06:19:06 +00:00
|
|
|
import history from "utils/history";
|
2021-06-03 18:36:34 +00:00
|
|
|
import { APPLICATIONS_URL } from "constants/routes";
|
2021-03-13 14:24:45 +00:00
|
|
|
import log from "loglevel";
|
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 { User } from "constants/userConstants";
|
2022-02-11 18:08:46 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
2022-06-15 15:37:41 +00:00
|
|
|
DELETE_WORKSPACE_SUCCESSFUL,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/messages";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { toast } from "@appsmith/ads";
|
2024-01-25 13:41:48 +00:00
|
|
|
import { failFastApiCalls } from "sagas/InitSagas";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getWorkspaceEntitiesActions } from "ee/utils/workspaceHelpers";
|
|
|
|
|
import type { SearchApiResponse } from "ee/types/ApiResponseTypes";
|
2024-01-25 13:41:48 +00:00
|
|
|
import SearchApi from "api/SearchApi";
|
|
|
|
|
|
|
|
|
|
export function* fetchAllWorkspacesSaga(
|
|
|
|
|
action?: ReduxAction<{ workspaceId?: string; fetchEntities: boolean }>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const response: FetchWorkspacesResponse = yield call(
|
|
|
|
|
WorkspaceApi.fetchAllWorkspaces,
|
|
|
|
|
);
|
|
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
const workspaces: Workspace[] = response.data;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_ALL_WORKSPACES_SUCCESS,
|
|
|
|
|
payload: workspaces,
|
|
|
|
|
});
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
if (action?.payload?.workspaceId || action?.payload?.fetchEntities) {
|
|
|
|
|
yield call(fetchEntitiesOfWorkspaceSaga, action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.FETCH_USER_APPLICATIONS_WORKSPACES_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* fetchEntitiesOfWorkspaceSaga(
|
|
|
|
|
action?: ReduxAction<{ workspaceId?: string }>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const allWorkspaces: Workspace[] = yield select(getFetchedWorkspaces);
|
|
|
|
|
const workspaceId = action?.payload?.workspaceId || allWorkspaces[0]?.id;
|
|
|
|
|
const activeWorkspace = allWorkspaces.find(
|
|
|
|
|
(workspace) => workspace.id === workspaceId,
|
|
|
|
|
);
|
|
|
|
|
const { errorActions, initActions, successActions } =
|
|
|
|
|
getWorkspaceEntitiesActions(workspaceId);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SET_CURRENT_WORKSPACE,
|
|
|
|
|
payload: { ...activeWorkspace },
|
|
|
|
|
});
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
if (workspaceId) {
|
|
|
|
|
yield call(failFastApiCalls, initActions, successActions, errorActions);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.FETCH_WORKSPACE_ENTITIES_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* fetchWorkspaceSaga(
|
|
|
|
|
action: ReduxAction<FetchWorkspaceRequest>,
|
|
|
|
|
) {
|
2019-12-23 12:16:33 +00:00
|
|
|
try {
|
2022-06-15 15:37:41 +00:00
|
|
|
const request: FetchWorkspaceRequest = action.payload;
|
|
|
|
|
const response: FetchWorkspaceResponse = yield call(
|
|
|
|
|
WorkspaceApi.fetchWorkspace,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield request.skipValidation ||
|
2021-07-16 08:31:26 +00:00
|
|
|
validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-09-12 13:49:22 +00:00
|
|
|
if (isValidResponse && response) {
|
2019-12-23 12:16:33 +00:00
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.FETCH_WORKSPACE_SUCCESS,
|
2021-07-16 08:31:26 +00:00
|
|
|
payload: response.data || {},
|
2019-12-23 12:16:33 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.FETCH_WORKSPACE_ERROR,
|
2019-12-23 12:16:33 +00:00
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
export function* fetchAllUsersSaga(action: ReduxAction<FetchAllUsersRequest>) {
|
|
|
|
|
try {
|
|
|
|
|
const request: FetchAllUsersRequest = action.payload;
|
|
|
|
|
const response: FetchAllUsersResponse = yield call(
|
2022-06-15 15:37:41 +00:00
|
|
|
WorkspaceApi.fetchAllUsers,
|
2020-06-17 10:19:56 +00:00
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
if (isValidResponse) {
|
2020-12-24 04:32:25 +00:00
|
|
|
const users = response.data.map((user) => ({
|
2020-06-25 03:05:41 +00:00
|
|
|
...user,
|
|
|
|
|
isDeleting: false,
|
|
|
|
|
isChangingRole: false,
|
|
|
|
|
}));
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_ALL_USERS_SUCCESS,
|
2020-06-25 03:05:41 +00:00
|
|
|
payload: users,
|
2020-06-17 10:19:56 +00:00
|
|
|
});
|
2024-01-25 13:41:48 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.GET_ALL_USERS_OF_WORKSPACE_SUCCESS,
|
|
|
|
|
payload: users,
|
|
|
|
|
});
|
2020-06-17 10:19:56 +00:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.FETCH_ALL_USERS_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* changeWorkspaceUserRoleSaga(
|
2020-06-17 10:19:56 +00:00
|
|
|
action: ReduxAction<ChangeUserRoleRequest>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const request: ChangeUserRoleRequest = action.payload;
|
2022-06-15 15:37:41 +00:00
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.changeWorkspaceUserRole,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.CHANGE_WORKSPACE_USER_ROLE_SUCCESS,
|
2020-06-17 10:19:56 +00:00
|
|
|
payload: response.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.CHANGE_WORKSPACE_USER_ROLE_ERROR,
|
2020-08-28 18:51:16 +00:00
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
2020-06-17 10:19:56 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* deleteWorkspaceUserSaga(
|
|
|
|
|
action: ReduxAction<DeleteWorkspaceUserRequest>,
|
|
|
|
|
) {
|
2020-06-17 10:19:56 +00:00
|
|
|
try {
|
2022-06-15 15:37:41 +00:00
|
|
|
const request: DeleteWorkspaceUserRequest = action.payload;
|
|
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.deleteWorkspaceUser,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
if (isValidResponse) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const currentUser: User | undefined = yield select(getCurrentUser);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2021-06-03 18:36:34 +00:00
|
|
|
if (currentUser?.username == action.payload.username) {
|
|
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
} else {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.DELETE_WORKSPACE_USER_SUCCESS,
|
2021-06-03 18:36:34 +00:00
|
|
|
payload: {
|
|
|
|
|
username: action.payload.username,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
//@ts-expect-error: response is of type unknown
|
|
|
|
|
toast.show(`${response.data.username} has been removed successfully`, {
|
|
|
|
|
kind: "success",
|
2020-06-17 10:19:56 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.DELETE_WORKSPACE_USER_ERROR,
|
2020-06-17 10:19:56 +00:00
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 11:41:56 +00:00
|
|
|
export function* fetchAllRolesSaga(action: ReduxAction<FetchAllRolesRequest>) {
|
2020-06-17 10:19:56 +00:00
|
|
|
try {
|
2020-08-12 11:41:56 +00:00
|
|
|
const request: FetchAllRolesRequest = action.payload;
|
|
|
|
|
const response: FetchAllRolesResponse = yield call(
|
2022-06-15 15:37:41 +00:00
|
|
|
WorkspaceApi.fetchAllRoles,
|
2020-08-12 11:41:56 +00:00
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.FETCH_ALL_ROLES_SUCCESS,
|
|
|
|
|
payload: response.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.FETCH_ALL_ROLES_ERROR,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* saveWorkspaceSaga(action: ReduxAction<SaveWorkspaceRequest>) {
|
2019-12-23 12:16:33 +00:00
|
|
|
try {
|
2022-06-15 15:37:41 +00:00
|
|
|
const request: SaveWorkspaceRequest = action.payload;
|
|
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.saveWorkspace,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.SAVE_WORKSPACE_SUCCESS,
|
2020-11-25 12:24:14 +00:00
|
|
|
payload: request,
|
2019-12-23 12:16:33 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.SAVE_WORKSPACE_ERROR,
|
2019-12-23 12:16:33 +00:00
|
|
|
payload: {
|
2024-04-17 05:11:31 +00:00
|
|
|
error,
|
2019-12-23 12:16:33 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* deleteWorkspaceSaga(action: ReduxAction<string>) {
|
2021-12-20 05:58:01 +00:00
|
|
|
try {
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceId: string = action.payload;
|
|
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.deleteWorkspace,
|
|
|
|
|
workspaceId,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2021-12-20 05:58:01 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.DELETE_WORKSPACE_SUCCESS,
|
|
|
|
|
payload: workspaceId,
|
2021-12-20 05:58:01 +00:00
|
|
|
});
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(createMessage(DELETE_WORKSPACE_SUCCESSFUL), {
|
|
|
|
|
kind: "success",
|
2021-12-20 05:58:01 +00:00
|
|
|
});
|
2024-01-25 13:41:48 +00:00
|
|
|
history.push("/applications");
|
2021-12-20 05:58:01 +00:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.DELETE_WORKSPACE_ERROR,
|
2021-12-20 05:58:01 +00:00
|
|
|
payload: {
|
2022-06-21 13:57:34 +00:00
|
|
|
error: (error as Error).message,
|
2021-12-20 05:58:01 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* createWorkspaceSaga(
|
|
|
|
|
action: ReduxActionWithPromise<CreateWorkspaceRequest>,
|
2020-02-03 10:37:03 +00:00
|
|
|
) {
|
2021-05-13 08:35:39 +00:00
|
|
|
const { name, reject, resolve } = action.payload;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
try {
|
2022-06-15 15:37:41 +00:00
|
|
|
const request: CreateWorkspaceRequest = { name };
|
|
|
|
|
const response: ApiResponse = yield callAPI(
|
|
|
|
|
WorkspaceApi.createWorkspace,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
if (!isValidResponse) {
|
2023-10-11 07:14:38 +00:00
|
|
|
const errorMessage: string | undefined =
|
|
|
|
|
yield getResponseErrorMessage(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-02-03 10:37:03 +00:00
|
|
|
yield call(reject, { _error: errorMessage });
|
|
|
|
|
} else {
|
|
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.CREATE_WORKSPACE_SUCCESS,
|
2020-02-03 10:37:03 +00:00
|
|
|
payload: response.data,
|
|
|
|
|
});
|
|
|
|
|
yield call(resolve);
|
|
|
|
|
}
|
2021-01-21 06:19:06 +00:00
|
|
|
|
2022-07-20 11:54:16 +00:00
|
|
|
// get created workspace in focus
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: response is of type unknown
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceId = response.data.id;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
history.push(`${window.location.pathname}?workspaceId=${workspaceId}`);
|
2020-02-03 10:37:03 +00:00
|
|
|
} catch (error) {
|
2022-06-21 13:57:34 +00:00
|
|
|
yield call(reject, { _error: (error as Error).message });
|
2020-02-03 10:37:03 +00:00
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionErrorTypes.CREATE_WORKSPACE_ERROR,
|
2020-02-03 10:37:03 +00:00
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* uploadWorkspaceLogoSaga(
|
|
|
|
|
action: ReduxAction<SaveWorkspaceLogo>,
|
|
|
|
|
) {
|
2020-12-01 22:01:27 +00:00
|
|
|
try {
|
|
|
|
|
const request = action.payload;
|
2022-06-15 15:37:41 +00:00
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.saveWorkspaceLogo,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-12-01 22:01:27 +00:00
|
|
|
if (isValidResponse) {
|
2024-01-25 13:41:48 +00:00
|
|
|
const allWorkspaces: Workspace[] = yield select(getFetchedWorkspaces);
|
2022-06-15 15:37:41 +00:00
|
|
|
const currentWorkspace = allWorkspaces.filter(
|
|
|
|
|
(el: Workspace) => el.id === request.id,
|
|
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
if (currentWorkspace.length > 0) {
|
2020-12-01 22:01:27 +00:00
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.SAVE_WORKSPACE_SUCCESS,
|
2020-12-11 07:01:13 +00:00
|
|
|
payload: {
|
2022-06-15 15:37:41 +00:00
|
|
|
id: currentWorkspace[0].id,
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: response is of type unknown
|
2020-12-11 07:01:13 +00:00
|
|
|
logoUrl: response.data.logoUrl,
|
|
|
|
|
},
|
2020-12-01 22:01:27 +00:00
|
|
|
});
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show("Logo uploaded successfully", {
|
|
|
|
|
kind: "success",
|
2020-12-01 22:01:27 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2021-03-13 14:24:45 +00:00
|
|
|
log.error("Error occured while uploading the logo", error);
|
2020-12-01 22:01:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
export function* deleteWorkspaceLogoSaga(action: ReduxAction<{ id: string }>) {
|
2020-12-01 22:01:27 +00:00
|
|
|
try {
|
|
|
|
|
const request = action.payload;
|
2022-06-15 15:37:41 +00:00
|
|
|
const response: ApiResponse = yield call(
|
|
|
|
|
WorkspaceApi.deleteWorkspaceLogo,
|
|
|
|
|
request,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-12-01 22:01:27 +00:00
|
|
|
if (isValidResponse) {
|
2024-01-25 13:41:48 +00:00
|
|
|
const allWorkspaces: Workspace[] = yield select(getFetchedWorkspaces);
|
2022-06-15 15:37:41 +00:00
|
|
|
const currentWorkspace = allWorkspaces.filter(
|
|
|
|
|
(el: Workspace) => el.id === request.id,
|
|
|
|
|
);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-06-15 15:37:41 +00:00
|
|
|
if (currentWorkspace.length > 0) {
|
2020-12-01 22:01:27 +00:00
|
|
|
yield put({
|
2022-06-15 15:37:41 +00:00
|
|
|
type: ReduxActionTypes.SAVE_WORKSPACE_SUCCESS,
|
2020-12-11 07:01:13 +00:00
|
|
|
payload: {
|
2022-06-15 15:37:41 +00:00
|
|
|
id: currentWorkspace[0].id,
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: response is of type unknown
|
2020-12-11 07:01:13 +00:00
|
|
|
logoUrl: response.data.logoUrl,
|
|
|
|
|
},
|
2020-12-01 22:01:27 +00:00
|
|
|
});
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show("Logo removed successfully", {
|
|
|
|
|
kind: "success",
|
2020-12-01 22:01:27 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2021-03-13 14:24:45 +00:00
|
|
|
log.error("Error occured while removing the logo", error);
|
2020-12-01 22:01:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-01-25 13:41:48 +00:00
|
|
|
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-01-25 13:41:48 +00:00
|
|
|
export function* searchWorkspaceEntitiesSaga(action: ReduxAction<any>) {
|
|
|
|
|
try {
|
|
|
|
|
const response: SearchApiResponse = yield call(
|
|
|
|
|
SearchApi.searchAllEntities,
|
|
|
|
|
{ keyword: action.payload },
|
|
|
|
|
);
|
|
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-01-25 13:41:48 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.SEARCH_WORKSPACE_ENTITIES_SUCCESS,
|
|
|
|
|
payload: response.data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.SEARCH_WORKSPACE_ENTITIES_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|