Skip to content

Commit

Permalink
fix: remove unused variables
Browse files Browse the repository at this point in the history
  • Loading branch information
luigibarbato committed Mar 15, 2023
1 parent e7a7d08 commit c174368
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
16 changes: 8 additions & 8 deletions web-client/src/components/edit-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function EditUser({ user }: EditUserParameters) {
}, [refreshRbacData])

useEffect(() => {
let { rbs, crbs, extractedPairItems } = extractUsersRoles(roleBindings, clusterRoleBindings, username);
let { extractedPairItems } = extractUsersRoles(roleBindings, clusterRoleBindings, username);

if (extractedPairItems.length === 0) {
setRoleBindingNotFound(true);
Expand All @@ -65,12 +65,12 @@ export default function EditUser({ user }: EditUserParameters) {

// we proceed to bootstrap aggregatedRoleBindings
setAggregatedRoleBindings(extractedPairItems)
}, [roleBindings, clusterRoleBindings])
}, [roleBindings, username, clusterRoleBindings])

useEffect(() => {
setCanCheckLegacyUser(true);

let { rbs, crbs, extractedPairItems } = extractUsersRoles(roleBindings, clusterRoleBindings, username);
let { crbs } = extractUsersRoles(roleBindings, clusterRoleBindings, username);

// we bootstrap clusterRoleBinding value.
const clusterRoleBinding = crbs.find(crb => crb.metadata.name.includes(templateClusterResourceRolePrefix))
Expand All @@ -92,7 +92,7 @@ export default function EditUser({ user }: EditUserParameters) {
}

setClusterAccess(clusterBindingAccessValue)
}, [roleBindings, clusterRoleBindings, initialClusterAccess])
}, [roleBindings, username, clusterRoleBindings, initialClusterAccess])

