Skip to content

Commit

Permalink
gd-ui-boilerplate-v8 - Done
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsBunny338 committed Aug 28, 2020
1 parent e943e2b commit fc7bf1e
Show file tree
Hide file tree
Showing 16 changed files with 4,428 additions and 206 deletions.
1 change: 1 addition & 0 deletions gd-ui-boilerplate-v8/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.env.development.local
.env.test.local
.env.production.local
.s3cfg

npm-debug.log*
yarn-debug.log*
Expand Down
1 change: 1 addition & 0 deletions gd-ui-boilerplate-v8/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.16.1
78 changes: 28 additions & 50 deletions gd-ui-boilerplate-v8/README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `yarn test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
# GoodData.UI@v8 Boilerplate App

### `yarn build`
This app follows steps from https://sdk.gooddata.com/gooddata-ui/docs/next/ht_create_your_first_visualization.html:

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
* It initializes create-react-app
* It configures GoodData proxy
* It adds GoodData.UI dependencies

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
This app also shows:

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
* Use of `<AttributeFilter>` component
* Use of `<Kpi>` component

### `yarn eject`
And finally this app demonstrates 3 approaches how to render visualizations:

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
* By referencing `<InsightView>` created in Analytical Designer
* By specifying buckets (measures, viewBy, stackBy) with `<ColumnChart>` component
* By creating custom column chart using `<Execute>` component and [Highcharts](https://www.highcharts.com/) library

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
## Live demo

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
This app is deployed at https://gooddata-demo.s3.amazonaws.com/gd-ui-boilerplate-v8/index.html. For access, you can register at https://gooddata-examples.herokuapp.com/.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## How to run locally

## Learn More
* `git clone --depth 1 https://github.com/gooddata/ui-sdk-examples.git`
* `cd ui-sdk-examples/gd-ui-boilerplate-v8/`
* `yarn install`
* `yarn start`

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
## How to build for deployment

