snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import type { ISettingColor, SettingEditor, SettingValue } from '@rocket.chat/core-typings';
|
||||
import { isSettingColor, isSetting } from '@rocket.chat/core-typings';
|
||||
import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { useSettingsDispatch, useSettingStructure } from '@rocket.chat/ui-contexts';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { useEffect, useMemo, useState, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import MarkdownText from '../../../../components/MarkdownText';
|
||||
import { useEditableSetting, useEditableSettingVisibilityQuery } from '../../EditableSettingsContext';
|
||||
import MemoizedSetting from '../../settings/Setting/MemoizedSetting';
|
||||
import { useHasSettingModule } from '../../settings/hooks/useHasSettingModule';
|
||||
|
||||
export type SettingFieldProps = {
|
||||
className?: string;
|
||||
settingId: string;
|
||||
sectionChanged?: boolean;
|
||||
};
|
||||
|
||||
function SettingField({ className = undefined, settingId, sectionChanged }: SettingFieldProps) {
|
||||
const setting = useEditableSetting(settingId);
|
||||
const persistedSetting = useSettingStructure(settingId);
|
||||
const hasSettingModule = useHasSettingModule(setting);
|
||||
|
||||
if (!setting || !persistedSetting) {
|
||||
throw new Error(`Setting ${settingId} not found`);
|
||||
}
|
||||
|
||||
// Checks if setting has at least required fields before doing anything
|
||||
if (!isSetting(setting)) {
|
||||
throw new Error(`Setting ${settingId} is not valid`);
|
||||
}
|
||||
|
||||
const dispatch = useSettingsDispatch();
|
||||
|
||||
const update = useDebouncedCallback(
|
||||
({ value, editor }: { value?: SettingValue; editor?: SettingEditor }) => {
|
||||
if (!persistedSetting) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch([
|
||||
{
|
||||
_id: persistedSetting._id,
|
||||
...(value !== undefined && { value }),
|
||||
...(editor !== undefined && { editor }),
|
||||
},
|
||||
]);
|
||||
},
|
||||
230,
|
||||
[persistedSetting, dispatch],
|
||||
);
|
||||
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
const [value, setValue] = useState(setting.value);
|
||||
const [editor, setEditor] = useState(isSettingColor(setting) ? setting.editor : undefined);
|
||||
|
||||
useEffect(() => {
|
||||
setValue(setting.value);
|
||||
}, [setting.value]);
|
||||
|
||||
useEffect(() => {
|
||||
setEditor(isSettingColor(setting) ? setting.editor : undefined);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [(setting as ISettingColor).editor]);
|
||||
|
||||
const onChangeValue = useCallback(
|
||||
(value: SettingValue) => {
|
||||
setValue(value);
|
||||
update({ value });
|
||||
},
|
||||
[update],
|
||||
);
|
||||
|
||||
const onChangeEditor = useCallback(
|
||||
(editor: SettingEditor) => {
|
||||
setEditor(editor);
|
||||
update({ editor });
|
||||
},
|
||||
[update],
|
||||
);
|
||||
|
||||
const onResetButtonClick = useCallback(() => {
|
||||
setValue(setting.value);
|
||||
setEditor(isSettingColor(setting) ? setting.editor : undefined);
|
||||
update({
|
||||
value: persistedSetting.packageValue,
|
||||
...(isSettingColor(persistedSetting) && { editor: persistedSetting.packageEditor }),
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [setting.value, (setting as ISettingColor).editor, update, persistedSetting]);
|
||||
|
||||
const { _id, readonly, type, packageValue, i18nLabel, i18nDescription, alert } = setting;
|
||||
|
||||
const disabled = !useEditableSettingVisibilityQuery(persistedSetting.enableQuery);
|
||||
const invisible = !useEditableSettingVisibilityQuery(persistedSetting.displayQuery);
|
||||
|
||||
const labelText = (i18n.exists(i18nLabel) && t(i18nLabel)) || (i18n.exists(_id) && t(_id)) || i18nLabel || _id;
|
||||
|
||||
const hint = useMemo(
|
||||
() => (i18nDescription && i18n.exists(i18nDescription) ? <MarkdownText variant='inline' content={t(i18nDescription)} /> : undefined),
|
||||
[i18n, i18nDescription, t],
|
||||
);
|
||||
|
||||
const callout = useMemo(
|
||||
() =>
|
||||
alert && <span dangerouslySetInnerHTML={{ __html: i18n.exists(alert) ? DOMPurify.sanitize(t(alert)) : DOMPurify.sanitize(alert) }} />,
|
||||
[alert, i18n, t],
|
||||
);
|
||||
|
||||
const shouldDisableEnterprise = setting.enterprise && !hasSettingModule;
|
||||
|
||||
const hasResetButton =
|
||||
!shouldDisableEnterprise &&
|
||||
!readonly &&
|
||||
type !== 'asset' &&
|
||||
((isSettingColor(setting) && JSON.stringify(setting.packageEditor) !== JSON.stringify(editor)) ||
|
||||
JSON.stringify(value) !== JSON.stringify(packageValue)) &&
|
||||
!disabled;
|
||||
|
||||
// @todo: type check props based on setting type
|
||||
|
||||
return (
|
||||
<MemoizedSetting
|
||||
className={className}
|
||||
label={labelText}
|
||||
hint={hint}
|
||||
callout={callout}
|
||||
sectionChanged={sectionChanged}
|
||||
{...setting}
|
||||
disabled={disabled || shouldDisableEnterprise}
|
||||
value={value}
|
||||
editor={editor}
|
||||
hasResetButton={hasResetButton}
|
||||
onChangeValue={onChangeValue}
|
||||
onChangeEditor={onChangeEditor}
|
||||
onResetButtonClick={onResetButtonClick}
|
||||
invisible={invisible}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default SettingField;
|
||||
Reference in New Issue
Block a user