Skip to content

Commit

Permalink
fix: featuresPreview wrong DB structure (#34209)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti authored Dec 18, 2024
1 parent 9521463 commit be2ede4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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

0 comments on commit be2ede4

Please sign in to comment.