From 41509bb4430c0cf7d691c18e4ddfc5e09f7dd96c Mon Sep 17 00:00:00 2001
From: Ryan Brink <5607577+unredundant@users.noreply.github.com>
Date: Sun, 17 Jul 2022 08:50:33 -0600
Subject: [PATCH] allow for multiple graphs
Signed-off-by: Ryan Brink <5607577+unredundant@users.noreply.github.com>
---
packages/app/src/App.tsx | 12 +++
.../ApolloExplorer/ApolloExplorer.tsx | 72 ----------------
.../ApolloExplorerBrowser.tsx | 85 +++++++++++++++++++
.../components/ApolloExplorerBrowser/index.ts | 0
.../ApolloExplorerPage/ApolloExplorerPage.tsx | 39 +++++++++
.../index.ts | 2 +-
plugins/apollo-explorer/src/plugin.ts | 2 +-
7 files changed, 138 insertions(+), 74 deletions(-)
delete mode 100644 plugins/apollo-explorer/src/components/ApolloExplorer/ApolloExplorer.tsx
create mode 100644 plugins/apollo-explorer/src/components/ApolloExplorerBrowser/ApolloExplorerBrowser.tsx
create mode 100644 plugins/apollo-explorer/src/components/ApolloExplorerBrowser/index.ts
create mode 100644 plugins/apollo-explorer/src/components/ApolloExplorerPage/ApolloExplorerPage.tsx
rename plugins/apollo-explorer/src/components/{ApolloExplorer => ApolloExplorerPage}/index.ts (91%)
diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx
index 35c61f2f16..4739b1a380 100644
--- a/packages/app/src/App.tsx
+++ b/packages/app/src/App.tsx
@@ -98,6 +98,7 @@ import { techDocsPage } from './components/techdocs/TechDocsPage';
import { ApacheAirflowPage } from '@backstage/plugin-apache-airflow';
import { PermissionedRoute } from '@backstage/plugin-permission-react';
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common';
+import { ApolloExplorerPage } from '@backstage/plugin-apollo-explorer';
const app = createApp({
apis,
@@ -239,6 +240,17 @@ const routes = (
} />
} />
+
+ }
+ />
);
diff --git a/plugins/apollo-explorer/src/components/ApolloExplorer/ApolloExplorer.tsx b/plugins/apollo-explorer/src/components/ApolloExplorer/ApolloExplorer.tsx
deleted file mode 100644
index 02ab3152f6..0000000000
--- a/plugins/apollo-explorer/src/components/ApolloExplorer/ApolloExplorer.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2022 The Backstage Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import React from 'react';
-import { Content, Header, Page } from '@backstage/core-components';
-import { ApolloExplorer as ApolloExplorerReact } from '@apollo/explorer/react';
-import { makeStyles } from '@material-ui/core';
-import { JSONObject } from '@apollo/explorer/src/helpers/types';
-
-const useStyles = makeStyles(() => ({
- explorer: {
- height: '100%',
- },
-}));
-
-type PluginProps = {
- title?: string;
- subtitle?: string | undefined;
-};
-
-type GraphProps = {
- graphRef: string;
- persistExplorerState?: boolean;
- initialState?: {
- document?: string;
- variables?: JSONObject;
- headers?: Record;
- displayOptions: {
- docsPanelState?: 'open' | 'closed';
- showHeadersAndEnvVars?: boolean;
- theme?: 'dark' | 'light';
- };
- };
-};
-
-type Props = PluginProps & GraphProps;
-
-export const ApolloExplorer = ({
- graphRef,
- persistExplorerState = true,
- initialState,
- title = 'Welcome to the Apollo Explorer 👩🚀',
- subtitle,
-}: Props) => {
- const classes = useStyles();
- return (
-
-
-
-
-
-
- );
-};
diff --git a/plugins/apollo-explorer/src/components/ApolloExplorerBrowser/ApolloExplorerBrowser.tsx b/plugins/apollo-explorer/src/components/ApolloExplorerBrowser/ApolloExplorerBrowser.tsx
new file mode 100644
index 0000000000..bce3ce00bb
--- /dev/null
+++ b/plugins/apollo-explorer/src/components/ApolloExplorerBrowser/ApolloExplorerBrowser.tsx
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2020 The Backstage Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState } from 'react';
+import { Divider, makeStyles, Tab, Tabs } from '@material-ui/core';
+import { BackstageTheme } from '@backstage/theme';
+import { JSONObject } from '@apollo/explorer/src/helpers/types';
+import { ApolloExplorer } from '@apollo/explorer/react';
+import { Content } from '@backstage/core-components';
+
+const useStyles = makeStyles(theme => ({
+ tabs: {
+ background: theme.palette.background.paper,
+ },
+ root: {
+ height: '100%',
+ },
+ content: {
+ height: '100%',
+ },
+ explorer: {
+ height: '95%',
+ },
+}));
+
+export type ApolloEndpointProps = {
+ title: string;
+ graphRef: string;
+ persistExplorerState?: boolean;
+ initialState?: {
+ document?: string;
+ variables?: JSONObject;
+ headers?: Record;
+ displayOptions: {
+ docsPanelState?: 'open' | 'closed';
+ showHeadersAndEnvVars?: boolean;
+ theme?: 'dark' | 'light';
+ };
+ };
+};
+
+type Props = {
+ endpoints: ApolloEndpointProps[];
+};
+
+export const ApolloExplorerBrowser = ({ endpoints }: Props) => {
+ const classes = useStyles();
+ const [tabIndex, setTabIndex] = useState(0);
+
+ return (
+
+
setTabIndex(value)}
+ indicatorColor="primary"
+ >
+ {endpoints.map(({ title }, index) => (
+
+ ))}
+
+
+
+
+
+
+ );
+};
diff --git a/plugins/apollo-explorer/src/components/ApolloExplorerBrowser/index.ts b/plugins/apollo-explorer/src/components/ApolloExplorerBrowser/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/plugins/apollo-explorer/src/components/ApolloExplorerPage/ApolloExplorerPage.tsx b/plugins/apollo-explorer/src/components/ApolloExplorerPage/ApolloExplorerPage.tsx
new file mode 100644
index 0000000000..b41e6aa041
--- /dev/null
+++ b/plugins/apollo-explorer/src/components/ApolloExplorerPage/ApolloExplorerPage.tsx
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2022 The Backstage Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import React from 'react';
+import { Content, Header, Page } from '@backstage/core-components';
+import {
+ ApolloEndpointProps,
+ ApolloExplorerBrowser,
+} from '../ApolloExplorerBrowser/ApolloExplorerBrowser';
+
+type Props = {
+ title?: string | undefined;
+ subtitle?: string | undefined;
+ endpoints: ApolloEndpointProps[];
+};
+
+export const ApolloExplorerPage = ({ title, subtitle, endpoints }: Props) => {
+ return (
+
+
+
+
+
+
+ );
+};
diff --git a/plugins/apollo-explorer/src/components/ApolloExplorer/index.ts b/plugins/apollo-explorer/src/components/ApolloExplorerPage/index.ts
similarity index 91%
rename from plugins/apollo-explorer/src/components/ApolloExplorer/index.ts
rename to plugins/apollo-explorer/src/components/ApolloExplorerPage/index.ts
index 2c1204b8d1..8f62872fe6 100644
--- a/plugins/apollo-explorer/src/components/ApolloExplorer/index.ts
+++ b/plugins/apollo-explorer/src/components/ApolloExplorerPage/index.ts
@@ -13,4 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-export { ApolloExplorer } from './ApolloExplorer';
+export { ApolloExplorerPage } from './ApolloExplorerPage';
diff --git a/plugins/apollo-explorer/src/plugin.ts b/plugins/apollo-explorer/src/plugin.ts
index 0a32394e9a..b1025d32e7 100644
--- a/plugins/apollo-explorer/src/plugin.ts
+++ b/plugins/apollo-explorer/src/plugin.ts
@@ -31,7 +31,7 @@ export const ApolloExplorerPage = apolloExplorerPlugin.provide(
createRoutableExtension({
name: 'ApolloExplorerPage',
component: () =>
- import('./components/ApolloExplorer').then(m => m.ApolloExplorer),
+ import('./components/ApolloExplorerPage').then(m => m.ApolloExplorerPage),
mountPoint: rootRouteRef,
}),
);