To learn React, check out the [React documentation](https://reactjs.org/).
* `yarn build` when deploying to root folder
* `PUBLIC_URL=/gd-ui-boilerplate-v8 yarn build` when deploying to `/gd-ui-boilerplate-v8` folder

### Code Splitting
## Backend/proxy info

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This app is configured to run against https://developer.na.gooddata.com/. For access, you can register at https://gooddata-examples.herokuapp.com/.

### Analyzing the Bundle Size
## Screnshots

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
![homepage](https://raw.githubusercontent.com/gooddata/ui-sdk-examples/master/gd-ui-boilerplate-v8/public/screen1.png "Homepage")

### Making a Progressive Web App
---

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `yarn build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
17 changes: 12 additions & 5 deletions gd-ui-boilerplate-v8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@gooddata/sdk-backend-bear": "^8.0.0-beta.52",
"@gooddata/sdk-model": "^8.0.0-beta.52",
"@gooddata/sdk-ui": "^8.0.0-beta.52",
"@gooddata/sdk-ui-charts": "^8.0.0-beta.52",
"@gooddata/sdk-backend-bear": "^8.0.0-beta.54",
"@gooddata/sdk-model": "^8.0.0-beta.54",
"@gooddata/sdk-ui": "^8.0.0-beta.54",
"@gooddata/sdk-ui-charts": "^8.0.0-beta.54",
"@gooddata/sdk-ui-ext": "^8.0.0-beta.54",
"@gooddata/sdk-ui-filters": "^8.0.0-beta.54",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-highcharts": "^16.1.0",
"react-scripts": "3.4.3"
},
"scripts": {
"start": "cross-env HTTPS=true react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"refresh-ldm": "./scripts/refresh-ldm.sh",
"buildgd": "cross-env PUBLIC_URL=/gd-ui-boilerplate-v8 yarn build",
"syncgd": "s3cmd --config .s3cfg sync --delete-removed ./build/ s3://gooddata-demo/gd-ui-boilerplate-v8/"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -36,6 +42,7 @@
]
},
"devDependencies": {
"@gooddata/catalog-export": "^8.0.0-beta.55",
"cross-env": "^7.0.2"
}
}
2 changes: 1 addition & 1 deletion gd-ui-boilerplate-v8/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>GoodData.UI Boilerplate</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file added gd-ui-boilerplate-v8/public/screen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions gd-ui-boilerplate-v8/scripts/refresh-ldm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

SCRIPTDIR=`dirname $0`
ROOTDIR="${SCRIPTDIR}/.."
EXPORTER="${ROOTDIR}/node_modules/.bin/gdc-catalog-export"
OUTPUT="${ROOTDIR}/src/ldm/full.js"
PROJECTID="xms7ga4tf3g3nzucd8380o2bev8oeknp"

$EXPORTER \
--hostname "https://developer.na.gooddata.com" \
--output "${OUTPUT}" \
--project-id "${PROJECTID}"
35 changes: 0 additions & 35 deletions gd-ui-boilerplate-v8/src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
95 changes: 75 additions & 20 deletions gd-ui-boilerplate-v8/src/App.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,88 @@
import React from "react";
import { LineChart } from "@gooddata/sdk-ui-charts";
import { newMeasure, newAttribute } from "@gooddata/sdk-model";
import bearFactory, {
ContextDeferredAuthProvider
} from "@gooddata/sdk-backend-bear";
import { BackendProvider, WorkspaceProvider } from "@gooddata/sdk-ui";
// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved.
import React, { useState, useEffect } from "react";
import { Headline, ColumnChart } from "@gooddata/sdk-ui-charts";
import { newAttribute, newPositiveAttributeFilter } from "@gooddata/sdk-model";
import { BackendProvider, WorkspaceProvider, Execute } from "@gooddata/sdk-ui";
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";
import "@gooddata/sdk-ui-filters/styles/css/main.css";
import "./App.css";

const backend = bearFactory().withAuthentication(
new ContextDeferredAuthProvider()
);
const WORKSPACE = "xms7ga4tf3g3nzucd8380o2bev8oeknp";

function App() {
const measures = [newMeasure("aaEGaXAEgB7U", m => m.format("#,##0"))];
const attribute = newAttribute("date.abm81lMifn6q");
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 <span>Checking your credentials, please wait…</span>;
}

return (
<BackendProvider backend={backend}>
<WorkspaceProvider workspace="xms7ga4tf3g3nzucd8380o2bev8oeknp">
<WorkspaceProvider workspace={WORKSPACE}>
<div className="App">
<div style={{ height: 500 }}>
<LineChart
measures={measures}
trendBy={attribute}
config={{
colors: ["#14b2e2"]
}}
<div
style={{
width: 400,
margin: "auto",
marginBottom: 20,
marginTop: 20
}}
>
<AttributeFilter
filter={newPositiveAttributeFilter(
newAttribute("label.restaurantlocation.locationcity"),
[]
)}
onApply={filter => setFilters([filter])}
/>
</div>
<div>
# of Location City:{" "}
<Headline primaryMeasure={Ldm.NrLocationCity} filters={filters} />
<br />
<br />
</div>
<div style={{ height: 400 }}>
<InsightView
// insight="aby6oS6DbpFX"
insight={Ldm.Insights.NrChecksViewedByCityStackedByLocation}
filters={filters}
config={{ legend: { position: "top" } }}
/>
</div>
<div style={{ height: 400 }}>
<ColumnChart
measures={[Ldm.NrChecks]}
viewBy={Ldm.LocationCity}
stackBy={Ldm.LocationName.Default}
filters={filters}
/>
</div>
<div style={{ height: 400 }}>
<Execute
seriesBy={[Ldm.NrChecks]}
slicesBy={[Ldm.LocationCity]}
filters={filters}
children={CustomBarChart}
/>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions gd-ui-boilerplate-v8/src/backend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved.
import bearFactory, {
ContextDeferredAuthProvider
// FixedLoginAndPasswordAuthProvider
} 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()
);

window.gooddata = backend;

export default backend;
37 changes: 37 additions & 0 deletions gd-ui-boilerplate-v8/src/components/CustomBarChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved.
import React from "react";
import ReactHighcharts from "react-highcharts";
import * as Ldm from "../ldm/full";

const CustomBarChart = ({ error, isLoading, result }) => {
if (isLoading) {
return <span>Loading…</span>;
}

if (error) {
return <span>Something went wrong :-(</span>;
}

if (result) {
const config = {
chart: {
type: "column"
},
title: {
text: "🎉🍾🙌 My First Custom Chart 🙌🍾🎉"
},
series: result
.data()
.series()
.firstForMeasure(Ldm.NrChecks)
.dataPoints()
.map((row, i) => ({ data: [parseFloat(row.rawValue)] }))
};

return <ReactHighcharts config={config} />;
}

return "🧟‍♂️ UGLY INIT";
};

export default CustomBarChart;
1 change: 1 addition & 0 deletions gd-ui-boilerplate-v8/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2007-2020, GoodData(R) Corporation. All rights reserved.
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
Expand Down
Loading

0 comments on commit fc7bf1e

Please sign in to comment.