mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[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:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user