Skip to content

Commit

Permalink
fix: Enforce download path change if featureStatus is not changed (#1…
Browse files Browse the repository at this point in the history
…6623)

* feat: show modal if feature status unchanged

* fix: test/functionality
  • Loading branch information
tlebon committed Jan 24, 2024
1 parent 7f41783 commit 734ef89
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@
"featureConfigChangeModalAudioVideoHeadline": "There has been a change in {{brandName}}",
"featureConfigChangeModalDownloadPathDisabled": "Enforced Download Path is disabled. You will need to restart the app if you want to save downloads in a new location.",
"featureConfigChangeModalDownloadPathEnabled": "Enforced Download Path is enabled. The App will restart for the new settings to take effect.",
"featureConfigChangeModalDownloadPathChanged": "Enforced Download Path location is changed. The App will restart for the new settings to take effect.",
"featureConfigChangeModalDownloadPathHeadline": "There has been a change in {{brandName}}",
"featureConfigChangeModalConferenceCallingEnabled": "Your team was upgraded to {{brandName}} Enterprise, which gives you access to features such as conference calls and more. [link]Learn more about {{brandName}} Enterprise[/link]",
"featureConfigChangeModalConferenceCallingTitle": "{{brandName}} Enterprise",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import {act, render, waitFor} from '@testing-library/react';
import {FeatureStatus, FEATURE_KEY, FeatureList} from '@wireapp/api-client/lib/team/feature';
import {Runtime} from '@wireapp/commons/lib/util/Runtime';

import {PrimaryModal} from 'Components/Modals/PrimaryModal';
import en from 'I18n/en-US.json';
Expand All @@ -36,6 +37,8 @@ describe('FeatureConfigChangeNotifier', () => {
beforeEach(() => {
showModalSpy.mockClear();
localStorage.clear();
jest.spyOn(Runtime, 'isDesktopApp').mockReturnValue(true);
jest.spyOn(Runtime, 'isWindows').mockReturnValue(true);
});

const baseConfig: FeatureList = {
Expand Down Expand Up @@ -95,6 +98,7 @@ describe('FeatureConfigChangeNotifier', () => {
...baseConfig,
[feature]: {
status: FeatureStatus.ENABLED,
...(feature === FEATURE_KEY.ENFORCE_DOWNLOAD_PATH && {config: {enforcedDownloadLocation: 'dlpath'}}),
},
});
});
Expand All @@ -116,6 +120,7 @@ describe('FeatureConfigChangeNotifier', () => {
...baseConfig,
[feature]: {
status: FeatureStatus.DISABLED,
...(feature === FEATURE_KEY.ENFORCE_DOWNLOAD_PATH && {config: {enforcedDownloadLocation: ''}}),
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,42 @@ const featureNotifications: Partial<
};
},
[FEATURE_KEY.ENFORCE_DOWNLOAD_PATH]: (oldConfig, newConfig) => {
const status = wasTurnedOnOrOff(oldConfig, newConfig);
if (!status) {
return undefined;
}
if (newConfig && 'config' in newConfig) {
if (
newConfig &&
'config' in newConfig &&
oldConfig &&
'config' in oldConfig &&
newConfig?.config?.enforcedDownloadLocation !== oldConfig?.config?.enforcedDownloadLocation &&
Runtime.isDesktopApp() &&
Runtime.isWindows()
) {
const status = wasTurnedOnOrOff(oldConfig, newConfig);
const configStatus = newConfig?.config?.enforcedDownloadLocation !== oldConfig?.config?.enforcedDownloadLocation;
if (!status && !configStatus) {
return undefined;
}
amplify.publish(
WebAppEvents.TEAM.DOWNLOAD_PATH_UPDATE,
newConfig.status === FeatureStatus.ENABLED ? newConfig.config.enforcedDownloadLocation : undefined,
);
}
return {
htmlMessage:
status === FeatureStatus.ENABLED
? t('featureConfigChangeModalDownloadPathEnabled')
: t('featureConfigChangeModalDownloadPathDisabled'),
title: 'featureConfigChangeModalDownloadPathHeadline',
primaryAction: {
action: () => {
if (Runtime.isDesktopApp() && status === FeatureStatus.ENABLED) {
// if we are in a desktop env, we just warn the wrapper that we need to reload. It then decide what should be done
amplify.publish(WebAppEvents.LIFECYCLE.RESTART);
}
return {
htmlMessage:
status === FeatureStatus.ENABLED
? t('featureConfigChangeModalDownloadPathEnabled')
: status === FeatureStatus.DISABLED
? t('featureConfigChangeModalDownloadPathDisabled')
: t('featureConfigChangeModalDownloadPathChanged'),
title: 'featureConfigChangeModalDownloadPathHeadline',
primaryAction: {
action: () => {
if (Runtime.isDesktopApp() && status !== FeatureStatus.DISABLED) {
amplify.publish(WebAppEvents.LIFECYCLE.RESTART);
}
},
},
},
};
};
}
return undefined;
},
[FEATURE_KEY.SELF_DELETING_MESSAGES]: (oldConfig, newConfig) => {
if (!oldConfig || !('config' in oldConfig) || !newConfig || !('config' in newConfig)) {
Expand Down

0 comments on commit 734ef89

Please sign in to comment.