aboutsummaryrefslogtreecommitdiffstats
path: root/webui/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'webui/src/components')
-rw-r--r--webui/src/components/Author.tsx2
-rw-r--r--webui/src/components/BugTitleForm/BugTitleForm.tsx202
-rw-r--r--webui/src/components/BugTitleForm/SetTitle.graphql7
-rw-r--r--webui/src/components/CloseBugButton/CloseBug.graphql8
-rw-r--r--webui/src/components/CloseBugButton/CloseBugButton.tsx55
-rw-r--r--webui/src/components/CommentInput/CommentInput.tsx107
-rw-r--r--webui/src/components/CurrentIdentity/CurrentIdentity.graphql8
-rw-r--r--webui/src/components/CurrentIdentity/CurrentIdentity.tsx31
-rw-r--r--webui/src/components/Header/Header.tsx50
-rw-r--r--webui/src/components/Header/index.tsx18
-rw-r--r--webui/src/components/IfLoggedIn/IfLoggedIn.tsx14
-rw-r--r--webui/src/components/Label.tsx3
-rw-r--r--webui/src/components/ReopenBugButton/OpenBug.graphql7
-rw-r--r--webui/src/components/ReopenBugButton/ReopenBugButton.tsx55
-rw-r--r--webui/src/components/fragments.graphql19
15 files changed, 564 insertions, 22 deletions
diff --git a/webui/src/components/Author.tsx b/webui/src/components/Author.tsx
index 9ac1da52..d60e8969 100644
--- a/webui/src/components/Author.tsx
+++ b/webui/src/components/Author.tsx
@@ -3,7 +3,7 @@ import React from 'react';
import MAvatar from '@material-ui/core/Avatar';
import Tooltip from '@material-ui/core/Tooltip/Tooltip';
-import { AuthoredFragment } from './fragments.generated';
+import { AuthoredFragment } from '../graphql/fragments.generated';
type Props = AuthoredFragment & {
className?: string;
diff --git a/webui/src/components/BugTitleForm/BugTitleForm.tsx b/webui/src/components/BugTitleForm/BugTitleForm.tsx
new file mode 100644
index 00000000..c47eab31
--- /dev/null
+++ b/webui/src/components/BugTitleForm/BugTitleForm.tsx
@@ -0,0 +1,202 @@
+import React, { useState } from 'react';
+
+import {
+ Button,
+ fade,
+ makeStyles,
+ TextField,
+ Typography,
+} from '@material-ui/core';
+
+import { TimelineDocument } from '../../pages/bug/TimelineQuery.generated';
+import IfLoggedIn from '../IfLoggedIn/IfLoggedIn';
+import Author from 'src/components/Author';
+import Date from 'src/components/Date';
+import { BugFragment } from 'src/pages/bug/Bug.generated';
+
+import { useSetTitleMutation } from './SetTitle.generated';
+
+/**
+ * Css in JS styles
+ */
+const useStyles = makeStyles((theme) => ({
+ header: {
+ display: 'flex',
+ flexDirection: 'column',
+ },
+ headerTitle: {
+ display: 'flex',
+ flexDirection: 'row',
+ justifyContent: 'space-between',
+ },
+ readOnlyTitle: {
+ ...theme.typography.h5,
+ },
+ readOnlyId: {
+ ...theme.typography.subtitle1,
+ marginLeft: theme.spacing(1),
+ },
+ editButtonContainer: {
+ display: 'flex',
+ flexDirection: 'row',
+ justifyContent: 'flex-start',
+ alignItems: 'center',
+ minWidth: 200,
+ marginLeft: theme.spacing(2),
+ },
+ greenButton: {
+ marginLeft: '8px',
+ backgroundColor: '#2ea44fd9',
+ color: '#fff',
+ '&:hover': {
+ backgroundColor: '#2ea44f',
+ },
+ },
+ titleInput: {
+ borderRadius: theme.shape.borderRadius,
+ borderColor: fade(theme.palette.primary.main, 0.2),
+ borderStyle: 'solid',
+ borderWidth: '1px',
+ backgroundColor: fade(theme.palette.primary.main, 0.05),
+ padding: theme.spacing(0, 0),
+ minWidth: 336,
+ transition: theme.transitions.create([
+ 'width',
+ 'borderColor',
+ 'backgroundColor',
+ ]),
+ },
+}));
+
+interface Props {
+ bug: BugFragment;
+}
+
+/**
+ * Component for bug title change
+ * @param bug Selected bug in list page
+ */
+function BugTitleForm({ bug }: Props) {
+ const [bugTitleEdition, setbugTitleEdition] = useState(false);
+ const [setTitle, { loading, error }] = useSetTitleMutation();
+ const [issueTitle, setIssueTitle] = useState(bug.title);
+ const classes = useStyles();
+ let issueTitleInput: any;
+
+ function isFormValid() {
+ if (issueTitleInput) {
+ return issueTitleInput.value.length > 0 ? true : false;
+ } else {
+ return false;
+ }
+ }
+
+ function submitNewTitle() {
+ if (!isFormValid()) return;
+ setTitle({
+ variables: {
+ input: {
+ prefix: bug.humanId,
+ title: issueTitleInput.value,
+ },
+ },
+ refetchQueries: [
+ // TODO: update the cache instead of refetching
+ {
+ query: TimelineDocument,
+ variables: {
+ id: bug.id,
+ first: 100,
+ },
+ },
+ ],
+ awaitRefetchQueries: true,
+ }).then(() => setbugTitleEdition(false));
+ }
+
+ function cancelChange() {
+ setIssueTitle(bug.title);
+ setbugTitleEdition(false);
+ }
+
+ function editableBugTitle() {
+ return (
+ <form className={classes.headerTitle} onSubmit={submitNewTitle}>
+ <TextField
+ inputRef={(node) => {
+ issueTitleInput = node;
+ }}
+ className={classes.titleInput}
+ variant="outlined"
+ fullWidth
+ margin="dense"
+ value={issueTitle}
+ onChange={(event: any) => setIssueTitle(event.target.value)}
+ />
+ <div className={classes.editButtonContainer}>
+ <Button
+ size="small"
+ variant="contained"
+ type="submit"
+ disabled={issueTitle.length === 0}
+ >
+ Save
+ </Button>
+ <Button size="small" onClick={() => cancelChange()}>
+ Cancel
+ </Button>
+ </div>
+ </form>
+ );
+ }
+
+ function readonlyBugTitle() {
+ return (
+ <div className={classes.headerTitle}>
+ <div>
+ <span className={classes.readOnlyTitle}>{bug.title}</span>
+ <span className={classes.readOnlyId}>{bug.humanId}</span>
+ </div>
+ <IfLoggedIn>
+ {() => (
+ <div className={classes.editButtonContainer}>
+ <Button
+ size="small"
+ variant="contained"
+ onClick={() => setbugTitleEdition(!bugTitleEdition)}
+ >
+ Edit
+ </Button>
+ <Button
+ className={classes.greenButton}
+ size="small"
+ variant="contained"
+ href="/new"
+ >
+ New issue
+ </Button>
+ </div>
+ )}
+ </IfLoggedIn>
+ </div>
+ );
+ }
+
+ if (loading) return <div>Loading...</div>;
+ if (error) return <div>Error</div>;
+
+ return (
+ <div className={classes.header}>
+ {bugTitleEdition ? editableBugTitle() : readonlyBugTitle()}
+ <div className="classes.headerSubtitle">
+ <Typography color={'textSecondary'}>
+ <Author author={bug.author} />
+ {' opened this bug '}
+ <Date date={bug.createdAt} />
+ </Typography>
+ </div>
+ </div>
+ );
+}
+
+export default BugTitleForm;
diff --git a/webui/src/components/BugTitleForm/SetTitle.graphql b/webui/src/components/BugTitleForm/SetTitle.graphql
new file mode 100644
index 00000000..b96af155
--- /dev/null
+++ b/webui/src/components/BugTitleForm/SetTitle.graphql
@@ -0,0 +1,7 @@
+mutation setTitle($input: SetTitleInput!) {
+ setTitle(input: $input) {
+ bug {
+ id
+ }
+ }
+} \ No newline at end of file
diff --git a/webui/src/components/CloseBugButton/CloseBug.graphql b/webui/src/components/CloseBugButton/CloseBug.graphql
new file mode 100644
index 00000000..e2f4bff2
--- /dev/null
+++ b/webui/src/components/CloseBugButton/CloseBug.graphql
@@ -0,0 +1,8 @@
+# Write your query or mutation here
+mutation closeBug($input: CloseBugInput!) {
+ closeBug(input: $input) {
+ bug {
+ id
+ }
+ }
+} \ No newline at end of file
diff --git a/webui/src/components/CloseBugButton/CloseBugButton.tsx b/webui/src/components/CloseBugButton/CloseBugButton.tsx
new file mode 100644
index 00000000..19f56cab
--- /dev/null
+++ b/webui/src/components/CloseBugButton/CloseBugButton.tsx
@@ -0,0 +1,55 @@
+import React from 'react';
+
+import Button from '@material-ui/core/Button';
+
+import { BugFragment } from 'src/pages/bug/Bug.generated';
+import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated';
+
+import { useCloseBugMutation } from './CloseBug.generated';
+
+interface Props {
+ bug: BugFragment;
+ disabled: boolean;
+}
+
+function CloseBugButton({ bug, disabled }: Props) {
+ const [closeBug, { loading, error }] = useCloseBugMutation();
+
+ function closeBugAction() {
+ closeBug({
+ variables: {
+ input: {
+ prefix: bug.id,
+ },
+ },
+ refetchQueries: [
+ // TODO: update the cache instead of refetching
+ {
+ query: TimelineDocument,
+ variables: {
+ id: bug.id,
+ first: 100,
+ },
+ },
+ ],
+ awaitRefetchQueries: true,
+ });
+ }
+
+ if (loading) return <div>Loading...</div>;
+ if (error) return <div>Error</div>;
+
+ return (
+ <div>
+ <Button
+ variant="contained"
+ onClick={() => closeBugAction()}
+ disabled={bug.status === 'CLOSED' || disabled}
+ >
+ Close issue
+ </Button>
+ </div>
+ );
+}
+
+export default CloseBugButton;
diff --git a/webui/src/components/CommentInput/CommentInput.tsx b/webui/src/components/CommentInput/CommentInput.tsx
new file mode 100644
index 00000000..86cc7dbb
--- /dev/null
+++ b/webui/src/components/CommentInput/CommentInput.tsx
@@ -0,0 +1,107 @@
+import React, { useState, useEffect } from 'react';
+
+import Tab from '@material-ui/core/Tab';
+import Tabs from '@material-ui/core/Tabs';
+import TextField from '@material-ui/core/TextField';
+import { makeStyles } from '@material-ui/core/styles';
+
+import Content from 'src/components/Content';
+
+/**
+ * Styles
+ */
+const useStyles = makeStyles((theme) => ({
+ container: {
+ margin: theme.spacing(2, 0),
+ padding: theme.spacing(0, 2, 2, 2),
+ },
+ textarea: {},
+ tabContent: {
+ margin: theme.spacing(2, 0),
+ },
+ preview: {
+ borderBottom: `solid 3px ${theme.palette.grey['200']}`,
+ minHeight: '5rem',
+ },
+}));
+
+type TabPanelProps = {
+ children: React.ReactNode;
+ value: number;
+ index: number;
+} & React.HTMLProps<HTMLDivElement>;
+function TabPanel({ children, value, index, ...props }: TabPanelProps) {
+ return (
+ <div
+ role="tabpanel"
+ hidden={value !== index}
+ id={`editor-tabpanel-${index}`}
+ aria-labelledby={`editor-tab-${index}`}
+ {...props}
+ >
+ {value === index && children}
+ </div>
+ );
+}
+
+const a11yProps = (index: number) => ({
+ id: `editor-tab-${index}`,
+ 'aria-controls': `editor-tabpanel-${index}`,
+});
+
+type Props = {
+ inputProps?: any;
+ loading: boolean;
+ onChange: (comment: string) => void;
+};
+
+/**
+ * Component for issue comment input
+ *
+ * @param inputProps Reset input value
+ * @param loading Disable input when component not ready yet
+ * @param onChange Callback to return input value changes
+ */
+function CommentInput({ inputProps, loading, onChange }: Props) {
+ const [input, setInput] = useState<string>('');
+ const [tab, setTab] = useState(0);
+ const classes = useStyles();
+
+ useEffect(() => {
+ if (inputProps) setInput(inputProps.value);
+ }, [inputProps]);
+
+ useEffect(() => {
+ onChange(input);
+ }, [input, onChange]);
+
+ return (
+ <div>
+ <Tabs value={tab} onChange={(_, t) => setTab(t)}>
+ <Tab label="Write" {...a11yProps(0)} />
+ <Tab label="Preview" {...a11yProps(1)} />
+ </Tabs>
+ <div className={classes.tabContent}>
+ <TabPanel value={tab} index={0}>
+ <TextField
+ fullWidth
+ label="Comment"
+ placeholder="Leave a comment"
+ className={classes.textarea}
+ multiline
+ value={input}
+ variant="filled"
+ rows="4" // TODO: rowsMin support
+ onChange={(e: any) => setInput(e.target.value)}
+ disabled={loading}
+ />
+ </TabPanel>
+ <TabPanel value={tab} index={1} className={classes.preview}>
+ <Content markdown={input} />
+ </TabPanel>
+ </div>
+ </div>
+ );
+}
+
+export default CommentInput;
diff --git a/webui/src/components/CurrentIdentity/CurrentIdentity.graphql b/webui/src/components/CurrentIdentity/CurrentIdentity.graphql
new file mode 100644
index 00000000..2794a40f
--- /dev/null
+++ b/webui/src/components/CurrentIdentity/CurrentIdentity.graphql
@@ -0,0 +1,8 @@
+query CurrentIdentity {
+ repository {
+ userIdentity {
+ displayName
+ avatarUrl
+ }
+ }
+}
diff --git a/webui/src/components/CurrentIdentity/CurrentIdentity.tsx b/webui/src/components/CurrentIdentity/CurrentIdentity.tsx
new file mode 100644
index 00000000..8cd3585b
--- /dev/null
+++ b/webui/src/components/CurrentIdentity/CurrentIdentity.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+
+import Avatar from '@material-ui/core/Avatar';
+import { makeStyles } from '@material-ui/core/styles';
+
+import { useCurrentIdentityQuery } from './CurrentIdentity.generated';
+
+const useStyles = makeStyles((theme) => ({
+ displayName: {
+ marginLeft: theme.spacing(2),
+ },
+}));
+
+const CurrentIdentity = () => {
+ const classes = useStyles();
+ const { loading, error, data } = useCurrentIdentityQuery();
+
+ if (error || loading || !data?.repository?.userIdentity) return null;
+
+ const user = data.repository.userIdentity;
+ return (
+ <>
+ <Avatar src={user.avatarUrl ? user.avatarUrl : undefined}>
+ {user.displayName.charAt(0).toUpperCase()}
+ </Avatar>
+ <div className={classes.displayName}>{user.displayName}</div>
+ </>
+ );
+};
+
+export default CurrentIdentity;
diff --git a/webui/src/components/Header/Header.tsx b/webui/src/components/Header/Header.tsx
new file mode 100644
index 00000000..3e39b5f3
--- /dev/null
+++ b/webui/src/components/Header/Header.tsx
@@ -0,0 +1,50 @@
+import React from 'react';
+import { Link } from 'react-router-dom';
+
+import AppBar from '@material-ui/core/AppBar';
+import Toolbar from '@material-ui/core/Toolbar';
+import { makeStyles } from '@material-ui/core/styles';
+
+import CurrentIdentity from '../CurrentIdentity/CurrentIdentity';
+
+const useStyles = makeStyles((theme) => ({
+ offset: {
+ ...theme.mixins.toolbar,
+ },
+ filler: {
+ flexGrow: 1,
+ },
+ appTitle: {
+ ...theme.typography.h6,
+ color: 'white',
+ textDecoration: 'none',
+ display: 'flex',
+ alignItems: 'center',
+ },
+ logo: {
+ height: '42px',
+ marginRight: theme.spacing(2),
+ },
+}));
+
+function Header() {
+ const classes = useStyles();
+
+ return (
+ <>
+ <AppBar position="fixed" color="primary">
+ <Toolbar>
+ <Link to="/" className={classes.appTitle}>
+ <img src="/logo.svg" className={classes.logo} alt="git-bug" />
+ git-bug
+ </Link>
+ <div className={classes.filler}></div>
+ <CurrentIdentity />
+ </Toolbar>
+ </AppBar>
+ <div className={classes.offset} />
+ </>
+ );
+}
+
+export default Header;
diff --git a/webui/src/components/Header/index.tsx b/webui/src/components/Header/index.tsx
new file mode 100644
index 00000000..42a0cfc1
--- /dev/null
+++ b/webui/src/components/Header/index.tsx
@@ -0,0 +1,18 @@
+import React from 'react';
+
+import CssBaseline from '@material-ui/core/CssBaseline';
+
+import Header from './Header';
+
+type Props = { children: React.ReactNode };
+function Layout({ children }: Props) {
+ return (
+ <>
+ <CssBaseline />
+ <Header />
+ {children}
+ </>
+ );
+}
+
+export default Layout;
diff --git a/webui/src/components/IfLoggedIn/IfLoggedIn.tsx b/webui/src/components/IfLoggedIn/IfLoggedIn.tsx
new file mode 100644
index 00000000..2476aad8
--- /dev/null
+++ b/webui/src/components/IfLoggedIn/IfLoggedIn.tsx
@@ -0,0 +1,14 @@
+import React from 'react';
+
+import { useCurrentIdentityQuery } from '../CurrentIdentity/CurrentIdentity.generated';
+
+type Props = { children: () => React.ReactNode };
+const IfLoggedIn = ({ children }: Props) => {
+ const { loading, error, data } = useCurrentIdentityQuery();
+
+ if (error || loading || !data?.repository?.userIdentity) return null;
+
+ return <>{children()}</>;
+};
+
+export default IfLoggedIn;
diff --git a/webui/src/components/Label.tsx b/webui/src/components/Label.tsx
index 4aaa6bb6..111f6d7f 100644
--- a/webui/src/components/Label.tsx
+++ b/webui/src/components/Label.tsx
@@ -7,10 +7,9 @@ import {
darken,
} from '@material-ui/core/styles/colorManipulator';
+import { LabelFragment } from '../graphql/fragments.generated';
import { Color } from 'src/gqlTypes';
-import { LabelFragment } from './fragments.generated';
-
// Minimum contrast between the background and the text color
const contrastThreshold = 2.5;
diff --git a/webui/src/components/ReopenBugButton/OpenBug.graphql b/webui/src/components/ReopenBugButton/OpenBug.graphql
new file mode 100644
index 00000000..cf9e49e5
--- /dev/null
+++ b/webui/src/components/ReopenBugButton/OpenBug.graphql
@@ -0,0 +1,7 @@
+mutation openBug($input: OpenBugInput!) {
+ openBug(input: $input) {
+ bug {
+ id
+ }
+ }
+} \ No newline at end of file
diff --git a/webui/src/components/ReopenBugButton/ReopenBugButton.tsx b/webui/src/components/ReopenBugButton/ReopenBugButton.tsx
new file mode 100644
index 00000000..195ca512
--- /dev/null
+++ b/webui/src/components/ReopenBugButton/ReopenBugButton.tsx
@@ -0,0 +1,55 @@
+import React from 'react';
+
+import Button from '@material-ui/core/Button';
+
+import { BugFragment } from 'src/pages/bug/Bug.generated';
+import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated';
+
+import { useOpenBugMutation } from './OpenBug.generated';
+
+interface Props {
+ bug: BugFragment;
+ disabled: boolean;
+}
+
+function ReopenBugButton({ bug, disabled }: Props) {
+ const [openBug, { loading, error }] = useOpenBugMutation();
+
+ function openBugAction() {
+ openBug({
+ variables: {
+ input: {
+ prefix: bug.id,
+ },
+ },
+ refetchQueries: [
+ // TODO: update the cache instead of refetching
+ {
+ query: TimelineDocument,
+ variables: {
+ id: bug.id,
+ first: 100,
+ },
+ },
+ ],
+ awaitRefetchQueries: true,
+ });
+ }
+
+ if (loading) return <div>Loading...</div>;
+ if (error) return <div>Error</div>;
+
+ return (
+ <div>
+ <Button
+ variant="contained"
+ onClick={() => openBugAction()}
+ disabled={bug.status === 'OPEN' || disabled}
+ >
+ Reopen issue
+ </Button>
+ </div>
+ );
+}
+
+export default ReopenBugButton;
diff --git a/webui/src/components/fragments.graphql b/webui/src/components/fragments.graphql
deleted file mode 100644
index 03a235f9..00000000
--- a/webui/src/components/fragments.graphql
+++ /dev/null
@@ -1,19 +0,0 @@
-# Label.tsx
-fragment Label on Label {
- name
- color {
- R
- G
- B
- }
-}
-
-# Author.tsx
-fragment authored on Authored {
- author {
- name
- email
- displayName
- avatarUrl
- }
-}