[MM-54818] Convert system_permission_gate.tsx from Class Component to Function Component (#24939)

* Convert class to function for SystemPermissionGate

* refactor into arrow func and destructure props param;

* add newline to file

* indent params, remove space before colon, add semicolon

* Wrap return in empty tags; run fix-style; consolidate multiple IFs into XOR-like condition

* Update with invert=false default param for SystemPermissionGate component

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Erin Akarice
2023-10-30 02:41:42 -07:00
committed by GitHub
parent fb6118c107
commit 7ff635cfb1
2 changed files with 12 additions and 18 deletions

View File

@@ -24,7 +24,6 @@ exports[`components/permissions_gates SystemPermissionGate should match snapshot
<SystemPermissionGate
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_system_permission",
@@ -63,7 +62,6 @@ exports[`components/permissions_gates SystemPermissionGate should match snapshot
<SystemPermissionGate
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_system_permission",
@@ -136,7 +134,6 @@ exports[`components/permissions_gates SystemPermissionGate should match snapshot
<SystemPermissionGate
dispatch={[Function]}
hasPermission={false}
invert={false}
permissions={
Array [
"invalid_permission",

View File

@@ -17,7 +17,7 @@ type Props = {
/**
* Invert the permission (used for else)
*/
invert: boolean;
invert?: boolean;
/**
* Content protected by the permissions gate
@@ -25,18 +25,15 @@ type Props = {
children: React.ReactNode;
};
export default class SystemPermissionGate extends React.PureComponent<Props> {
public static defaultProps = {
invert: false,
};
render() {
if (this.props.hasPermission && !this.props.invert) {
return this.props.children;
}
if (!this.props.hasPermission && this.props.invert) {
return this.props.children;
}
return null;
const SystemPermissionGate = ({
invert = false,
hasPermission,
children,
}: Props) => {
if (hasPermission !== invert) {
return <>{children}</>;
}
}
return null;
};
export default SystemPermissionGate;