fix
This commit is contained in:
164
src/App.js
164
src/App.js
@@ -1,5 +1,5 @@
|
|||||||
import React, {useEffect, useState} from 'react';
|
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 {useNavigate, Route, Routes, useParams} from "react-router-dom";
|
||||||
import {Mutation} from "@apollo/client/react/components";
|
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`
|
const GET_QUEUE = gql`
|
||||||
query getQueue {
|
query getQueue {
|
||||||
@@ -34,7 +41,7 @@ function DisplayBnds() {
|
|||||||
<input type={"checkbox"} disabled={true} checked={user.newbnd}/> новый БнД –
|
<input type={"checkbox"} disabled={true} checked={user.newbnd}/> новый БнД –
|
||||||
<input type={"checkbox"} disabled={true} checked={user.active}/> активный –
|
<input type={"checkbox"} disabled={true} checked={user.active}/> активный –
|
||||||
<input type={"checkbox"} disabled={true} checked={user.upstream}/> вышестоящий –
|
<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>
|
</p>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
@@ -45,6 +52,7 @@ function DisplayBnds() {
|
|||||||
<div>
|
<div>
|
||||||
<a href={"/newbnd"}>Новый банк данных</a><br/>
|
<a href={"/newbnd"}>Новый банк данных</a><br/>
|
||||||
<a href={"/queue"}>Очередь</a><br/>
|
<a href={"/queue"}>Очередь</a><br/>
|
||||||
|
<a href={"/send"}>Отправить коммит</a><br/>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
@@ -75,6 +83,8 @@ function DisplayQueue() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function BndForm() {
|
function BndForm() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return <Mutation
|
return <Mutation
|
||||||
mutation={gql`
|
mutation={gql`
|
||||||
mutation createUser($passwd: String!, $username: String!){
|
mutation createUser($passwd: String!, $username: String!){
|
||||||
@@ -93,7 +103,9 @@ function BndForm() {
|
|||||||
createUser({ variables: {
|
createUser({ variables: {
|
||||||
username: username.value ,
|
username: username.value ,
|
||||||
passwd: passwd.value ,
|
passwd: passwd.value ,
|
||||||
}});
|
}}).then(() => {
|
||||||
|
navigate("/");
|
||||||
|
});
|
||||||
}}>
|
}}>
|
||||||
username <input
|
username <input
|
||||||
type='text'
|
type='text'
|
||||||
@@ -114,9 +126,20 @@ function DeleteBnd() {
|
|||||||
const {id} = useParams();
|
const {id} = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const DEL_BND = gql`
|
||||||
|
mutation removeBnd($id: Int!) {
|
||||||
|
removeUser(id_: $id)
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const [removeUser, { data, loading, error }] = useMutation(DEL_BND)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(id);
|
removeUser({
|
||||||
|
variables: {id: parseInt(id)}
|
||||||
|
}).then(() => {
|
||||||
navigate("/");
|
navigate("/");
|
||||||
|
})
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
return <h3>Del BND</h3>;
|
return <h3>Del BND</h3>;
|
||||||
}
|
}
|
||||||
@@ -126,14 +149,134 @@ function BndEdit() {
|
|||||||
const {id} = useParams();
|
const {id} = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
const { loading, error, data } = useQuery(GET_BND, {variables: {id: parseInt(id)}});
|
||||||
console.log(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("/");
|
navigate("/");
|
||||||
}, []);
|
}}>
|
||||||
return <h3>Del BND</h3>;
|
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() {
|
export default function App() {
|
||||||
@@ -144,7 +287,12 @@ export default function App() {
|
|||||||
<Route path={"/queue"} element={<DisplayQueue/>}/>
|
<Route path={"/queue"} element={<DisplayQueue/>}/>
|
||||||
<Route path={"/newbnd"} element={<BndForm/>}/>
|
<Route path={"/newbnd"} element={<BndForm/>}/>
|
||||||
<Route path={"/delbnd/:id"} element={<DeleteBnd/>}/>
|
<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={"/bnd/:id"} element={<BndEdit/>}/>
|
||||||
|
<Route path={"/scr"} element={<StartCorrectingReplication/>}/>
|
||||||
|
<Route path={"/send"} element={<SendCommit/>}/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user