Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
feat: ui can now edit configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
chirino committed Jun 6, 2020
1 parent 60abf48 commit 65171c1
Show file tree
Hide file tree
Showing 38 changed files with 71,552 additions and 498 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/serve/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func mountGatewayOnHttpServer(c *config.Config) error {
graphqlURL := fmt.Sprintf("%s/graphql", c.Server.URL)
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Mount("/admin", admin.CreateHttpHandler())
r.Handle("/graphql", gatewayHandler)
r.Handle("/", graphiql.New(graphqlURL, true))
r.Handle("/graphql", gatewayHandler)
r.Mount("/admin", admin.CreateHttpHandler())
c.Server.Config.Handler = r
config.Value.Log.Printf("GraphQL endpoint running at %s", graphqlURL)
config.Value.Log.Printf("GraphQL UI running at %s", c.Server.URL)
Expand Down
20 changes: 15 additions & 5 deletions internal/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ type Subscription {}
for eid, upstream := range upstreams {
original, err := loadEndpointSchema(config, upstream)
if err != nil {
return nil, err
log.Printf("%v", err)
continue
//return nil, err
}

upstreams[eid].RenameTypes(original)
Expand All @@ -149,22 +151,30 @@ type Subscription {}
case *Mount:
err := actionRunner.mount(action)
if err != nil {
return nil, err
log.Printf("%v", err)
continue
//return nil, err
}
case *Link:
err := actionRunner.link(action)
if err != nil {
return nil, err
log.Printf("%v", err)
continue
//return nil, err
}
case *Rename:
err := actionRunner.rename(action)
if err != nil {
return nil, err
log.Printf("%v", err)
continue
//return nil, err
}
case *Remove:
err := actionRunner.remove(action)
if err != nil {
return nil, err
log.Printf("%v", err)
continue
//return nil, err
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/gateway/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func mount(c actionRunner, field schema.Field, upstream *upstreamServer, upstrea
v.Type = t
}

if c.Gateway.Schema.Types[c.Type.Name] == nil {
c.Gateway.Schema.Types[c.Type.Name] = &schema.Object{
Name: c.Type.Name,
}
}

mountType := c.Gateway.Schema.Types[c.Type.Name].(*schema.Object)
existingField := mountType.Fields.Get(field.Name)
if existingField == nil {
Expand Down
16 changes: 13 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
"name": "ui",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:8080",
"dependencies": {
"@patternfly/react-core": "^3.158.1",
"@patternfly/react-table": "^2.28.47",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-router-last-location": "^2.0.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test"
"start": "npm run watch:css && react-scripts start",
"build": "npm run build:css && react-scripts build",
"test": "react-scripts test",
"build:css": "postcss src/assets/tailwind.css -o src/assets/main.css",
"watch:css": "postcss src/assets/tailwind.css -o src/assets/main.css"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -32,5 +37,10 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"autoprefixer": "^9.8.0",
"postcss-cli": "^7.1.1",
"tailwindcss": "^1.4.6"
}
}
7 changes: 7 additions & 0 deletions ui/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [
tailwindcss('./tailwind.js'),
require('autoprefixer')
],
};
2 changes: 2 additions & 0 deletions ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="GraphQL Gateway"/>
<!--
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
-->
<title>GraphQL Gateway</title>
</head>
<body>
Expand Down
21 changes: 12 additions & 9 deletions ui/src/App/AppLayout.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Nav, NavItem, NavList, Page, PageHeader, PageSidebar, SkipToContent } from '@patternfly/react-core';
import {Nav, NavItem, NavList, Page, PageHeader, PageSidebar, SkipToContent} from '@patternfly/react-core';
import * as React from 'react';
import { NavLink } from 'react-router-dom';
import {NavLink} from 'react-router-dom';

import routes from '../routes';

export default (props) => {

const logoProps = {
href: '/',
target: '_blank'
Expand Down Expand Up @@ -36,32 +36,35 @@ export default (props) => {
<Nav id="nav-primary-simple" theme="dark">
<NavList id="nav-list-simple">
{routes.map((route, idx) => route.label && (
<NavItem key={`${route.label}-${idx}`} id={`${route.label}-${idx}`}>
<NavLink exact to={route.path} activeClassName="pf-m-current">{route.label}</NavLink>
</NavItem>
))}
<NavItem key={`${route.label}-${idx}`} id={`${route.label}-${idx}`}>
<NavLink exact to={route.path} activeClassName="pf-m-current">{route.label}</NavLink>
</NavItem>
))}
</NavList>
</Nav>
);
const Sidebar = (
<PageSidebar
theme="dark"
nav={Navigation}
isNavOpen={isMobileView ? isNavOpenMobile : isNavOpen} />
isNavOpen={isMobileView ? isNavOpenMobile : isNavOpen}/>
);
const PageSkipToContent = (
<SkipToContent href="#primary-app-container">
Skip to Content
</SkipToContent>
);

