-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds new admin feature preview setting management (#33212)
Co-authored-by: Guilherme Gazzo <[email protected]>
- Loading branch information
1 parent
a6b9152
commit 1f89f78
Showing
27 changed files
with
324 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/i18n": minor | ||
"@rocket.chat/ui-client": minor | ||
--- | ||
|
||
Added new Admin Feature Preview management view, this will allow the workspace admins to both enable feature previewing in the workspace as well as define which feature previews are enabled by default for the users in the workspace. |
4 changes: 2 additions & 2 deletions
4
apps/meteor/client/NavBarV2/NavBarSettingsToolbar/UserMenu/hooks/useAccountItems.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { FeaturePreviewProps } from '@rocket.chat/ui-client'; | ||
import { useMemo } from 'react'; | ||
|
||
const handleFeaturePreviewEnableQuery = (item: FeaturePreviewProps, _: any, features: FeaturePreviewProps[]) => { | ||
if (item.enableQuery) { | ||
const expected = item.enableQuery.value; | ||
const received = features.find((el) => el.name === item.enableQuery?.name)?.value; | ||
if (expected !== received) { | ||
item.disabled = true; | ||
item.value = false; | ||
} else { | ||
item.disabled = false; | ||
} | ||
} | ||
return item; | ||
}; | ||
|
||
const groupFeaturePreview = (features: FeaturePreviewProps[]) => | ||
Object.entries( | ||
features.reduce((result, currentValue) => { | ||
(result[currentValue.group] = result[currentValue.group] || []).push(currentValue); | ||
return result; | ||
}, {} as Record<FeaturePreviewProps['group'], FeaturePreviewProps[]>), | ||
); | ||
|
||
export const useFeaturePreviewEnableQuery = (features: FeaturePreviewProps[]) => { | ||
return useMemo(() => groupFeaturePreview(features.map(handleFeaturePreviewEnableQuery)), [features]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
apps/meteor/client/views/account/featurePreview/AccountFeaturePreviewBadge.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { | ||
ButtonGroup, | ||
Button, | ||
Box, | ||
ToggleSwitch, | ||
Accordion, | ||
Field, | ||
FieldGroup, | ||
FieldLabel, | ||
FieldRow, | ||
FieldHint, | ||
Callout, | ||
Margins, | ||
} from '@rocket.chat/fuselage'; | ||
import { useDefaultSettingFeaturePreviewList } from '@rocket.chat/ui-client'; | ||
import type { TranslationKey } from '@rocket.chat/ui-contexts'; | ||
import { useToastMessageDispatch, useTranslation, useSettingsDispatch } from '@rocket.chat/ui-contexts'; | ||
import type { ChangeEvent } from 'react'; | ||
import React, { Fragment } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import { Page, PageHeader, PageScrollableContentWithShadow, PageFooter } from '../../../components/Page'; | ||
import { useFeaturePreviewEnableQuery } from '../../../hooks/useFeaturePreviewEnableQuery'; | ||
import { useEditableSetting } from '../EditableSettingsContext'; | ||
import Setting from '../settings/Setting'; | ||
import SettingsGroupPageSkeleton from '../settings/SettingsGroupPage/SettingsGroupPageSkeleton'; | ||
|
||
const AdminFeaturePreviewPage = () => { | ||
const t = useTranslation(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
const allowFeaturePreviewSetting = useEditableSetting('Accounts_AllowFeaturePreview'); | ||
const { features } = useDefaultSettingFeaturePreviewList(); | ||
|
||
const { | ||
watch, | ||
formState: { isDirty }, | ||
setValue, | ||
handleSubmit, | ||
reset, | ||
} = useForm({ | ||
defaultValues: { featuresPreview: features }, | ||
}); | ||
const { featuresPreview } = watch(); | ||
const dispatch = useSettingsDispatch(); | ||
|
||
const handleSave = async () => { | ||
try { | ||
const featuresToBeSaved = featuresPreview.map((feature) => ({ name: feature.name, value: feature.value })); | ||
|
||
await dispatch([ | ||
{ _id: allowFeaturePreviewSetting!._id, value: allowFeaturePreviewSetting!.value }, | ||
{ _id: 'Accounts_Default_User_Preferences_featuresPreview', value: JSON.stringify(featuresToBeSaved) }, | ||
]); | ||
dispatchToastMessage({ type: 'success', message: t('Preferences_saved') }); | ||
} catch (error) { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
} finally { | ||
reset({ featuresPreview }); | ||
} | ||
}; | ||
|
||
const handleFeatures = (e: ChangeEvent<HTMLInputElement>) => { | ||
const updated = featuresPreview.map((item) => (item.name === e.target.name ? { ...item, value: e.target.checked } : item)); | ||
setValue('featuresPreview', updated, { shouldDirty: true }); | ||
}; | ||
|
||
const grouppedFeaturesPreview = useFeaturePreviewEnableQuery(featuresPreview); | ||
|
||
if (!allowFeaturePreviewSetting) { | ||
// TODO: Implement FeaturePreviewSkeleton component | ||
return <SettingsGroupPageSkeleton />; | ||
} | ||
|
||
return ( | ||
<Page> | ||
<PageHeader title={t('Feature_preview')} /> | ||
<PageScrollableContentWithShadow> | ||
<Box maxWidth='x600' w='full' alignSelf='center'> | ||
<Box> | ||
<Margins block={24}> | ||
<Box fontScale='p1'>{t('Feature_preview_admin_page_description')}</Box> | ||
<Callout>{t('Feature_preview_page_callout')}</Callout> | ||
<Callout>{t('Feature_preview_admin_page_callout')}</Callout> | ||
<Setting settingId='Accounts_AllowFeaturePreview' sectionChanged={allowFeaturePreviewSetting.changed} /> | ||
</Margins> | ||
</Box> | ||
<Accordion> | ||
{grouppedFeaturesPreview?.map(([group, features], index) => ( | ||
<Accordion.Item defaultExpanded={index === 0} key={group} title={t(group as TranslationKey)}> | ||
<FieldGroup> | ||
{features.map((feature) => ( | ||
<Fragment key={feature.name}> | ||
<Field> | ||
<FieldRow> | ||
<FieldLabel htmlFor={feature.name}>{t(feature.i18n)}</FieldLabel> | ||
<ToggleSwitch | ||
id={feature.name} | ||
checked={feature.value} | ||
name={feature.name} | ||
onChange={handleFeatures} | ||
disabled={feature.disabled || !allowFeaturePreviewSetting.value} | ||
/> | ||
</FieldRow> | ||
{feature.description && <FieldHint mbs={12}>{t(feature.description)}</FieldHint>} | ||
</Field> | ||
{feature.imageUrl && <Box is='img' width='100%' height='auto' mbs={16} src={feature.imageUrl} alt='' />} | ||
</Fragment> | ||
))} | ||
</FieldGroup> | ||
</Accordion.Item> | ||
))} | ||
</Accordion> | ||
</Box> | ||
</PageScrollableContentWithShadow> | ||
<PageFooter isDirty={isDirty || allowFeaturePreviewSetting.changed}> | ||
<ButtonGroup> | ||
<Button onClick={() => reset({ featuresPreview: features })}>{t('Cancel')}</Button> | ||
<Button primary disabled={!(isDirty || allowFeaturePreviewSetting.changed)} onClick={handleSubmit(handleSave)}> | ||
{t('Save_changes')} | ||
</Button> | ||
</ButtonGroup> | ||
</PageFooter> | ||
</Page> | ||
); | ||
}; | ||
|
||
export default AdminFeaturePreviewPage; |
26 changes: 26 additions & 0 deletions
26
apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewRoute.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { usePermission } from '@rocket.chat/ui-contexts'; | ||
import type { ReactElement } from 'react'; | ||
import React, { memo } from 'react'; | ||
|
||
import SettingsProvider from '../../../providers/SettingsProvider'; | ||
import NotAuthorizedPage from '../../notAuthorized/NotAuthorizedPage'; | ||
import EditableSettingsProvider from '../settings/EditableSettingsProvider'; | ||
import AdminFeaturePreviewPage from './AdminFeaturePreviewPage'; | ||
|
||
const AdminFeaturePreviewRoute = (): ReactElement => { | ||
const canViewFeaturesPreview = usePermission('manage-cloud'); | ||
|
||
if (!canViewFeaturesPreview) { | ||
return <NotAuthorizedPage />; | ||
} | ||
|
||
return ( | ||
<SettingsProvider privileged> | ||
<EditableSettingsProvider> | ||
<AdminFeaturePreviewPage /> | ||
</EditableSettingsProvider> | ||
</SettingsProvider> | ||
); | ||
}; | ||
|
||
export default memo(AdminFeaturePreviewRoute); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.66 KB
apps/meteor/public/images/featurePreview/resizable-contextual-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.