useEffect(() => {
async function checkLegacyUser(): Promise<boolean> {
Expand Down Expand Up @@ -135,7 +135,7 @@ export default function EditUser({ user }: EditUserParameters) {
* delete all the user-resources currently in the k8s cluster
*/
async function deleteUserResources() {
let { rbs, crbs, extractedPairItems } = extractUsersRoles(roleBindings, clusterRoleBindings, username);
let { rbs, crbs } = extractUsersRoles(roleBindings, clusterRoleBindings, username);

await httpRequests.rolebindingRequests.delete.rolebinding(rbs);
await httpRequests.rolebindingRequests.delete.clusterRolebinding(crbs);
Expand Down Expand Up @@ -189,12 +189,12 @@ export default function EditUser({ user }: EditUserParameters) {
username={username}></LegacyUserModal>
}
{roleBindingNotFound && (
<div className="flex items-center m-10 bg-red-200 rounded-lg p-5 justify-items-center">
<div className="flex items-center m-10 bg-red-200 rounded-lg p-5 justify-items-center" role='alert'>
<div className="flex flex-col content-around">
<p className='text-gray-700 font-bold uppercase text-xs'>Error</p>
<p className="p-2">Permission Manager can't retrieve the user's permissions. This is usually caused by a manual action on the cluster. <strong>Try to recreate the permissions</strong></p>
</div>
<span className="bg-red-300 py-1 px-2 rounded hover:shadow text-gray-700 font-bold uppercase text-md">
<span className="bg-red-300 py-1 px-2 rounded hover:shadow text-gray-700 font-bold uppercase text-md" role='img' aria-label='alert'>
⚠️
</span>
</div>
Expand All @@ -209,7 +209,7 @@ export default function EditUser({ user }: EditUserParameters) {
type="button"
className="bg-transparent hover:bg-red-600 text-gray-700 hover:text-gray-100 py-1 px-2 rounded hover:shadow ml-2 text-xs"
onClick={() => {
const confirmed = window.confirm(
const confirmed = window.confirm(
`Confirm deletion of User ${username}`
)

Expand Down
35 changes: 16 additions & 19 deletions web-client/src/components/new-user-wizard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, {useCallback, useEffect, useState} from 'react'
import uuid from 'uuid'
import {useHistory} from 'react-router-dom'
import React, { useCallback, useEffect, useState } from 'react'
import { useHistory } from 'react-router-dom'
import ClusterAccessRadio from './ClusterAccessRadio'
import Templates from './Templates'
import {FullScreenLoader} from './Loader'
import { FullScreenLoader } from './Loader'
import Summary from './Summary'
import {useUsers} from '../hooks/useUsers'
import {AggregatedRoleBinding} from "../services/role";
import {ClusterAccess} from "./types";
import {httpRequests} from "../services/httpRequests";
import { useUsers } from '../hooks/useUsers'
import { AggregatedRoleBinding } from "../services/role";
import { ClusterAccess } from "./types";
import { httpRequests } from "../services/httpRequests";


export interface AggregatedRoleBindingManager {
Expand All @@ -28,7 +27,7 @@ export default function NewUserWizard() {
const [clusterAccess, setClusterAccess] = useState<ClusterAccess>('none')
const [formTouched, setFormTouched] = useState<boolean>(false)
const [showLoader, setShowLoader] = useState<boolean>(false)
const {users} = useUsers()
const { users } = useUsers()

const validateUsername = useCallback(() => {
if (username.length < 3) {
Expand Down Expand Up @@ -104,14 +103,14 @@ export default function NewUserWizard() {
}, [])

const addEmptyPair = useCallback(() => {
setAggregatedRoleBindings(state => [...state, {id: '', namespaces: [], template: ''}])
setAggregatedRoleBindings(state => [...state, { id: '', namespaces: [], template: '' }])
}, [])

useEffect(addEmptyPair, [])

return (
<div>
{showLoader && <FullScreenLoader/>}
{showLoader && <FullScreenLoader />}
<h2 className="text-3xl mb-4 text-gray-800">New User</h2>
<form
onSubmit={e => {
Expand All @@ -128,9 +127,8 @@ export default function NewUserWizard() {
<input
autoFocus
placeholder="jane.doe"
className={`appearance-none block w-full text-gray-700 border rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white ${
usernameError && formTouched ? 'border-red-500' : ''
}`}
className={`appearance-none block w-full text-gray-700 border rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white ${usernameError && formTouched ? 'border-red-500' : ''
}`}
required
type="text"
value={username}
Expand Down Expand Up @@ -162,11 +160,10 @@ export default function NewUserWizard() {
setClusterAccess={setClusterAccess}
/>

<hr className="my-6"/>
<hr className="my-6" />
<button
className={`bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded shadow ${
saveButtonDisabled ? ' opacity-50 cursor-not-allowed' : ''
}`}
className={`bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded shadow ${saveButtonDisabled ? ' opacity-50 cursor-not-allowed' : ''
}`}
disabled={saveButtonDisabled}
type="submit"
>
Expand All @@ -177,7 +174,7 @@ export default function NewUserWizard() {

{aggregatedRoleBindings.length > 0 && aggregatedRoleBindings.some(p => p.namespaces.length > 0) ? (
<>
<div className="mt-12 mb-4"/>
<div className="mt-12 mb-4" />
<Summary pairItems={aggregatedRoleBindings}></Summary>
</>
) : null}
Expand Down
9 changes: 4 additions & 5 deletions web-client/src/services/role.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {resourceSeparator, templateClusterResourceRolePrefix} from "../constants";
import uuid from "uuid";
import {ClusterRoleBinding, RoleBinding} from "../hooks/useRbac";
import { resourceSeparator, templateClusterResourceRolePrefix } from "../constants";
import { ClusterRoleBinding, RoleBinding } from "../hooks/useRbac";

type MixedRoleBindings = RoleBinding | ClusterRoleBinding

Expand Down Expand Up @@ -76,7 +75,7 @@ export function extractUsersRoles(roleBindings: RoleBinding[], clusterRoleBindin
const name = mixedRoleBinding.metadata.name
const template = mixedRoleBinding.roleRef.name
const namespace = mixedRoleBinding.metadata['namespace'] || 'ALL_NAMESPACES'
return {template, namespace, name}
return { template, namespace, name }
})

const extractedPairItems: AggregatedRoleBinding[] = normalizedRoleBindings.reduce((acc, item) => {
Expand Down Expand Up @@ -105,5 +104,5 @@ export function extractUsersRoles(roleBindings: RoleBinding[], clusterRoleBindin
return acc
}, [])

return {rbs, crbs, extractedPairItems};
return { rbs, crbs, extractedPairItems };
}

0 comments on commit c174368

Please sign in to comment.