Skip to content

Commit

Permalink
chore: Settings files sanitization (#33057)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris authored Aug 19, 2024
1 parent 7e2facc commit 5d657ee
Show file tree
Hide file tree
Showing 79 changed files with 305 additions and 307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { ReactElement } from 'react';
import React, { useState } from 'react';
import { Controller, useForm } from 'react-hook-form';

import StringSettingInput from '../../views/admin/settings/inputs/StringSettingInput';
import StringSettingInput from '../../views/admin/settings/Setting/inputs/StringSettingInput';

export type PriorityFormData = { name: string; reset: boolean };

Expand Down
26 changes: 0 additions & 26 deletions apps/meteor/client/views/admin/settings/GroupPage.stories.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions apps/meteor/client/views/admin/settings/GroupSelector.stories.tsx

This file was deleted.

43 changes: 0 additions & 43 deletions apps/meteor/client/views/admin/settings/GroupSelector.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions apps/meteor/client/views/admin/settings/Section.stories.tsx

This file was deleted.

59 changes: 0 additions & 59 deletions apps/meteor/client/views/admin/settings/Setting.stories.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ResetSettingButton';
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { FieldGroup } from '@rocket.chat/fuselage';
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import React from 'react';

import MemoizedSetting from './MemoizedSetting';
import Setting from './Setting';
import SettingSkeleton from './SettingSkeleton';

export default {
title: 'Admin/Settings/Setting',
component: Setting,
parameters: {
layout: 'centered',
actions: {
argTypesRegex: '^on.*',
},
},
decorators: [
(fn) => (
<div className='rc-old'>
<div className='page-settings'>{fn()}</div>
</div>
),
],
} as ComponentMeta<typeof Setting>;

export const Default: ComponentStory<typeof MemoizedSetting> = (args) => <MemoizedSetting {...args} />;
Default.args = {
_id: 'setting-id',
label: 'Label',
hint: 'Hint',
};

export const WithCallout: ComponentStory<typeof MemoizedSetting> = (args) => <MemoizedSetting {...args} />;
WithCallout.args = {
_id: 'setting-id',
label: 'Label',
hint: 'Hint',
callout: 'Callout text',
};

export const types = () => (
<FieldGroup>
<MemoizedSetting packageValue _id='setting-id-1' label='Label' type='action' actionText='Action text' />
<MemoizedSetting packageValue='' _id='setting-id-2' label='Label' type='asset' />
<MemoizedSetting packageValue _id='setting-id-3' label='Label' type='boolean' />
<MemoizedSetting packageValue='' _id='setting-id-4' label='Label' type='code' />
<MemoizedSetting packageValue='' _id='setting-id-5' label='Label' type='font' />
<MemoizedSetting packageValue={1} _id='setting-id-6' label='Label' type='int' />
<MemoizedSetting packageValue='' _id='setting-id-7' label='Label' type='language' />
<MemoizedSetting packageValue='' _id='setting-id-8' label='Label' type='password' />
<MemoizedSetting packageValue='' _id='setting-id-9' label='Label' type='relativeUrl' />
<MemoizedSetting packageValue='' _id='setting-id-10' label='Label' type='select' />
<MemoizedSetting packageValue='' _id='setting-id-11' label='Label' type='string' />
</FieldGroup>
);

export const Skeleton = () => <SettingSkeleton />;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { useSettingStructure, useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useEffect, useMemo, useState, useCallback } from 'react';

import MarkdownText from '../../../components/MarkdownText';
import { useEditableSetting, useEditableSettingsDispatch, useIsEnterprise } from '../EditableSettingsContext';
import MarkdownText from '../../../../components/MarkdownText';
import { useEditableSetting, useEditableSettingsDispatch, useIsEnterprise } from '../../EditableSettingsContext';
import MemoizedSetting from './MemoizedSetting';
import SettingSkeleton from './SettingSkeleton';

type SettingProps = {
className?: string;
Expand Down Expand Up @@ -165,7 +164,4 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr
);
}

