Skip to content

Commit

Permalink
[mattermostGH-24745] Convert ./components/admin_console/setting.tsx f…
Browse files Browse the repository at this point in the history
…rom Class Component to Function Component (mattermost#24861)

* fix: convert admin_console/setting.tsx to FC

* fix: update failing snapshots
  • Loading branch information
umrkhn authored Nov 6, 2023
1 parent 83e06a6 commit caa87ec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with multi
]
}
>
<Settings
<Memo(Settings)
helpText="Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
Expand Down Expand Up @@ -88,7 +88,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with multi
</div>
</div>
</div>
</Settings>
</Memo(Settings)>
</CustomURLSchemesSetting>
`;

Expand Down Expand Up @@ -138,7 +138,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no it
setByEnv={false}
value={Array []}
>
<Settings
<Memo(Settings)
helpText="Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
Expand Down Expand Up @@ -174,7 +174,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no it
</div>
</div>
</div>
</Settings>
</Memo(Settings)>
</CustomURLSchemesSetting>
`;

Expand Down Expand Up @@ -228,7 +228,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with one i
]
}
>
<Settings
<Memo(Settings)
helpText="Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
Expand Down Expand Up @@ -264,7 +264,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with one i
</div>
</div>
</div>
</Settings>
</Memo(Settings)>
</CustomURLSchemesSetting>
`;

Expand Down Expand Up @@ -319,7 +319,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when di
]
}
>
<Settings
<Memo(Settings)
helpText="Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
Expand Down Expand Up @@ -355,7 +355,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when di
</div>
</div>
</div>
</Settings>
</Memo(Settings)>
</CustomURLSchemesSetting>
`;

Expand Down Expand Up @@ -410,7 +410,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when se
]
}
>
<Settings
<Memo(Settings)
helpText="Allows message text to link if it begins with any of the comma-separated URL schemes listed. By default, the following schemes will create links: \\"http\\", \\"https\\", \\"ftp\\", \\"tel\\", and \\"mailto\\"."
inputId="MySetting"
label="Custom URL Schemes:"
Expand Down Expand Up @@ -460,6 +460,6 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when se
</SetByEnv>
</div>
</div>
</Settings>
</Memo(Settings)>
</CustomURLSchemesSetting>
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/admin_console/RadioSetting should match snapshot 1`] = `
<Settings
<Memo(Settings)
inputId="string.id"
label="some label"
setByEnv={false}
Expand Down Expand Up @@ -54,5 +54,5 @@ exports[`components/admin_console/RadioSetting should match snapshot 1`] = `
this is administration
</label>
</div>
</Settings>
</Memo(Settings)>
`;
56 changes: 24 additions & 32 deletions webapp/channels/src/components/admin_console/setting.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React, {PureComponent} from 'react';
import React from 'react';

import SetByEnv from './set_by_env';

Expand All @@ -13,38 +13,30 @@ export type Props = {
setByEnv?: boolean;
}

export default class Settings extends PureComponent<Props> {
public render() {
const {
children,
setByEnv,
helpText,
inputId,
label,
} = this.props;

return (
<div
data-testid={inputId}
className='form-group'
const Settings = ({children, setByEnv, helpText, inputId, label}: Props) => {
return (
<div
data-testid={inputId}
className='form-group'
>
<label
className='control-label col-sm-4'
htmlFor={inputId}
>
<label
className='control-label col-sm-4'
htmlFor={inputId}
{label}
</label>
<div className='col-sm-8'>
{children}
<div
data-testid={inputId + 'help-text'}
className='help-text'
>
{label}
</label>
<div className='col-sm-8'>
{children}
<div
data-testid={inputId + 'help-text'}
className='help-text'
>
{helpText}
</div>
{setByEnv ? <SetByEnv/> : null}
{helpText}
</div>
{setByEnv ? <SetByEnv/> : null}
</div>
);
}
}
</div>
);
};

export default React.memo(Settings);

0 comments on commit caa87ec

Please sign in to comment.