Skip to content

Commit

Permalink
feat: user edit view withuot cluster access
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDellaValle committed May 12, 2023
1 parent 0bb94d8 commit 4376af0
Show file tree
Hide file tree
Showing 3 changed files with 661 additions and 66 deletions.
6 changes: 3 additions & 3 deletions web-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import Footer from './components/Footer'
import Home from './views/Home'
import NewUser from './views/NewUser'
import Advanced from './deadcode/views/Advanced'
import EditUser from './views/EditUser'
// import EditUser from './views/EditUser'
import EditUser from './views/EditUserNew'

import UsersList from './views/UsersList';
import CreateUser from './views/CreateUser';
Expand All @@ -22,7 +23,6 @@ import {
QueryClient,
QueryClientProvider,
} from '@tanstack/react-query';
// import { ReactQueryDevtools } from '@tanstack/react-query/devtools';

const queryClient = new QueryClient();

Expand All @@ -48,7 +48,7 @@ export default function App() {
{/* <div style={{ flexGrow: 1, backgroundColor: '#edf2f7' }}> */}
<Switch>
<Route path="/advanced" exact component={Advanced} />
<Route path="/new-user" exact component={NewUser} />
{/* <Route path="/new-user" exact component={NewUser} /> */}
<Route path="/create-new-user" exact component={CreateUser} />
<Route path="/users/:username" exact component={EditUser} />
{/* <Route path="/" exact component={Home} /> */}
Expand Down
78 changes: 15 additions & 63 deletions web-client/src/views/CreateUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ import { useNamespaceList } from '../hooks/useNamespaceList';
import { httpRequests } from '../services/httpRequests';
import { ClusterAccess } from "../components/types";
import { httpClient } from "../services/httpClient";
// import { rolebinding } from "../services/rolebindingCreateRequests";

import { AggregatedRoleBinding } from "../services/role";
import { method } from 'bluebird';
import { Subject, useRbac } from '../hooks/useRbac';
import { ClusterRolebindingCreate } from '../services/rolebindingCreateRequests';

type SummaryItem = {
resource: string,
Expand Down Expand Up @@ -89,24 +84,13 @@ const clusterRoleMap = {
write: 'admin'
};

const templateOptions = [
{
value: 'developer',
inputDisplay: 'Developer',
},
{
value: 'operation',
inputDisplay: 'Operation',
},
];

interface UserCreationParams {
generated_for_user: string,
roleName: string, // params.template,
namespace: string, // params.namespace,
roleKind: string, // params.roleKind,
subjects: Subject[], // params.subjects,
roleBindingName: string,// params.roleBindingName
roleName: string,
namespace: string,
roleKind: string,
subjects: Subject[],
roleBindingName: string,
};

type NamespaceOption = {
Expand Down Expand Up @@ -157,44 +141,16 @@ const CreateUser = () => {
return true

};
// const [aggregatedRoleBindings, setAggregatedRoleBindings] = useState<AggregatedRoleBinding[]>([])


// Queries
// const listUsers = useQuery('testQuery', useUsers)


// Mutations
// const mutation = useMutation(postTodo, {
// onSuccess: () => {
// // Invalidate and refetch
// queryClient.invalidateQueries('todos')
// },
// })

// const observer = new QueryObserver(queryClient, { queryKey: ['posts'] })

// const unsubscribe = observer.subscribe(result => {
// console.log(result)
// unsubscribe()
// })

const history = useHistory();

let usernameDone = false;
let bindingsDone = false;
let clusterBindingsDone = false;

const createUser = useMutation({
mutationFn: (username: string) => {
return httpClient.post('/api/create-user', {name: username});
},
onError(error, variables, context) {
setErrorModal(error.toString());
},
onSuccess() {
usernameDone = true;
},
});

const createRoleBindings = useMutation({
Expand All @@ -204,9 +160,6 @@ const CreateUser = () => {
onError(error, variables, context) {
setErrorModal(error.toString());
},
onSuccess(data, variables, context) {
bindingsDone = true;
},
});

const createClusterRoleBindings = useMutation({
Expand All @@ -216,9 +169,6 @@ const CreateUser = () => {
onError(error, variables, context) {
setErrorModal(error.toString())
},
onSuccess(data, variables, context) {
clusterBindingsDone = true;
},
});

async function handleSubmit(e) {
Expand Down Expand Up @@ -264,13 +214,10 @@ const CreateUser = () => {
console.log('calls done', res);
});

// history.push(`/users/${username}`)

} catch (e) {
setErrorModal(e.toString());
console.error('user creation error', e)
} finally {
console.log('finished')
!errorModal && setSuccessModal(true);
};
};
Expand Down Expand Up @@ -513,7 +460,7 @@ const NameSpaceSelect = (props: any) => {

useEffect(() => {
if (allNamespaces) {
// remove all namespaces and fill with ['all']
// Remove all namespaces and fill with ['all']
setTemplates(templates.map(template => {
if (template.id === templateId) {
return {...template, namespaces: [{value: 'all', label: 'All'}]}
Expand All @@ -522,7 +469,14 @@ const NameSpaceSelect = (props: any) => {
}
}))
} else {
console.log('not all')
// Empty selection
setTemplates(templates.map(template => {
if (template.id === templateId) {
return {...template, namespaces: []}
} else {
return template
}
}))
}
}, [allNamespaces]);

Expand All @@ -534,15 +488,13 @@ const NameSpaceSelect = (props: any) => {
<EuiFormRow label="Namespace">
<>
<EuiComboBox
// async
aria-label="Namespace Selection"
placeholder="Select Namespaces..."
options={isSuccess ? nameSpaceOptions : []}
// TODO: check deletion corner cases
selectedOptions={allNamespaces ? [{label: 'All', value: 'all'}] : (templates.find(t => t.id === templateId)?.namespaces ?? [])}
onChange={onChange}
isDisabled={allNamespaces}
// onCreateOption={() => {}}
isLoading={!nameSpaceOptions}
isClearable={true}
/>
Expand Down Expand Up @@ -593,7 +545,7 @@ const TemplatesSlider = (props: any) => {
setTemplates([...templates, {
id: templates.length + 1,
namespaces: [],
role: templateOptions[0].value,
role: '',
}]);
}}
>
Expand Down
Loading

0 comments on commit 4376af0

Please sign in to comment.