Skip to content

Commit

Permalink
cgra-slider - RSuite Slider
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsBunny338 committed Nov 3, 2021
1 parent c33ba4b commit 0b89722
Show file tree
Hide file tree
Showing 10 changed files with 6,021 additions and 176 deletions.
114 changes: 13 additions & 101 deletions cgra-slider/README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,24 @@
## GoodData.UI Accelerator Toolkit Application
# Slider

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).

### 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 command 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.
- If your configuration does not specify `workspace`, the script will prompt you to choose one of the workspaces available in the `backend`.

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.**

**Hint: To avoid constantly typing in credentials, you can create `.gdcatalogrc` file where you define your `username` and `password`.**

### Deployment

There are two ways to deploy your application.

1. If your domain does not have CORS set up and you want to get up and running fast, you can use the pre-configured Docker image included with the app.
2. If the Docker way is not suitable for you, you can build and deploy the app manually (keep in mind that you will have to setup CORS on your GoodData domain so that it allows access from your application).

#### Using the built-in Docker support
This demonstrates how you can easily implement a [Measure Value Filter](https://help.gooddata.com/doc/enterprise/en/dashboards-and-insights/analytical-designer/visualize-your-data/filters-in-analytical-designer/filter-insights-by-measure-values) using [RSuite RangeSlider](https://rsuitejs.com/components/slider) component.

The application comes with a simple Dockerfile. This image is a pre-configured nginx instance that both serves the application files and acts as a reverse proxy for your GoodData domain. In this deployment, your GoodData domain does not need any CORS setup because the application will only communicate with its origin server.
To use it, run these commands in your terminal:
## Backend

```bash
# build production version of your application
npm run build
# build the docker image
docker build -t your-tag .
# run the docker image
docker run \
--rm \
--publish 3000:8080 \
--name your-name \
--env BACKEND_HOST="secure.gooddata.com" \
--env BACKEND_URL="https://secure.gooddata.com" \
your-tag:latest
```
This app is designed to connect to workspace `xms7ga4tf3g3nzucd8380o2bev8oeknp` on https://live-examples-proxy.herokuapp.com/ domain, and does not require authentication.

The meaning of the `docker run` parameters is:
## Live demo

- `--publish 3000:8080` – expose the nginx running on port 8080 by default (you can change that if needed by adding `--env PORT=5000`, just make sure you update the `--publish` value accordingly), to port 3000 on your machine.
- `--name your-name` – assign a name to the container run.
- `--env BACKEND_HOST="secure.gooddata.com"` and `--env BACKEND_URL="https://secure.gooddata.com"` – set the host/URL where the GoodData analytical backend is running respectively. You need to change these values if you host GoodData on a different domain.
This app is deployed at https://gooddata-demo.s3.amazonaws.com/cgra-slider/index.html.

**IMPORTANT**: The Docker image is not setup with SSL certificates and thus by default offers no support for HTTPS. Read on to learn more.
## How to run locally

##### HTTPS on localhost
* `yarn install`
* `yarn start`

If you intend to use the Docker image on localhost and you need support for HTTPS, then you can use self-signed certificates.
## Screenshot

First generate the certificate and private key and store them in the `docker` directory.
![slider](public/slider.png)

```bash
cd docker
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
```
---

Then edit the [Dockerfile](./Dockerfile) and [docker/nginx.conf.template](./docker/nginx.conf.template) and uncomment the marked-up lines.

##### HTTPS in production

If you plan on hosting your application on platforms such as Heroku that solve the HTTPS transport and do the SSL termination
for you, then you do not have to set up anything - this image is good to go.

**IMPORTANT**: If your hosting does not provide SSL termination then we strongly recommend to not use this image as is. Your data or other
sensitive information will be at serious risk.

If you already own certificates issued by a trusted CA, then you can reconfigure the nginx to use them. The process is similar to
how you set up HTTPS on localhost.

If you do not own certificates but have your own domain then you can use the [Let's Encrypt](https://letsencrypt.org/) Certificate Authority. We recommend
that you switch the base image in the [Dockerfile](./Dockerfile) and use the [nginx-certbot](https://hub.docker.com/r/jonasal/nginx-certbot); this will
automate the certificate acquisition and renewal process for you.

#### Building and deploying manually

To deploy the application without the use of the provided Dockerfile, 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.
This project was bootstrapped with [GoodData.UI Accelerator Toolkit](https://sdk.gooddata.com/gooddata-ui/docs/create_new_application.html).
5 changes: 4 additions & 1 deletion cgra-slider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"react-router-dom": "^5.0.1",
"react-router-use-location-state": "^2.3.1",
"react-scripts": "4.0.3",
"rsuite": "^5.1.0",
"use-location-state": "^2.3.1",
"yup": "^0.32.9"
},
Expand All @@ -32,7 +33,9 @@
"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"
"refresh-md": "node ./scripts/refresh-md.js",
"buildgd": "cross-env PUBLIC_URL=/cgra-slider yarn build",
"syncgd": "s3cmd --config .s3cfg sync --delete-removed ./build/ s3://gooddata-demo/cgra-slider/"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
Binary file added cgra-slider/public/slider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions cgra-slider/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export const appName = "cgra-slider";

// The URL of analytical GoodData backend with workspaces, insights, metrics, attributes, datasets, and users
// that will be available to the application.
export const backend = "https://developer.na.gooddata.com";
export const backend = "https://live-examples-proxy.herokuapp.com/";

// The ID of workspace that is selected by default in the optional workspace picker component (located in the web
// application header). It is also a default setting for script that refreshes MD data used by the application.
// MD script shows list of available workspaces on backend in the case when the value is not set to any ID.
export const workspace = "";
export const workspace = "xms7ga4tf3g3nzucd8380o2bev8oeknp";

// RegExp used by optional workspace picker component (located in the web application header) to filter out
// workspaces that should not be rendered to the application user. Only the workspaces with title that match
Expand Down
16 changes: 6 additions & 10 deletions cgra-slider/src/contexts/Auth/backend.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import bearFactory, {
FixedLoginAndPasswordAuthProvider,
ContextDeferredAuthProvider,
AnonymousAuthProvider,
} from "@gooddata/sdk-backend-bear";

import { backend as hostname } from "../../constants";
import { backend } from "../../constants";

const backendConfig = process.env.REACT_APP_SET_HOSTNAME ? { hostname } : {};
export const createBackend = () =>
bearFactory({ hostname: backend }).withAuthentication(new AnonymousAuthProvider());

export const createBackend = () => {
return bearFactory(backendConfig).withAuthentication(new ContextDeferredAuthProvider());
};

export const backendWithCredentials = (backend, username, password) => {
return backend.withAuthentication(new FixedLoginAndPasswordAuthProvider(username, password));
};
export const backendWithCredentials = (backend, username, password) =>
backend.withAuthentication(new FixedLoginAndPasswordAuthProvider(username, password));
Loading

0 comments on commit 0b89722

Please sign in to comment.