diff --git a/gd-ui-boilerplate/README.md b/gd-ui-boilerplate/README.md index 7beb4301..34f406f0 100644 --- a/gd-ui-boilerplate/README.md +++ b/gd-ui-boilerplate/README.md @@ -1,15 +1,9 @@ # GoodData.UI Boilerplate App -This app follows steps from https://sdk.gooddata.com/gooddata-ui/docs/ht_create_your_first_visualization.html: - -* It initializes create-react-app -* It configures GoodData proxy -* It adds GoodData.UI dependencies - -This app also shows: +This app shows: * Use of `` component -* Use of `` component +* Use of `` component And finally this app demonstrates 3 approaches how to render visualizations: @@ -19,7 +13,7 @@ And finally this app demonstrates 3 approaches how to render visualizations: ## Live demo -This app is deployed at https://gooddata-demo.s3.amazonaws.com/gd-ui-boilerplate/index.html. For access, you can register at https://gooddata-examples.herokuapp.com/. +This app is deployed at https://gooddata-demo.s3.amazonaws.com/gd-ui-boilerplate/index.html. ## How to run locally @@ -35,11 +29,11 @@ This app is deployed at https://gooddata-demo.s3.amazonaws.com/gd-ui-boilerplate ## Backend/proxy info -This app is configured to run against https://developer.na.gooddata.com/. For access, you can register at https://gooddata-examples.herokuapp.com/. +This app is configured to run against https://live-examples-proxy.herokuapp.com/, workspace `xms7ga4tf3g3nzucd8380o2bev8oeknp`. No authentication required. ## Screnshots -![homepage](https://raw.githubusercontent.com/gooddata/ui-sdk-examples/master/gd-ui-boilerplate/public/home.png "Homepage") +![homepage](public/home.png) --- diff --git a/gd-ui-boilerplate/src/App.js b/gd-ui-boilerplate/src/App.js index a9210f82..ff31c92a 100644 --- a/gd-ui-boilerplate/src/App.js +++ b/gd-ui-boilerplate/src/App.js @@ -1,5 +1,5 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. -import React, { useState, useEffect } from "react"; +// Copyright (C) 2007-2021, GoodData(R) Corporation. All rights reserved. +import React, { useState } from "react"; import { Headline, ColumnChart } from "@gooddata/sdk-ui-charts"; import { newPositiveAttributeFilter } from "@gooddata/sdk-model"; import { BackendProvider, WorkspaceProvider, Execute } from "@gooddata/sdk-ui"; @@ -7,7 +7,6 @@ import { InsightView } from "@gooddata/sdk-ui-ext"; import { AttributeFilter } from "@gooddata/sdk-ui-filters"; import backend from "./backend"; import CustomBarChart from "./components/CustomBarChart"; -import { loginMachinery } from "./utils"; import * as Ldm from "./ldm/full"; import "@gooddata/sdk-ui-charts/styles/css/main.css"; @@ -17,24 +16,8 @@ import "./App.css"; const WORKSPACE = "xms7ga4tf3g3nzucd8380o2bev8oeknp"; function App() { - const [isLogged, setIsLogged] = useState(false); const [filters, setFilters] = useState([]); - useEffect(() => { - loginMachinery( - { - sdk: backend.sdk, - projectId: WORKSPACE, - domain: backend.config.hostname - }, - () => setIsLogged(true) - ); - }); - - if (!isLogged) { - return Checking your credentials, please wait…; - } - return ( @@ -48,10 +31,7 @@ function App() { }} > setFilters([filter])} /> diff --git a/gd-ui-boilerplate/src/backend.js b/gd-ui-boilerplate/src/backend.js index 0efe1ab4..de0ee3ee 100644 --- a/gd-ui-boilerplate/src/backend.js +++ b/gd-ui-boilerplate/src/backend.js @@ -1,22 +1,9 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. -import bearFactory, { - ContextDeferredAuthProvider -} from "@gooddata/sdk-backend-bear"; +// Copyright (C) 2007-2021, GoodData(R) Corporation. All rights reserved. +import bearFactory, { AnonymousAuthProvider } from "@gooddata/sdk-backend-bear"; -const config = { - hostname: "" -}; - -if (process.env.NODE_ENV === "production") { - const gdUrl = process.env.GD_URL; - config.hostname = gdUrl - ? `https://${gdUrl}` - : "https://developer.na.gooddata.com"; -} - -const backend = bearFactory(config).withAuthentication( - new ContextDeferredAuthProvider() -); +const backend = bearFactory({ + hostname: "https://live-examples-proxy.herokuapp.com/" +}).withAuthentication(new AnonymousAuthProvider()); window.gooddata = backend; diff --git a/gd-ui-boilerplate/src/components/CustomBarChart.js b/gd-ui-boilerplate/src/components/CustomBarChart.js index fdd54b7a..e7cbe604 100644 --- a/gd-ui-boilerplate/src/components/CustomBarChart.js +++ b/gd-ui-boilerplate/src/components/CustomBarChart.js @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. +// Copyright (C) 2007-2021, GoodData(R) Corporation. All rights reserved. import React from "react"; import ReactHighcharts from "react-highcharts"; diff --git a/gd-ui-boilerplate/src/index.js b/gd-ui-boilerplate/src/index.js index 3d7462fc..eba21751 100644 --- a/gd-ui-boilerplate/src/index.js +++ b/gd-ui-boilerplate/src/index.js @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. +// Copyright (C) 2007-2021, GoodData(R) Corporation. All rights reserved. import React from "react"; import ReactDOM from "react-dom"; import "./index.css"; diff --git a/gd-ui-boilerplate/src/setupProxy.js b/gd-ui-boilerplate/src/setupProxy.js deleted file mode 100644 index 94bb5c32..00000000 --- a/gd-ui-boilerplate/src/setupProxy.js +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. -const proxy = require("http-proxy-middleware"); - -module.exports = function(app) { - app.use( - proxy("/gdc", { - changeOrigin: true, - cookieDomainRewrite: "localhost", - secure: false, - target: "https://developer.na.gooddata.com", - headers: { - host: "developer.na.gooddata.com", - origin: null - }, - onProxyReq: function(proxyReq, req, res) { - proxyReq.setHeader("accept-encoding", "identity"); - } - }) - ); - app.use( - proxy("/*.html", { - changeOrigin: true, - secure: false, - target: "https://developer.na.gooddata.com" - }) - ); - app.use( - proxy("/packages/*.{js,css}", { - changeOrigin: true, - secure: false, - target: "https://developer.na.gooddata.com" - }) - ); -}; diff --git a/gd-ui-boilerplate/src/utils.js b/gd-ui-boilerplate/src/utils.js deleted file mode 100644 index 07cc82fc..00000000 --- a/gd-ui-boilerplate/src/utils.js +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved. -export const loginMachinery = ( - { sdk, projectId, domain }, - callback = () => {} -) => { - const redirectToLogin = () => { - if (domain) { - window.location.replace( - `${domain}/account.html?lastUrl=${encodeURIComponent(window.location)}` - ); - } else { - window.location.replace( - `https://${window.location.hostname}:${ - window.location.port - }/account.html?lastUrl=${encodeURIComponent(window.location)}` - ); - } - }; - - sdk.user.isLoggedIn().then(isLogged => { - if (isLogged) { - sdk.user.getAccountInfo().then(accountInfo => { - const { profileUri } = accountInfo; - - sdk.project.getProjects(profileUri.split("/")[4]).then(projects => { - if ( - projects.find(p => p.links.self === `/gdc/projects/${projectId}`) - ) { - callback(accountInfo); - } else { - sdk.user.logout().then(() => { - redirectToLogin(); - }); - } - }); - }); - } else { - redirectToLogin(); - } - }); -}; - -export const logout = (e, { sdk, domain }) => { - e.preventDefault(); - - const redirectToLogin = () => { - if (domain) { - window.location.replace( - `${domain}/account.html?lastUrl=${encodeURIComponent(window.location)}` - ); - } else { - window.location.replace( - `https://${window.location.hostname}:${window.location.port}/account.html` - ); - } - }; - - sdk.user.logout().then(() => { - redirectToLogin(); - }); -};