2023-06-02 11:06:41 +00:00
|
|
|
import React, { useCallback, useEffect, useMemo } from "react";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { saveSettings } from "ee/actions/settingsAction";
|
|
|
|
|
import { SETTINGS_FORM_NAME } from "ee/constants/forms";
|
|
|
|
|
import { ReduxActionTypes } from "ee/constants/ReduxActionConstants";
|
2022-02-11 18:08:46 +00:00
|
|
|
import _ from "lodash";
|
|
|
|
|
import ProductUpdatesModal from "pages/Applications/ProductUpdatesModal";
|
2023-04-30 06:22:42 +00:00
|
|
|
import { connect, useDispatch, useSelector } 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 { RouteComponentProps } from "react-router";
|
|
|
|
|
import { useParams, withRouter } from "react-router";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { AppState } from "ee/reducers";
|
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 { InjectedFormProps } from "redux-form";
|
|
|
|
|
import { formValueSelector, reduxForm } from "redux-form";
|
2022-02-11 18:08:46 +00:00
|
|
|
import {
|
|
|
|
|
getSettings,
|
|
|
|
|
getSettingsSavingState,
|
|
|
|
|
getShowReleaseNotes,
|
|
|
|
|
} from "selectors/settingsSelectors";
|
|
|
|
|
import Group from "./FormGroup/group";
|
|
|
|
|
import RestartBanner from "./RestartBanner";
|
|
|
|
|
import SaveAdminSettings from "./SaveSettings";
|
2022-05-05 05:37:50 +00:00
|
|
|
import { DisconnectService } from "./DisconnectService";
|
2024-08-06 14:52:22 +00:00
|
|
|
import AdminConfig from "ee/pages/AdminSettings/config";
|
|
|
|
|
import type { Setting } from "ee/pages/AdminSettings/config/types";
|
|
|
|
|
import { SettingTypes } from "ee/pages/AdminSettings/config/types";
|
2022-03-02 18:18:50 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
2022-04-26 14:21:06 +00:00
|
|
|
DISCONNECT_AUTH_ERROR,
|
2022-03-02 18:18:50 +00:00
|
|
|
DISCONNECT_SERVICE_SUBHEADER,
|
|
|
|
|
DISCONNECT_SERVICE_WARNING,
|
2022-04-26 14:21:06 +00:00
|
|
|
MANDATORY_FIELDS_ERROR,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/messages";
|
|
|
|
|
import { isTenantConfig, saveAllowed } from "ee/utils/adminSettingsHelpers";
|
|
|
|
|
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
|
2022-05-05 05:37:50 +00:00
|
|
|
import {
|
|
|
|
|
Wrapper,
|
|
|
|
|
BottomSpace,
|
|
|
|
|
HeaderWrapper,
|
|
|
|
|
SettingsHeader,
|
|
|
|
|
SettingsSubHeader,
|
|
|
|
|
SettingsFormWrapper,
|
|
|
|
|
} from "./components";
|
2022-08-27 14:27:10 +00:00
|
|
|
import { BackButton } from "components/utils/helperComponents";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { toast } from "@appsmith/ads";
|
2023-05-16 09:04:48 +00:00
|
|
|
import {
|
|
|
|
|
getIsFormLoginEnabled,
|
|
|
|
|
getThirdPartyAuths,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/selectors/tenantSelectors";
|
|
|
|
|
import { updateTenantConfig } from "ee/actions/tenantActions";
|
|
|
|
|
import { tenantConfigConnection } from "ee/constants/tenantConstants";
|
2022-02-11 18:08:46 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface FormProps {
|
2022-02-11 18:08:46 +00:00
|
|
|
settings: Record<string, string>;
|
|
|
|
|
settingsConfig: Record<string, string | boolean>;
|
|
|
|
|
isSaving: boolean;
|
|
|
|
|
showReleaseNotes: boolean;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2022-02-11 18:08:46 +00:00
|
|
|
|
|
|
|
|
function getSettingLabel(name = "") {
|
|
|
|
|
return name.replace(/-/g, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSettingDetail(category: string, subCategory: string) {
|
|
|
|
|
return AdminConfig.getCategoryDetails(category, subCategory);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 04:53:08 +00:00
|
|
|
function getSettingsConfig(category: string, subCategory?: string) {
|
2022-02-11 18:08:46 +00:00
|
|
|
return AdminConfig.get(subCategory ?? category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SettingsForm(
|
|
|
|
|
props: InjectedFormProps & RouteComponentProps & FormProps,
|
|
|
|
|
) {
|
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
|
2022-02-11 18:08:46 +00:00
|
|
|
const params = useParams() as any;
|
2022-06-08 13:18:15 +00:00
|
|
|
const { category, selected: subCategory } = params;
|
2022-05-18 04:53:08 +00:00
|
|
|
const settingsDetails = getSettingsConfig(category, subCategory);
|
2022-04-04 07:07:12 +00:00
|
|
|
const { settings, settingsConfig } = props;
|
2022-02-11 18:08:46 +00:00
|
|
|
const details = getSettingDetail(category, subCategory);
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const isSavable = AdminConfig.savableCategories.includes(
|
|
|
|
|
subCategory ?? category,
|
|
|
|
|
);
|
2022-03-02 18:18:50 +00:00
|
|
|
const pageTitle = getSettingLabel(
|
|
|
|
|
details?.title || (subCategory ?? category),
|
|
|
|
|
);
|
2023-05-16 09:04:48 +00:00
|
|
|
const isFormLoginEnabled = useSelector(getIsFormLoginEnabled);
|
2023-04-30 06:22:42 +00:00
|
|
|
const socialLoginList = useSelector(getThirdPartyAuths);
|
2022-02-11 18:08:46 +00:00
|
|
|
|
2023-06-02 11:06:41 +00:00
|
|
|
const updatedTenantSettings = useMemo(
|
|
|
|
|
() => Object.keys(props.settings).filter((s) => isTenantConfig(s)),
|
|
|
|
|
[props.settings],
|
|
|
|
|
);
|
|
|
|
|
|
2023-07-24 08:03:53 +00:00
|
|
|
// Is there a non-tenant (env) config in this category of settings?
|
|
|
|
|
const isOnlyTenantConfig = !settingsDetails.find(
|
|
|
|
|
(s) =>
|
|
|
|
|
s.category === (subCategory || category) &&
|
2023-08-28 15:37:32 +00:00
|
|
|
s.controlType != SettingTypes.CALLOUT &&
|
2023-07-24 08:03:53 +00:00
|
|
|
!isTenantConfig(s.id),
|
|
|
|
|
);
|
|
|
|
|
|
2023-06-02 11:06:41 +00:00
|
|
|
const saveChangedSettings = () => {
|
|
|
|
|
const settingsKeyLength = Object.keys(props.settings).length;
|
|
|
|
|
const isOnlyEnvSettings =
|
|
|
|
|
updatedTenantSettings.length === 0 && settingsKeyLength !== 0;
|
|
|
|
|
const isEnvAndTenantSettings =
|
|
|
|
|
updatedTenantSettings.length !== 0 &&
|
|
|
|
|
updatedTenantSettings.length !== settingsKeyLength;
|
|
|
|
|
if (isOnlyEnvSettings) {
|
|
|
|
|
// only env settings
|
|
|
|
|
dispatch(saveSettings(props.settings));
|
|
|
|
|
} else {
|
|
|
|
|
// only tenant settings
|
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
|
2023-06-02 11:06:41 +00:00
|
|
|
const config: any = {};
|
|
|
|
|
for (const each in props.settings) {
|
2023-06-14 14:09:38 +00:00
|
|
|
if (tenantConfigConnection.includes(each)) {
|
|
|
|
|
config[each] = props.settings[each];
|
2023-06-02 11:06:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dispatch(
|
|
|
|
|
updateTenantConfig({
|
|
|
|
|
tenantConfiguration: config,
|
|
|
|
|
isOnlyTenantSettings: !isEnvAndTenantSettings,
|
2023-07-24 08:03:53 +00:00
|
|
|
needsRefresh: details?.needsRefresh,
|
2023-06-02 11:06:41 +00:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
// both env and tenant settings
|
|
|
|
|
if (isEnvAndTenantSettings) {
|
|
|
|
|
const filteredSettings = Object.keys(props.settings)
|
|
|
|
|
.filter((key) => !isTenantConfig(key))
|
|
|
|
|
.reduce((obj, key) => {
|
|
|
|
|
return Object.assign(obj, {
|
|
|
|
|
[key]: props.settings[key],
|
|
|
|
|
});
|
|
|
|
|
}, {});
|
|
|
|
|
dispatch(saveSettings(filteredSettings));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-11 18:08:46 +00:00
|
|
|
const onSave = () => {
|
2022-04-04 07:07:12 +00:00
|
|
|
if (checkMandatoryFileds()) {
|
2023-05-16 09:04:48 +00:00
|
|
|
if (saveAllowed(props.settings, isFormLoginEnabled, socialLoginList)) {
|
2022-04-27 17:46:24 +00:00
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_SAVE", {
|
|
|
|
|
method: pageTitle,
|
|
|
|
|
});
|
2023-06-02 11:06:41 +00:00
|
|
|
saveChangedSettings();
|
2022-04-04 07:07:12 +00:00
|
|
|
} else {
|
|
|
|
|
saveBlocked();
|
|
|
|
|
}
|
2022-03-02 18:18:50 +00:00
|
|
|
} else {
|
2022-04-27 17:46:24 +00:00
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_ERROR", {
|
|
|
|
|
error: createMessage(MANDATORY_FIELDS_ERROR),
|
|
|
|
|
});
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(createMessage(MANDATORY_FIELDS_ERROR), {
|
|
|
|
|
kind: "error",
|
2022-04-04 07:07:12 +00:00
|
|
|
});
|
2022-03-02 18:18:50 +00:00
|
|
|
}
|
2022-02-11 18:08:46 +00:00
|
|
|
};
|
|
|
|
|
|
2022-04-04 07:07:12 +00:00
|
|
|
const checkMandatoryFileds = () => {
|
|
|
|
|
const requiredFields = settingsDetails.filter((eachSetting) => {
|
|
|
|
|
const isInitialSettingBlank =
|
|
|
|
|
settingsConfig[eachSetting.id]?.toString().trim() === "" ||
|
|
|
|
|
settingsConfig[eachSetting.id] === undefined;
|
|
|
|
|
const isInitialSettingNotBlank = settingsConfig[eachSetting.id];
|
2022-04-05 08:24:43 +00:00
|
|
|
const isNewSettingBlank =
|
|
|
|
|
settings[eachSetting.id]?.toString()?.trim() === "";
|
2022-04-04 07:07:12 +00:00
|
|
|
const isNewSettingNotBlank = !settings[eachSetting.id];
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
eachSetting.isRequired &&
|
|
|
|
|
!eachSetting.isHidden &&
|
|
|
|
|
((isInitialSettingBlank && isNewSettingNotBlank) ||
|
|
|
|
|
(isInitialSettingNotBlank && isNewSettingBlank))
|
|
|
|
|
) {
|
|
|
|
|
return eachSetting.id;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return !(requiredFields.length > 0);
|
|
|
|
|
};
|
|
|
|
|
|
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
|
2022-04-28 09:16:38 +00:00
|
|
|
const onClear = (event?: React.FocusEvent<any, any>) => {
|
|
|
|
|
if (event?.type === "click") {
|
|
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_RESET", {
|
|
|
|
|
method: pageTitle,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-11 18:08:46 +00:00
|
|
|
_.forEach(props.settingsConfig, (value, settingName) => {
|
|
|
|
|
const setting = AdminConfig.settingsMap[settingName];
|
2023-03-06 16:46:32 +00:00
|
|
|
if (
|
|
|
|
|
setting &&
|
|
|
|
|
(setting.controlType == SettingTypes.TOGGLE ||
|
|
|
|
|
setting.controlType == SettingTypes.CHECKBOX)
|
|
|
|
|
) {
|
2022-06-24 09:52:44 +00:00
|
|
|
const settingsStr = props.settingsConfig[settingName].toString();
|
|
|
|
|
if (settingName.toLowerCase().includes("enable")) {
|
|
|
|
|
props.settingsConfig[settingName] =
|
|
|
|
|
settingsStr === "" || settingsStr === "true";
|
|
|
|
|
} else {
|
|
|
|
|
props.settingsConfig[settingName] = settingsStr === "true";
|
|
|
|
|
}
|
2022-02-11 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
props.initialize(props.settingsConfig);
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-24 09:52:44 +00:00
|
|
|
useEffect(onClear, [subCategory]);
|
2022-02-11 18:08:46 +00:00
|
|
|
|
|
|
|
|
const onReleaseNotesClose = useCallback(() => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.TOGGLE_RELEASE_NOTES,
|
|
|
|
|
payload: false,
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2022-03-02 18:18:50 +00:00
|
|
|
const saveBlocked = () => {
|
2022-04-28 09:16:38 +00:00
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_ERROR", {
|
|
|
|
|
error: createMessage(DISCONNECT_AUTH_ERROR),
|
|
|
|
|
});
|
2023-05-19 18:37:06 +00:00
|
|
|
toast.show(createMessage(DISCONNECT_AUTH_ERROR), {
|
|
|
|
|
kind: "error",
|
2022-03-02 18:18:50 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disconnect = (currentSettings: AdminConfig) => {
|
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
|
2022-03-02 18:18:50 +00:00
|
|
|
const updatedSettings: any = {};
|
2023-04-30 06:22:42 +00:00
|
|
|
const connectedMethodsCount =
|
2023-05-16 09:04:48 +00:00
|
|
|
socialLoginList.length + (isFormLoginEnabled ? 1 : 0);
|
2023-04-30 06:22:42 +00:00
|
|
|
if (connectedMethodsCount >= 2) {
|
2022-03-02 18:18:50 +00:00
|
|
|
_.forEach(currentSettings, (setting: Setting) => {
|
2023-03-14 06:11:52 +00:00
|
|
|
if (
|
|
|
|
|
!setting.isHidden &&
|
|
|
|
|
[
|
2023-08-28 15:37:32 +00:00
|
|
|
SettingTypes.CALLOUT,
|
2023-03-14 06:11:52 +00:00
|
|
|
SettingTypes.ACCORDION,
|
|
|
|
|
SettingTypes.UNEDITABLEFIELD,
|
|
|
|
|
].indexOf(setting.controlType) === -1
|
|
|
|
|
) {
|
2022-03-02 18:18:50 +00:00
|
|
|
updatedSettings[setting.id] = "";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
dispatch(saveSettings(updatedSettings));
|
2022-04-27 17:46:24 +00:00
|
|
|
AnalyticsUtil.logEvent("ADMIN_SETTINGS_DISCONNECT_AUTH_METHOD", {
|
|
|
|
|
method: pageTitle,
|
|
|
|
|
});
|
2022-03-02 18:18:50 +00:00
|
|
|
} else {
|
|
|
|
|
saveBlocked();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-11 18:08:46 +00:00
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
2022-07-12 13:31:11 +00:00
|
|
|
{subCategory && <BackButton />}
|
2022-02-11 18:08:46 +00:00
|
|
|
<SettingsFormWrapper>
|
2023-05-19 18:37:06 +00:00
|
|
|
<HeaderWrapper>
|
|
|
|
|
<SettingsHeader
|
|
|
|
|
color="var(--ads-v2-color-fg-emphasis-plus)"
|
|
|
|
|
kind="heading-l"
|
|
|
|
|
renderAs="h1"
|
|
|
|
|
>
|
|
|
|
|
{pageTitle}
|
|
|
|
|
</SettingsHeader>
|
|
|
|
|
{details?.subText && (
|
|
|
|
|
<SettingsSubHeader
|
|
|
|
|
color="var(--ads-v2-color-fg-emphasis)"
|
|
|
|
|
kind="body-m"
|
|
|
|
|
renderAs="h2"
|
|
|
|
|
>
|
|
|
|
|
{details.subText}
|
|
|
|
|
</SettingsSubHeader>
|
2022-08-27 14:27:10 +00:00
|
|
|
)}
|
2023-05-19 18:37:06 +00:00
|
|
|
</HeaderWrapper>
|
|
|
|
|
<Group
|
|
|
|
|
category={category}
|
|
|
|
|
settings={settingsDetails}
|
|
|
|
|
subCategory={subCategory}
|
|
|
|
|
/>
|
|
|
|
|
{isSavable && (
|
|
|
|
|
<SaveAdminSettings
|
2023-07-24 08:03:53 +00:00
|
|
|
isOnlyTenantConfig={isOnlyTenantConfig}
|
2023-05-19 18:37:06 +00:00
|
|
|
isSaving={props.isSaving}
|
2023-07-24 08:03:53 +00:00
|
|
|
needsRefresh={details?.needsRefresh}
|
2023-05-19 18:37:06 +00:00
|
|
|
onClear={onClear}
|
|
|
|
|
onSave={onSave}
|
|
|
|
|
settings={props.settings}
|
2023-06-02 11:06:41 +00:00
|
|
|
updatedTenantSettings={updatedTenantSettings}
|
2023-05-19 18:37:06 +00:00
|
|
|
valid={props.valid}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{details?.isConnected && (
|
|
|
|
|
<DisconnectService
|
|
|
|
|
disconnect={() => disconnect(settingsDetails)}
|
|
|
|
|
subHeader={createMessage(DISCONNECT_SERVICE_SUBHEADER)}
|
|
|
|
|
warning={`${pageTitle} ${createMessage(
|
|
|
|
|
DISCONNECT_SERVICE_WARNING,
|
|
|
|
|
)}`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<BottomSpace />
|
2022-02-11 18:08:46 +00:00
|
|
|
</SettingsFormWrapper>
|
|
|
|
|
{props.showReleaseNotes && (
|
|
|
|
|
<ProductUpdatesModal hideTrigger isOpen onClose={onReleaseNotesClose} />
|
|
|
|
|
)}
|
|
|
|
|
<RestartBanner />
|
|
|
|
|
</Wrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2022-02-11 18:08:46 +00:00
|
|
|
const validate = (values: Record<string, any>) => {
|
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
|
2022-02-11 18:08:46 +00:00
|
|
|
const errors: any = {};
|
|
|
|
|
_.filter(values, (value, name) => {
|
2022-03-04 06:26:12 +00:00
|
|
|
const err_message = AdminConfig.validate(name, value);
|
|
|
|
|
if (err_message) {
|
|
|
|
|
errors[name] = err_message;
|
2022-02-11 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return errors;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selector = formValueSelector(SETTINGS_FORM_NAME);
|
|
|
|
|
export default withRouter(
|
|
|
|
|
connect((state: AppState) => {
|
|
|
|
|
const settingsConfig = getSettings(state);
|
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
|
2022-02-11 18:08:46 +00:00
|
|
|
const newProps: any = {
|
|
|
|
|
settings: {},
|
|
|
|
|
settingsConfig,
|
|
|
|
|
isSaving: getSettingsSavingState(state),
|
|
|
|
|
showReleaseNotes: getShowReleaseNotes(state),
|
|
|
|
|
};
|
|
|
|
|
_.forEach(AdminConfig.settingsMap, (setting, name) => {
|
|
|
|
|
const fieldValue = selector(state, name);
|
2023-05-23 17:00:20 +00:00
|
|
|
const doNotUpdate =
|
|
|
|
|
setting.controlType === SettingTypes.CHECKBOX &&
|
|
|
|
|
!settingsConfig[name] &&
|
|
|
|
|
!fieldValue;
|
2023-10-10 09:24:28 +00:00
|
|
|
//We are not performing type check here as inputs we take are stored as string
|
|
|
|
|
//But server stores as numeric, string etc..
|
|
|
|
|
if (fieldValue != settingsConfig[name] && !doNotUpdate) {
|
2022-02-11 18:08:46 +00:00
|
|
|
newProps.settings[name] = fieldValue;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return newProps;
|
|
|
|
|
}, null)(
|
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
|
2022-02-11 18:08:46 +00:00
|
|
|
reduxForm<any, any>({
|
|
|
|
|
validate,
|
|
|
|
|
form: SETTINGS_FORM_NAME,
|
|
|
|
|
touchOnBlur: true,
|
|
|
|
|
})(SettingsForm),
|
|
|
|
|
),
|
|
|
|
|
);
|