export default Object.assign(Setting, {
Memoized: MemoizedSetting,
Skeleton: SettingSkeleton,
});
export default Setting;
1 change: 1 addition & 0 deletions apps/meteor/client/views/admin/settings/Setting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Setting';
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function CodeMirror({
const setupCodeMirror = async (): Promise<void> => {
const CodeMirror = await import('codemirror');
await Promise.all([
import('../../../../../../app/ui/client/lib/codeMirror/codeMirror'),
import('../../../../../../../app/ui/client/lib/codeMirror/codeMirror'),
import('codemirror/addon/edit/matchbrackets'),
import('codemirror/addon/edit/closebrackets'),
import('codemirror/addon/edit/matchtags'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { PathPattern } from '@rocket.chat/rest-typings';
import type { ReactElement } from 'react';
import React from 'react';

import type { AsyncState } from '../../../../hooks/useAsyncState';
import { useEndpointData } from '../../../../hooks/useEndpointData';
import type { AsyncState } from '../../../../../hooks/useAsyncState';
import { useEndpointData } from '../../../../../hooks/useEndpointData';
import ResetSettingButton from '../ResetSettingButton';
import type { SettingInputProps } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Field, FieldLabel, FieldRow } from '@rocket.chat/fuselage';
import type { ReactElement } from 'react';
import React from 'react';

import RoomAutoCompleteMultiple from '../../../../components/RoomAutoCompleteMultiple';
import RoomAutoCompleteMultiple from '../../../../../components/RoomAutoCompleteMultiple';
import ResetSettingButton from '../ResetSettingButton';
import type { SettingInputProps } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';

import { TIMEUNIT } from '../../../../lib/convertTimeUnit';
import { TIMEUNIT } from '../../../../../lib/convertTimeUnit';
import { default as TimespanSettingInput, getHighestTimeUnit } from './TimespanSettingInput';

global.ResizeObserver = jest.fn().mockImplementation(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
import type { FormEventHandler, ReactElement } from 'react';
import React, { useMemo, useState } from 'react';

import { TIMEUNIT, timeUnitToMs, msToTimeUnit } from '../../../../lib/convertTimeUnit';
import { TIMEUNIT, timeUnitToMs, msToTimeUnit } from '../../../../../lib/convertTimeUnit';
import ResetSettingButton from '../ResetSettingButton';
import type { SettingInputProps } from './types';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import React from 'react';

import SettingsGroupPage from './SettingsGroupPage';
import SettingsGroupPageSkeleton from './SettingsGroupPageSkeleton';

export default {
title: 'Admin/Settings/SettingsGroupPage',
component: SettingsGroupPage,
parameters: {
layout: 'fullscreen',
controls: { hideNoControlsWarning: true },
},
} as ComponentMeta<typeof SettingsGroupPage>;

export const Default: ComponentStory<typeof SettingsGroupPage> = (args) => <SettingsGroupPage {...args} />;

export const WithGroup: ComponentStory<typeof SettingsGroupPage> = (args) => <SettingsGroupPage {...args} />;
WithGroup.args = {
_id: 'General',
i18nLabel: 'General',
};

export const Skeleton: ComponentStory<typeof SettingsGroupPageSkeleton> = () => <SettingsGroupPageSkeleton />;
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { useToastMessageDispatch, useSettingsDispatch, useSettings, useTranslati
import type { ReactNode, FormEvent, MouseEvent } from 'react';
import React, { useMemo, memo } from 'react';

import { Page, PageHeader, PageScrollableContentWithShadow, PageFooter } from '../../../components/Page';
import type { EditableSetting } from '../EditableSettingsContext';
import { useEditableSettingsDispatch, useEditableSettings } from '../EditableSettingsContext';
import GroupPageSkeleton from './GroupPageSkeleton';
import { Page, PageHeader, PageScrollableContentWithShadow, PageFooter } from '../../../../components/Page';
import type { EditableSetting } from '../../EditableSettingsContext';
import { useEditableSettingsDispatch, useEditableSettings } from '../../EditableSettingsContext';

type GroupPageProps = {
type SettingsGroupPageProps = {
children: ReactNode;
headerButtons?: ReactNode;
onClickBack?: () => void;
Expand All @@ -22,7 +21,7 @@ type GroupPageProps = {
isCustom?: boolean;
};

const GroupPage = ({
const SettingsGroupPage = ({
children = undefined,
headerButtons = undefined,
onClickBack,
Expand All @@ -31,7 +30,7 @@ const GroupPage = ({
i18nDescription = undefined,
tabs = undefined,
isCustom = false,
}: GroupPageProps) => {
}: SettingsGroupPageProps) => {
const t = useTranslation();
const dispatch = useSettingsDispatch();
const dispatchToastMessage = useToastMessageDispatch();
Expand Down Expand Up @@ -133,7 +132,6 @@ const GroupPage = ({
return <Page>{children}</Page>;
}

// The settings
const isTranslationKey = (key: string): key is TranslationKey => (key as TranslationKey) !== undefined;

return (
Expand Down Expand Up @@ -178,6 +176,4 @@ const GroupPage = ({
);
};

export default Object.assign(memo(GroupPage), {
Skeleton: GroupPageSkeleton,
});
export default memo(SettingsGroupPage);
Loading

0 comments on commit 5d657ee

Please sign in to comment.