Skip to content

Commit

Permalink
spreadjs - Example
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsBunny338 committed Aug 23, 2022
1 parent 3bc3293 commit 00bbfaf
Show file tree
Hide file tree
Showing 77 changed files with 18,085 additions and 0 deletions.
1 change: 1 addition & 0 deletions spreadjs/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions spreadjs/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
25 changes: 25 additions & 0 deletions spreadjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.gdcatalogrc
1 change: 1 addition & 0 deletions spreadjs/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.17.0
5 changes: 5 additions & 0 deletions spreadjs/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 110,
"tabWidth": 4,
"trailingComma": "all"
}
64 changes: 64 additions & 0 deletions spreadjs/HOWTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm 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.

### `npm 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.

### `npm run build`

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.

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

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

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.

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.

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.

## Learn More

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

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

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

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### 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

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
98 changes: 98 additions & 0 deletions spreadjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## GoodData.UI Accelerator Toolkit Application

This project was bootstrapped with [GoodData.UI Accelerator Toolkit](https://sdk.gooddata.com/gooddata-ui/docs/create_new_application.html).

- To start the application on your workstation run the `npm run start` command.
- To create a production build run the `npm run build` command.

This project uses the [Create React App](https://github.com/facebook/create-react-app) (CRA) scripts and infrastructure, you
can find the original documentation for CRA in [HOWTO.md](./HOWTO.md).

This application uses GoodData Cloud or GoodData.CN as a backend. Please note, that in the developer tools context, we refer to GoodData Cloud and GoodData.CN using the codename `tiger` (for example in the npm package names and variable names).

### Authentication and CORS

When building and deploying your application on top of GoodData Cloud/GoodData.CN backend you will sooner or later run into a delicate
topic of [Cross Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) (CORS) combined
with Authentication.

The goal of this section is to help you arrive at correct application setup which can work with your GoodData.CN
installation.

**Note: Please see the [Adding Custom Environment Variables](https://create-react-app.dev/docs/adding-custom-environment-variables/)
page to learn how to correctly set environment variables for the application.**

#### Production Deployment

Application is always set to use GoodData Cloud/GoodData.CN's OIDC authentication flow. As soon as the application finds that the session
is not authenticated, the app will redirect to page where the flow starts.

- If you host the application on the same origin as the GoodData Cloud instance/GoodData.CN installation then you do not have to change the
default configuration in any way.

- If you host the application on a different origin than the GoodData Cloud instance/GoodData.CN installation, then you must set the
`REACT_APP_SET_HOSTNAME` env variable to `true`. This will ensure that wherever you deploy your application,
it will always connect to server specified in [constants.js](./src/constants.js) `backend` property.

**This requires correct CORS setup of your GoodData Cloud instance/GoodData.CN installation**

#### Development on your workstation

Application may use GoodData.CN's OIDC authentication flow or use API token. The behavior in each setup is different:

* In the OIDC authentication flow setup, the application will redirect to page where the flow starts as soon as it finds that the session is not authenticated.
* In the API Token authentication setup, the application will be sending the token from the very first request. If the token is invalid the application
will encounter 401 error that it does not know how to handle and will crash.

The choice of the authentication method depends on your GoodData Cloud instance/GoodData.CN installation setup:

- If your GoodData Cloud instance/GoodData.CN installation is set up with CORS and allows the `https://localhost:3000` origin, then you can use the
OIDC authentication flow even while developing the application on your workstation. To do this, set the `REACT_APP_SET_HOSTNAME` env
variable to `true`.

- If your GoodData Cloud instance/GoodData.CN installation does not allow cross origin requests, then you must use API token authentication method. To
enable this make sure that the `REACT_APP_SET_HOSTNAME` is not set and that the `REACT_APP_DEV_TIGER_API_TOKEN` is
set and contains a valid API Token.

In this setup, the application will not communicate with the GoodData Cloud/GoodData.CN backend directly. It will use a 'development proxy'
running inside webpack dev server. Requests to all `/api` resources will be proxied to your GoodData Cloud instance/GoodData.CN installation running at
location specified in [constants.js](./src/constants.js) `backend` property.

**IMPORTANT: If you have to go with the API token, make sure you specify the token in the `.env.development.local` file. This ensures
that the value of your token will not leak into production build.**

### Getting started

Before you can create visualizations for data in your workspace, you need to export its Logical Data Model (LDM). You can
then use the exported LDM entities to define the visualizations.

The export is simple: run the `npm run refresh-md` command.

- This script will use information from [constants.js](./src/constants.js). It will connect to GoodData servers running
on the host specified in the `backend` property and [export](https://sdk.gooddata.com/gooddata-ui/docs/export_catalog.html) MD for the `workspace` of your choice.

- The script will use GoodData Cloud/GoodData.CN API Token for authentication. You need to set the `TIGER_API_TOKEN` env variable with the Token.

Once done, you will find that the [src/md/full.js](src/md/full.js) file will be populated with attribute and measure definitions
matching the MD defined in your workspace. You can then use these generated definitions as inputs to the different
[visualization components](https://sdk.gooddata.com/gooddata-ui/docs/start_with_visual_components.html) available in GoodData.UI SDK.

**Note: Before running this script, please make sure `backend` is defined in `constants.js` file.**

### Deployment

To deploy the application, you can run

```bash
npm run build
```

which will create a `build` folder with all the build outputs that can you can then host anyway you want. Built like this, the application will assume that the GoodData Analytical Backend is hosted on the same host as the application itself.

In case you want to host the application on a host other than the one you use to host the GoodData Analytical Backend, you should build the application like this

```bash
npm run build-with-explicit-hostname
```

Built like this, the application will connect to the GoodData Analytical Backend hosted at the host specified in `src/constants.js` in `backend` field.
4 changes: 4 additions & 0 deletions spreadjs/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const enzyme = require("enzyme");
const Adapter = require("@wojtekmaj/enzyme-adapter-react-17");

enzyme.configure({ adapter: new Adapter() });
7 changes: 7 additions & 0 deletions spreadjs/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"checkJs": true,
"jsx": "react"
},
"exclude": ["node_modules"]
}
86 changes: 86 additions & 0 deletions spreadjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"name": "spreadjs",
"version": "0.1.0",
"private": true,
"dependencies": {
"@gooddata/sdk-backend-tiger": "^8.10.0",
"@gooddata/sdk-model": "^8.10.0",
"@gooddata/sdk-ui": "^8.10.0",
"@gooddata/sdk-ui-charts": "^8.10.0",
"@gooddata/sdk-ui-dashboard": "^8.10.0",
"@gooddata/sdk-ui-ext": "^8.10.0",
"@gooddata/sdk-ui-filters": "^8.10.0",
"@gooddata/sdk-ui-geo": "^8.10.0",
"@gooddata/sdk-ui-pivot": "^8.10.0",
"@grapecity/spread-sheets": "^15.2.0",
"@grapecity/spread-sheets-react": "^15.2.0",
"classnames": "^2.3.1",
"formik": "^2.2.9",
"lodash": "^4.17.15",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
"react-router-dom": "^5.3.0",
"react-router-use-location-state": "^2.3.1",
"react-scripts": "5.0.1",
"use-location-state": "^2.3.1",
"yup": "^0.32.9"
},
"scripts": {
"start": "cross-env HTTPS=true PORT=8443 GENERATE_SOURCEMAP=false react-scripts start",
"build": "react-scripts build",
"build-with-explicit-hostname": "cross-env REACT_APP_SET_HOSTNAME=true npm run build",
"eject": "react-scripts eject",
"test": "react-scripts test --setupFilesAfterEnv ./jest.setup.js",
"testcafe-backend": "rm -R ./build & yarn build & serve -l 5000 build",
"testcafe": "cross-env TEST_BACKEND=http://localhost:5000 ./scripts/run-testcafe.js",
"testcafe-visual": "cross-env TEST_MODE=visual ./scripts/run-testcafe.js",
"refresh-md": "node ./scripts/refresh-md.js --backend tiger"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not ie 11",
"not chrome < 51",
"not safari < 10",
"not android < 51"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/plugin-transform-typescript": "^7.16.1",
"@babel/preset-env": "^7.16.5",
"@babel/preset-typescript": "^7.16.5",
"@babel/register": "^7.16.5",
"@gooddata/catalog-export": "^8.10.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.6",
"babel-plugin-add-module-exports": "^1.0.4",
"cross-env": "^5.2.0",
"enzyme": "^3.10.0",
"husky": "^3.0.0",
"prettier": "2.5.1",
"pretty-quick": "^3.1.3",
"sass": "^1.45.1",
"serve": "^11.3.2",
"testcafe": "^1.18.3",
"typescript": "^4.1.5"
},
"resolutions": {},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged --pattern \"**/*.*(js|jsx|ts|tsx|scss)\""
}
},
"engines": {
"node": ">=12.15.0"
}
}
Binary file added spreadjs/public/favicon.ico
Binary file not shown.
37 changes: 37 additions & 0 deletions spreadjs/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
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>GoodData App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
--></body>
</html>
15 changes: 15 additions & 0 deletions spreadjs/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "GoodData App",
"name": "Create GoodData App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
12 changes: 12 additions & 0 deletions spreadjs/scripts/refresh-md.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env node

require("@babel/register")({
presets: ["@babel/preset-typescript", "@babel/preset-env"],
plugins: ["add-module-exports"],
extensions: [".ts", ".js"],
});

const { workspace, backend } = require("../src/constants");
const path = "./src/md/full.js";
process.argv.push("--workspace-id", workspace, "--hostname", backend, "--output", path);
require("../node_modules/@gooddata/catalog-export");
Loading

0 comments on commit 00bbfaf

Please sign in to comment.