Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
tidy debugs, rename setting to Parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Kerry Archibald <kerrya@element.io>
  • Loading branch information
Kerry Archibald committed Jan 27, 2022
1 parent 3146317 commit 63f3559
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/components/views/dialogs/ExportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const validateNumberInRange = (min: number, max: number) => (value?: string | nu
};

// Sanitize setting values, exclude invalid or missing values
export type ForceRoomExportSettings = {
export type ForceRoomExportParameters = {
format?: ExportFormat; range?: ExportType; numberOfMessages?: number; includeAttachments?: boolean; sizeMb?: number;
};
export const getSafeForceRoomExportSettings = (): ForceRoomExportSettings => {
const config = SettingsStore.getValue<ForceRoomExportSettings>(UIFeature.ForceRoomExportSettings);
export const getSafeForceRoomExportParameters = (): ForceRoomExportParameters => {
const config = SettingsStore.getValue<ForceRoomExportParameters>(UIFeature.ForceRoomExportParameters);
if (!config || typeof config !== "object") return {};

const { format, range, numberOfMessages, includeAttachments, sizeMb } = config;
Expand Down Expand Up @@ -90,12 +90,12 @@ interface ExportConfig {
}

/**
* Set up form state using UIFeature.ForceRoomExportSettings or defaults
* Form fields configured in ForceRoomExportSettings are not allowed to be edited
* Set up form state using UIFeature.ForceRoomExportParameters or defaults
* Form fields configured in ForceRoomExportParameters are not allowed to be edited
* Only return change handlers for editable values
*/
const useExportFormState = (): ExportConfig => {
const config = getSafeForceRoomExportSettings();
const config = getSafeForceRoomExportParameters();

const [exportFormat, setExportFormat] = useState(config.format || ExportFormat.Html);
const [exportType, setExportType] = useState(config.range || ExportType.Timeline);
Expand Down
2 changes: 1 addition & 1 deletion src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ export const SETTINGS: {[setting: string]: ISetting} = {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.ForceRoomExportSettings]: {
[UIFeature.ForceRoomExportParameters]: {
supportedLevels: LEVELS_UI_FEATURE,
default: {},
},
Expand Down
2 changes: 1 addition & 1 deletion src/settings/UIFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export enum UIFeature {
AdvancedSettings = "UIFeature.advancedSettings",
RoomHistorySettings = "UIFeature.roomHistorySettings",
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates",
ForceRoomExportSettings = "UIFeature.forceRoomExportSettings"
ForceRoomExportParameters = "UIFeature.ForceRoomExportParameters"
}

export enum UIComponent {
Expand Down
22 changes: 11 additions & 11 deletions test/components/views/dialogs/ExportDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { act } from "react-dom/test-utils";
import { Room } from 'matrix-js-sdk';

import ExportDialog,
{ getSafeForceRoomExportSettings, ForceRoomExportSettings }
{ getSafeForceRoomExportParameters, ForceRoomExportParameters }
from '../../../../src/components/views/dialogs/ExportDialog';
import { ExportType, ExportFormat } from '../../../../src/utils/exportUtils/exportUtils';
import { createTestClient, mkStubRoom } from '../../../test-utils';
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('<ExportDialog />', () => {
expect(htmlExporterInstance.export).toHaveBeenCalled();
});

it('exports room using values set from ForceRoomExportSettings', async () => {
it('exports room using values set from ForceRoomExportParameters', async () => {
SettingsStoreMock.getValue.mockReturnValue({
format: ExportFormat.PlainText,
range: ExportType.Beginning,
Expand Down Expand Up @@ -188,12 +188,12 @@ describe('<ExportDialog />', () => {
expect(getExportFormatInput(component, ExportFormat.Html).props().checked).toBeFalsy();
});

it('hides export format input when format is valid in ForceRoomExportSettings', () => {
it('hides export format input when format is valid in ForceRoomExportParameters', () => {
const component = getComponent();
expect(getExportFormatInput(component, ExportFormat.Html).props().checked).toBeTruthy();
});

it('does not render export format when set in ForceRoomExportSettings', () => {
it('does not render export format when set in ForceRoomExportParameters', () => {
SettingsStoreMock.getValue.mockReturnValue({
format: ExportFormat.PlainText,
});
Expand All @@ -214,7 +214,7 @@ describe('<ExportDialog />', () => {
expect(getExportTypeInput(component).props().value).toEqual(ExportType.Beginning);
});

it('does not render export type when set in ForceRoomExportSettings', () => {
it('does not render export type when set in ForceRoomExportParameters', () => {
SettingsStoreMock.getValue.mockReturnValue({
range: ExportType.Beginning,
});
Expand Down Expand Up @@ -305,7 +305,7 @@ describe('<ExportDialog />', () => {
expect(htmlExporterInstance.export).toHaveBeenCalled();
});

it('does not render size limit input when set in ForceRoomExportSettings', () => {
it('does not render size limit input when set in ForceRoomExportParameters', () => {
SettingsStoreMock.getValue.mockReturnValue({
sizeMb: 10000,
});
Expand All @@ -316,7 +316,7 @@ describe('<ExportDialog />', () => {
/**
* 2000mb size limit does not apply when higher limit is configured in config
*/
it('exports when size limit set in ForceRoomExportSettings is larger than 2000', async () => {
it('exports when size limit set in ForceRoomExportParameters is larger than 2000', async () => {
SettingsStoreMock.getValue.mockReturnValue({
sizeMb: 10000,
});
Expand All @@ -339,7 +339,7 @@ describe('<ExportDialog />', () => {
expect(getAttachmentsCheckbox(component).props().checked).toEqual(true);
});

it('does not render input when set in ForceRoomExportSettings', () => {
it('does not render input when set in ForceRoomExportParameters', () => {
SettingsStoreMock.getValue.mockReturnValue({
includeAttachments: false,
});
Expand All @@ -348,8 +348,8 @@ describe('<ExportDialog />', () => {
});
});

describe('getSafeForceRoomExportSettings()', () => {
const testCases: [string, ForceRoomExportSettings, ForceRoomExportSettings][] = [
describe('getSafeForceRoomExportParameters()', () => {
const testCases: [string, ForceRoomExportParameters, ForceRoomExportParameters][] = [
['setting is falsy', undefined, {}],
['setting is configured to string', 'test' as unknown, {}],
['setting is empty', {}, {}],
Expand All @@ -373,7 +373,7 @@ describe('<ExportDialog />', () => {
it.each(testCases)('sanitizes correctly when %s', (_d, setting, expected) => {
SettingsStoreMock.getValue.mockReturnValue(setting);

expect(getSafeForceRoomExportSettings()).toEqual(expected);
expect(getSafeForceRoomExportParameters()).toEqual(expected);
});
});
});
Expand Down

0 comments on commit 63f3559

Please sign in to comment.