Client: LDAP: add disabled restore button

This commit is contained in:
Viktor Fomin 2024-06-03 16:30:57 +03:00
parent 4108f56f52
commit df689ba855
2 changed files with 36 additions and 9 deletions

View File

@ -11,6 +11,7 @@ const ButtonContainer = ({
isLdapEnabled,
isLdapAvailable,
hasChanges,
isDefaultSettings,
}) => {
const { t } = useTranslation(["Settings", "Common"]);
@ -33,7 +34,7 @@ const ButtonContainer = ({
hasScroll={true}
hideBorder={true}
saveButtonDisabled={!isLdapAvailable || !isLdapEnabled || !hasChanges}
cancelEnable
disableRestoreToDefault={isDefaultSettings}
showReminder
additionalClassSaveButton="ldap-save"
additionalClassCancelButton="ldap-reset"
@ -43,7 +44,13 @@ const ButtonContainer = ({
};
export default inject(({ currentQuotaStore, ldapStore }) => {
const { save, restoreToDefault, isLdapEnabled, hasChanges } = ldapStore;
const {
save,
restoreToDefault,
isLdapEnabled,
hasChanges,
isDefaultSettings,
} = ldapStore;
const { isLdapAvailable } = currentQuotaStore;
return {
@ -52,5 +59,6 @@ export default inject(({ currentQuotaStore, ldapStore }) => {
isLdapEnabled,
isLdapAvailable,
hasChanges,
isDefaultSettings,
};
})(observer(ButtonContainer));

View File

@ -84,6 +84,8 @@ class LdapFormStore {
};
defaultSettings = {};
serverData = {};
serverSettings = {};
constructor() {
makeAutoObservable(this);
@ -91,6 +93,7 @@ class LdapFormStore {
mapSettings = (data) => {
console.log("LDAP settings data", data);
this.serverData = data;
const {
enableLdapAuthentication,
@ -158,7 +161,7 @@ class LdapFormStore {
this.login = login;
this.password = password || "";
this.setDefaultSettings();
this.setServerSettings();
};
mapCron = (cron) => {
@ -167,10 +170,18 @@ class LdapFormStore {
this.setCron(cronWithoutSeconds);
};
mapDefaultSettings = (data) => {
delete data.ldapMapping.LocationAttribute;
delete data.ldapMapping.MobilePhoneAttribute;
delete data.ldapMapping.TitleAttribute;
this.defaultSettings = data;
};
load = async () => {
const [settingsRes, cronRes] = await Promise.allSettled([
const [settingsRes, cronRes, defaultRes] = await Promise.allSettled([
getLdapSettings(),
getCronLdap(),
getLdapDefaultSettings(),
]);
if (settingsRes.status == "fulfilled") this.mapSettings(settingsRes.value);
@ -179,6 +190,10 @@ class LdapFormStore {
this.mapCron(cronRes.value?.cron);
}
if (defaultRes.status == "fulfilled") {
this.mapDefaultSettings(defaultRes.value);
}
this.isLoaded = true;
//TDOD: handle error
};
@ -343,7 +358,7 @@ class LdapFormStore {
const settings = this.getSettings();
const respose = await saveLdapSettings(settings);
this.defaultSettings = settings;
this.setServerSettings();
if (respose?.id) {
this.inProgress = true;
@ -472,7 +487,7 @@ class LdapFormStore {
status.certificateConfirmRequest.requested
) {
setCertificateDetails(status.certificateConfirmRequest);
currentSettings = previousSettings;
// currentSettings = previousSettings;
return true;
}
@ -590,9 +605,9 @@ class LdapFormStore {
return !this.progressStatus.source;
}
setDefaultSettings = () => {
setServerSettings = () => {
const settings = this.getSettings();
this.defaultSettings = settings;
this.serverSettings = settings;
};
getSettings = () => {
@ -631,7 +646,11 @@ class LdapFormStore {
get hasChanges() {
const settings = this.getSettings();
return !isEqual(settings, this.defaultSettings);
return !isEqual(settings, this.serverSettings);
}
get isDefaultSettings() {
return isEqual(this.serverData, this.defaultSettings);
}
}