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

feat: Introduced section-based accordion groups to the App Settings interface #34121

Merged
merged 7 commits into from
Dec 5, 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
5 changes: 5 additions & 0 deletions .changeset/real-crabs-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Organizes App Settings interface by introducing section-based accordion groups to improve navigation and readability for administrators.
Original file line number Diff line number Diff line change
@@ -1,53 +1,13 @@
import type { ISettingSelectValue } from '@rocket.chat/apps-engine/definition/settings';
import type { ISetting } from '@rocket.chat/apps-engine/definition/settings/ISetting';
import { useRouteParameter, useTranslation } from '@rocket.chat/ui-contexts';
import { useRouteParameter } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useMemo, useCallback } from 'react';
import React, { useMemo } from 'react';
import { Controller, useFormContext } from 'react-hook-form';

import { Utilities } from '../../../../../../ee/lib/misc/Utilities';
import MarkdownText from '../../../../../components/MarkdownText';
import MemoizedSetting from '../../../../admin/settings/Setting/MemoizedSetting';

type AppTranslationFunction = {
(key: string, ...replaces: unknown[]): string;
has: (key: string | undefined) => boolean;
};

const useAppTranslation = (appId: string): AppTranslationFunction => {
const t = useTranslation();

const tApp = useCallback(
(key: string, ...args: unknown[]) => {
if (!key) {
return '';
}
const appKey = Utilities.getI18nKeyForApp(key, appId);

if (t.has(appKey)) {
return t(appKey, ...args);
}
if (t.has(key)) {
return t(key, ...args);
}
return key;
},
[t, appId],
);

return Object.assign(tApp, {
has: useCallback(
(key: string | undefined) => {
if (!key) {
return false;
}

return t.has(Utilities.getI18nKeyForApp(key, appId)) || t.has(key);
},
[t, appId],
),
});
};
import { useAppTranslation } from '../../../hooks/useAppTranslation';

const AppSetting = ({ id, type, i18nLabel, i18nDescription, values, value, packageValue, ...props }: ISetting): ReactElement => {
const appId = useRouteParameter('id');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
import { Box, FieldGroup } from '@rocket.chat/fuselage';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Box, FieldGroup, Accordion, AccordionItem } from '@rocket.chat/fuselage';
import { useRouteParameter } from '@rocket.chat/ui-contexts';
import React, { useMemo } from 'react';

import AppSetting from './AppSetting';
import type { ISettings } from '../../../../../apps/@types/IOrchestrator';
import { useAppTranslation } from '../../../hooks/useAppTranslation';

const AppSettings = ({ settings }: { settings: ISettings }) => {
const { t } = useTranslation();
const appId = useRouteParameter('id');
const tApp = useAppTranslation(appId || '');

const groupedSettings = useMemo(() => {
const groups = Object.values(settings).reduce(
(acc, setting) => {
const section = setting.section || 'general';
if (!acc[section]) {
acc[section] = [];
}
acc[section].push(setting);
return acc;
},
{} as Record<string, (typeof settings)[keyof typeof settings][]>,
);

return Object.entries(groups);
}, [settings]);

return (
<>
<Box display='flex' flexDirection='column' maxWidth='x640' w='full' marginInline='auto'>
<Box fontScale='h4' mb={12}>
{t('Settings')}
</Box>
<FieldGroup>
{Object.values(settings).map((field) => (
<AppSetting key={field.id} {...field} />
))}
</FieldGroup>
</Box>
</>
<Box display='flex' flexDirection='column' maxWidth='x640' w='full' marginInline='auto'>
<Accordion>
{groupedSettings.map(([section, sectionSettings], index) => (
<AccordionItem key={section} title={tApp(section)} defaultExpanded={index === 0}>
<FieldGroup>
{sectionSettings.map((field) => (
<AppSetting key={field.id} {...field} />
))}
</FieldGroup>
</AccordionItem>
))}
</Accordion>
</Box>
);
};

Expand Down
44 changes: 44 additions & 0 deletions apps/meteor/client/views/marketplace/hooks/useAppTranslation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import { useCallback } from 'react';

import { Utilities } from '../../../../ee/lib/misc/Utilities';

type AppTranslationFunction = {
(key: string, ...replaces: unknown[]): string;
has: (key: string | undefined) => boolean;
};

export const useAppTranslation = (appId: string): AppTranslationFunction => {
const t = useTranslation();

const tApp = useCallback(
(key: string, ...args: unknown[]) => {
if (!key) {
return '';
}
const appKey = Utilities.getI18nKeyForApp(key, appId);

if (t.has(appKey)) {
return t(appKey, ...args);
}
if (t.has(key)) {
return t(key, ...args);
}
return key;
},
[t, appId],
);

return Object.assign(tApp, {
has: useCallback(
(key: string | undefined) => {
if (!key) {
return false;
}

return t.has(Utilities.getI18nKeyForApp(key, appId)) || t.has(key);
},
[t, appId],
),
});
};
Loading