return (
<Page
mainContainerId="primary-app-container"
header={Header}
sidebar={Sidebar}
onPageResize={onPageResize}
skipToContent={PageSkipToContent}>
{props.children}
{/*<div style={{background: "white"}}>*/}
{props.children}
{/*</div>*/}
</Page>
);
}
78 changes: 10 additions & 68 deletions ui/src/App/AppRoutes.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,25 @@
import * as React from 'react';
import {Route, Switch} from 'react-router-dom';
import {LastLocationProvider, useLastLocation} from 'react-router-last-location';
import {LastLocationProvider} from 'react-router-last-location';

import {NotFound} from '../pages/NotFound';
import routes from '../routes';
import {accessibleRouteChangeHandler, useDocumentTitle} from '../utils';
import {useDocumentTitle} from '../utils';

// const getSupportModuleAsync = () => () => import(/* webpackChunkName: 'support' */ '@app/Support/Support');
// const Support = (routeProps) => {
// const lastNavigation = useLastLocation();
// return (
// <DynamicImport load={getSupportModuleAsync()} focusContentAfterMount={lastNavigation !== null}>
// {(Component) => {
// let loadedComponent = null;
// if (Component === null) {
// loadedComponent = (
// <PageSection aria-label="Loading Content Container">
// <div className="pf-l-bullseye">
// <Alert title="Loading" className="pf-l-bullseye__item" />
// </div>
// </PageSection>
// );
// } else {
// loadedComponent = <Component.Support {...routeProps} />;
// }
// return loadedComponent;
// }}
// </DynamicImport>
// );
// };


let routeFocusTimer;

// a custom hook for sending focus to the primary content container
// after a view has loaded so that subsequent press of tab key
// sends focus directly to relevant content
const useA11yRouteChange = (isAsync) => {
const lastNavigation = useLastLocation();
React.useEffect(() => {
if (!isAsync && lastNavigation !== null) {
routeFocusTimer = accessibleRouteChangeHandler();
}
return () => {
window.clearTimeout(routeFocusTimer);
};
}, [isAsync, lastNavigation]);
};

const RouteWithTitleUpdates = ({ component: Component, isAsync = false, title, ...rest }) => {
useA11yRouteChange(isAsync);
const PageNotFound = ({title}) => {
useDocumentTitle(title);

function routeWithTitle(routeProps) {
return <Component {...rest} {...routeProps} />;
}

return <Route render={routeWithTitle} />;
return <Route component={NotFound}/>;
};

const PageNotFound = ({ title }) => {
useDocumentTitle(title);
return <Route component={NotFound} />;
};
export default () => {

export default () => (
<LastLocationProvider>
return <LastLocationProvider>
<Switch>
{routes.map(({ path, exact, component, title, isAsync }, idx) => (
<RouteWithTitleUpdates
path={path}
exact={exact}
component={component}
key={idx}
title={title}
isAsync={isAsync}
/>
{routes.map(({path, exact, component, title, isAsync}, idx) => (
<Route path={path} exact={exact} component={component} key={idx}/>
))}
<PageNotFound title="404 Page Not Found" />
<PageNotFound title="404 Page Not Found"/>
</Switch>
</LastLocationProvider>
);
}
41 changes: 0 additions & 41 deletions ui/src/App/DynamicImport.js

This file was deleted.

Loading

0 comments on commit 65171c1

Please sign in to comment.