Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: featuresPreview wrong DB structure #34209

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/violet-pets-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/ui-client': patch
'@rocket.chat/meteor': patch
---

Fixed the data structure of the features preview
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ const AccountFeaturePreviewPage = () => {
const { featuresPreview } = watch();

const handleSave = async () => {
const featuresToBeSaved = featuresPreview.map((feature) => ({ name: feature.name, value: feature.value }));
try {
await setUserPreferences({ data: { featuresPreview } });
await setUserPreferences({ data: { featuresPreview: featuresToBeSaved } });
dispatchToastMessage({ type: 'success', message: t('Preferences_saved') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
Expand Down
12 changes: 9 additions & 3 deletions packages/ui-client/src/hooks/useFeaturePreviewList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ export const parseSetting = (setting?: FeaturePreviewProps[] | string) => {
return setting;
};

export const useFeaturePreviewList = (featuresList: Pick<FeaturePreviewProps, 'name' | 'value'>[]) => {
export const useFeaturePreviewList = (featuresList: FeaturePreviewProps[]) => {
const unseenFeatures = enabledDefaultFeatures.filter(
(defaultFeature) => !featuresList?.find((feature) => feature.name === defaultFeature.name),
).length;

const mergedFeatures = enabledDefaultFeatures.map((defaultFeature) => {
const features = featuresList?.find((feature) => feature.name === defaultFeature.name);
return { ...defaultFeature, ...features };
const feature = featuresList?.find((feature) => feature.name === defaultFeature.name);
// overwrite enableQuery and disabled with default value to avoid a migration to remove this from the DB
// payload on save now only have `name` and `value`
if (feature) {
feature.enableQuery = defaultFeature.enableQuery;
feature.disabled = defaultFeature.disabled;
}
return { ...defaultFeature, ...feature };
});

return { unseenFeatures, features: mergedFeatures };
Expand Down
Loading