[GH-24745] Convert ./components/admin_console/setting.tsx from Class Component to Function Component (#24861)

* fix: convert admin_console/setting.tsx to FC

* fix: update failing snapshots
This commit is contained in:
Umar Abid 2023-11-06 17:22:16 +05:00 committed by GitHub
parent 83e06a65a6
commit caa87ec7f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 44 deletions

View File

@ -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\\"." 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" inputId="MySetting"
label="Custom URL Schemes:" label="Custom URL Schemes:"
@ -88,7 +88,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with multi
</div> </div>
</div> </div>
</div> </div>
</Settings> </Memo(Settings)>
</CustomURLSchemesSetting> </CustomURLSchemesSetting>
`; `;
@ -138,7 +138,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no it
setByEnv={false} setByEnv={false}
value={Array []} 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\\"." 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" inputId="MySetting"
label="Custom URL Schemes:" label="Custom URL Schemes:"
@ -174,7 +174,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with no it
</div> </div>
</div> </div>
</div> </div>
</Settings> </Memo(Settings)>
</CustomURLSchemesSetting> </CustomURLSchemesSetting>
`; `;
@ -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\\"." 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" inputId="MySetting"
label="Custom URL Schemes:" label="Custom URL Schemes:"
@ -264,7 +264,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting initial state with one i
</div> </div>
</div> </div>
</div> </div>
</Settings> </Memo(Settings)>
</CustomURLSchemesSetting> </CustomURLSchemesSetting>
`; `;
@ -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\\"." 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" inputId="MySetting"
label="Custom URL Schemes:" label="Custom URL Schemes:"
@ -355,7 +355,7 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when di
</div> </div>
</div> </div>
</div> </div>
</Settings> </Memo(Settings)>
</CustomURLSchemesSetting> </CustomURLSchemesSetting>
`; `;
@ -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\\"." 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" inputId="MySetting"
label="Custom URL Schemes:" label="Custom URL Schemes:"
@ -460,6 +460,6 @@ exports[`components/AdminConsole/CustomUrlSchemeSetting renders properly when se
</SetByEnv> </SetByEnv>
</div> </div>
</div> </div>
</Settings> </Memo(Settings)>
</CustomURLSchemesSetting> </CustomURLSchemesSetting>
`; `;

View File

@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/admin_console/RadioSetting should match snapshot 1`] = ` exports[`components/admin_console/RadioSetting should match snapshot 1`] = `
<Settings <Memo(Settings)
inputId="string.id" inputId="string.id"
label="some label" label="some label"
setByEnv={false} setByEnv={false}
@ -54,5 +54,5 @@ exports[`components/admin_console/RadioSetting should match snapshot 1`] = `
this is administration this is administration
</label> </label>
</div> </div>
</Settings> </Memo(Settings)>
`; `;

View File

@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import React, {PureComponent} from 'react'; import React from 'react';
import SetByEnv from './set_by_env'; import SetByEnv from './set_by_env';
@ -13,38 +13,30 @@ export type Props = {
setByEnv?: boolean; setByEnv?: boolean;
} }
export default class Settings extends PureComponent<Props> { const Settings = ({children, setByEnv, helpText, inputId, label}: Props) => {
public render() { return (
const { <div
children, data-testid={inputId}
setByEnv, className='form-group'
helpText, >
inputId, <label
label, className='control-label col-sm-4'
} = this.props; htmlFor={inputId}
return (
<div
data-testid={inputId}
className='form-group'
> >
<label {label}
className='control-label col-sm-4' </label>
htmlFor={inputId} <div className='col-sm-8'>
{children}
<div
data-testid={inputId + 'help-text'}
className='help-text'
> >
{label} {helpText}
</label>
<div className='col-sm-8'>
{children}
<div
data-testid={inputId + 'help-text'}
className='help-text'
>
{helpText}
</div>
{setByEnv ? <SetByEnv/> : null}
</div> </div>
{setByEnv ? <SetByEnv/> : null}
</div> </div>
); </div>
} );
} };
export default React.memo(Settings);