fix
This commit is contained in:
168
src/App.js
168
src/App.js
@@ -1,5 +1,5 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import { useQuery, gql } from '@apollo/client';
|
||||
import {useQuery, gql, useMutation} from '@apollo/client';
|
||||
import {useNavigate, Route, Routes, useParams} from "react-router-dom";
|
||||
import {Mutation} from "@apollo/client/react/components";
|
||||
|
||||
@@ -11,6 +11,13 @@ const GET_BNDS = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
const GET_BND = gql`
|
||||
query getUser($id: Int!) {
|
||||
user(id: $id) {
|
||||
users
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const GET_QUEUE = gql`
|
||||
query getQueue {
|
||||
@@ -34,7 +41,7 @@ function DisplayBnds() {
|
||||
<input type={"checkbox"} disabled={true} checked={user.newbnd}/> новый БнД –
|
||||
<input type={"checkbox"} disabled={true} checked={user.active}/> активный –
|
||||
<input type={"checkbox"} disabled={true} checked={user.upstream}/> вышестоящий –
|
||||
<a href={"/delbnd/" + user.id}>X</a>
|
||||
<a href={"/delbnd/" + user.id}>X</a> <a href={"/bnd/" + user.id}>E</a>
|
||||
</p>
|
||||
</div>;
|
||||
}
|
||||
@@ -45,6 +52,7 @@ function DisplayBnds() {
|
||||
<div>
|
||||
<a href={"/newbnd"}>Новый банк данных</a><br/>
|
||||
<a href={"/queue"}>Очередь</a><br/>
|
||||
<a href={"/send"}>Отправить коммит</a><br/>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
@@ -75,6 +83,8 @@ function DisplayQueue() {
|
||||
}
|
||||
|
||||
function BndForm() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return <Mutation
|
||||
mutation={gql`
|
||||
mutation createUser($passwd: String!, $username: String!){
|
||||
@@ -93,7 +103,9 @@ function BndForm() {
|
||||
createUser({ variables: {
|
||||
username: username.value ,
|
||||
passwd: passwd.value ,
|
||||
}});
|
||||
}}).then(() => {
|
||||
navigate("/");
|
||||
});
|
||||
}}>
|
||||
username <input
|
||||
type='text'
|
||||
@@ -114,9 +126,20 @@ function DeleteBnd() {
|
||||
const {id} = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const DEL_BND = gql`
|
||||
mutation removeBnd($id: Int!) {
|
||||
removeUser(id_: $id)
|
||||
}
|
||||
`;
|
||||
const [removeUser, { data, loading, error }] = useMutation(DEL_BND)
|
||||
|
||||
useEffect(() => {
|
||||
console.log(id);
|
||||
navigate("/");
|
||||
removeUser({
|
||||
variables: {id: parseInt(id)}
|
||||
}).then(() => {
|
||||
navigate("/");
|
||||
})
|
||||
|
||||
}, []);
|
||||
return <h3>Del BND</h3>;
|
||||
}
|
||||
@@ -126,14 +149,134 @@ function BndEdit() {
|
||||
const {id} = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
console.log(id);
|
||||
navigate("/");
|
||||
}, []);
|
||||
return <h3>Del BND</h3>;
|
||||
const { loading, error, data } = useQuery(GET_BND, {variables: {id: parseInt(id)}});
|
||||
|
||||
if (loading) return <p>Loading...</p>;
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return <p>Error :(</p>;
|
||||
}
|
||||
const bnd = JSON.parse(data.user.users);
|
||||
|
||||
return <Mutation
|
||||
mutation={gql`
|
||||
mutation updateUser($id: Int!, $bndname: String!, $newbnd: Boolean!, $active: Boolean!, $upstream: Boolean!,
|
||||
$passwd: String!, $username: String!) {
|
||||
updateUser(id_: $id, bndname: $bndname, newbnd: $newbnd, active: $active, upstream: $upstream,
|
||||
passwd: $passwd, username: $username)
|
||||
}
|
||||
`}
|
||||
>
|
||||
{(updateUser, { loading, error, data }) => {
|
||||
if (loading) return <p>Loading...</p>;
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return <p>Error :(</p>;
|
||||
}
|
||||
let username, passwd, bndname, isActive, isNew, isUpstream
|
||||
|
||||
return (
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
await updateUser({ variables: {
|
||||
id: parseInt(id),
|
||||
username: username.value,
|
||||
bndname: username.value,
|
||||
active: isActive.checked,
|
||||
newbnd: isNew.checked,
|
||||
upstream: isUpstream.checked,
|
||||
passwd: passwd.value,
|
||||
}});
|
||||
navigate("/");
|
||||
}}>
|
||||
username <input
|
||||
type='text'
|
||||
ref={ node => username = node }
|
||||
defaultValue={bnd.username}
|
||||
/><br/>
|
||||
bndname <input
|
||||
type='text'
|
||||
ref={ node => bndname = node }
|
||||
defaultValue={bnd.bndname}
|
||||
/><br/>
|
||||
password <input
|
||||
type='password'
|
||||
ref={ node => passwd = node }
|
||||
defaultValue={bnd.passwd}
|
||||
/><br/>
|
||||
active <input
|
||||
type='checkbox'
|
||||
ref={ node => isActive = node }
|
||||
defaultChecked={bnd.active}
|
||||
/><br/>
|
||||
new <input
|
||||
type='checkbox'
|
||||
ref={ node => isNew = node }
|
||||
defaultChecked={bnd.newbnd}
|
||||
/><br/>
|
||||
upstream bnd <input
|
||||
type='checkbox'
|
||||
ref={ node => isUpstream = node }
|
||||
defaultChecked={bnd.upstream}
|
||||
/><br/>
|
||||
<button type='submit'>Обновить</button>
|
||||
</form>
|
||||
);
|
||||
}}
|
||||
</Mutation>;
|
||||
}
|
||||
|
||||
function BndProfiles() {
|
||||
const {id} = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { loading, error, data } = useQuery(GET_BND, {variables: {id: parseInt(id)}});
|
||||
|
||||
if (loading) return <p>Loading...</p>;
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return <p>Error :(</p>;
|
||||
}
|
||||
const bnd = JSON.parse(data.user.users);
|
||||
const res = bnd.profiles.map((x) => {
|
||||
return <div>
|
||||
<p>Схема: {x.scheme}</p>
|
||||
<p>Ветка: {x.branch}</p>
|
||||
<hr/>
|
||||
</div>;
|
||||
})
|
||||
|
||||
return <div>
|
||||
<h4>Профили БНД {bnd.bndname}</h4>
|
||||
{res}
|
||||
<div>
|
||||
<a href={"profiles/new"}>Создать</a>
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
|
||||
function SendCommit() {
|
||||
let commit_id, bndname
|
||||
|
||||
return <form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
console.log(commit_id.value)
|
||||
}}>
|
||||
commit id <input
|
||||
type='text'
|
||||
ref={node => commit_id = node}
|
||||
/><br/>
|
||||
bndname <input
|
||||
type='text'
|
||||
ref={node => bndname = node}
|
||||
/><br/>
|
||||
<button type='submit'>Обновить</button>
|
||||
</form>;
|
||||
}
|
||||
|
||||
function StartCorrectingReplication() {
|
||||
return <div></div>;
|
||||
}
|
||||
|
||||
|
||||
export default function App() {
|
||||
@@ -144,7 +287,12 @@ export default function App() {
|
||||
<Route path={"/queue"} element={<DisplayQueue/>}/>
|
||||
<Route path={"/newbnd"} element={<BndForm/>}/>
|
||||
<Route path={"/delbnd/:id"} element={<DeleteBnd/>}/>
|
||||
<Route path={"/bnd/:id/profiles"} element={<BndProfiles/>}/>
|
||||
<Route path={"/bnd/:id/schedule"} element={<BndProfiles/>}/>
|
||||
<Route path={"/bnd/:id/incoming"} element={<BndProfiles/>}/>
|
||||
<Route path={"/bnd/:id"} element={<BndEdit/>}/>
|
||||
<Route path={"/scr"} element={<StartCorrectingReplication/>}/>
|
||||
<Route path={"/send"} element={<SendCommit/>}/>
|
||||
</Routes>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user