diff --git a/spreadjs/.dockerignore b/spreadjs/.dockerignore new file mode 100644 index 00000000..b512c09d --- /dev/null +++ b/spreadjs/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/spreadjs/.env b/spreadjs/.env new file mode 100644 index 00000000..6f809cc2 --- /dev/null +++ b/spreadjs/.env @@ -0,0 +1 @@ +SKIP_PREFLIGHT_CHECK=true diff --git a/spreadjs/.gitignore b/spreadjs/.gitignore new file mode 100644 index 00000000..507886b2 --- /dev/null +++ b/spreadjs/.gitignore @@ -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 \ No newline at end of file diff --git a/spreadjs/.nvmrc b/spreadjs/.nvmrc new file mode 100644 index 00000000..cab13a79 --- /dev/null +++ b/spreadjs/.nvmrc @@ -0,0 +1 @@ +v14.17.0 diff --git a/spreadjs/.prettierrc b/spreadjs/.prettierrc new file mode 100644 index 00000000..5f1a4ce9 --- /dev/null +++ b/spreadjs/.prettierrc @@ -0,0 +1,5 @@ +{ + "printWidth": 110, + "tabWidth": 4, + "trailingComma": "all" +} diff --git a/spreadjs/HOWTO.md b/spreadjs/HOWTO.md new file mode 100644 index 00000000..8e2ea85e --- /dev/null +++ b/spreadjs/HOWTO.md @@ -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.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+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.
+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.
+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 diff --git a/spreadjs/README.md b/spreadjs/README.md new file mode 100644 index 00000000..5a554658 --- /dev/null +++ b/spreadjs/README.md @@ -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. diff --git a/spreadjs/jest.setup.js b/spreadjs/jest.setup.js new file mode 100644 index 00000000..fa686d8a --- /dev/null +++ b/spreadjs/jest.setup.js @@ -0,0 +1,4 @@ +const enzyme = require("enzyme"); +const Adapter = require("@wojtekmaj/enzyme-adapter-react-17"); + +enzyme.configure({ adapter: new Adapter() }); diff --git a/spreadjs/jsconfig.json b/spreadjs/jsconfig.json new file mode 100644 index 00000000..a01d49df --- /dev/null +++ b/spreadjs/jsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "checkJs": true, + "jsx": "react" + }, + "exclude": ["node_modules"] +} diff --git a/spreadjs/package.json b/spreadjs/package.json new file mode 100644 index 00000000..a774903b --- /dev/null +++ b/spreadjs/package.json @@ -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" + } +} diff --git a/spreadjs/public/favicon.ico b/spreadjs/public/favicon.ico new file mode 100644 index 00000000..8913c4c3 Binary files /dev/null and b/spreadjs/public/favicon.ico differ diff --git a/spreadjs/public/index.html b/spreadjs/public/index.html new file mode 100644 index 00000000..50dc50d0 --- /dev/null +++ b/spreadjs/public/index.html @@ -0,0 +1,37 @@ + + + + + + + + + + + GoodData App + + + +
+ + diff --git a/spreadjs/public/manifest.json b/spreadjs/public/manifest.json new file mode 100644 index 00000000..7959d354 --- /dev/null +++ b/spreadjs/public/manifest.json @@ -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" +} diff --git a/spreadjs/scripts/refresh-md.js b/spreadjs/scripts/refresh-md.js new file mode 100644 index 00000000..ca813eae --- /dev/null +++ b/spreadjs/scripts/refresh-md.js @@ -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"); diff --git a/spreadjs/scripts/run-testcafe.js b/spreadjs/scripts/run-testcafe.js new file mode 100755 index 00000000..b667e8c3 --- /dev/null +++ b/spreadjs/scripts/run-testcafe.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +const createTestCafe = require("testcafe"); + +const LOCAL_CONCURRENCY = 4; +const ASSERTION_TIMEOUT = 15000; +const SELECTOR_TIMEOUT = 30000; +const WINDOW_WIDTH = 1920; +const WINDOW_HEIGHT = 1080; +// For some reason testcafe has problems using globstar so we need to specify +// maximum directory depth, otherwise it just picks up tests in the deepest directory. +const TESTS_PATH = "tests/**/**/**/*.spec.js"; + +const CHROME_HEADLESS_LOCAL = `chrome:headless --window-size='${WINDOW_WIDTH},${WINDOW_HEIGHT}' --no-sandbox`; +const CHROME_LOCAL = `chrome --window-size='${WINDOW_WIDTH},${WINDOW_HEIGHT}' --no-sandbox --disable-background-timer-throttling`; + +let testcafe = null; + +createTestCafe("localhost") + .then((tc) => { + testcafe = tc; + const runner = testcafe.createRunner(); + const mode = process.env.TEST_MODE; + + const runnerBase = runner.src([TESTS_PATH]); + + if (mode === "visual") { + console.log("Starting TestCafe in visual-local mode without concurrency."); + return runnerBase.browsers([CHROME_LOCAL]).run({ + assertionTimeout: ASSERTION_TIMEOUT, + selectorTimeout: SELECTOR_TIMEOUT, + debugOnFail: true, + }); + } + + console.log(`Starting TestCafe in local mode with concurrency ${LOCAL_CONCURRENCY}.`); + return runnerBase.browsers([CHROME_HEADLESS_LOCAL]).concurrency(LOCAL_CONCURRENCY).run({ + assertionTimeout: ASSERTION_TIMEOUT, + selectorTimeout: SELECTOR_TIMEOUT, + }); + }) + .then((failedCount) => { + testcafe.close(); + if (failedCount > 0) { + process.exit(1); + } + }) + .catch((e) => { + console.error(e.message); + testcafe.close(); + process.exit(1); + }); diff --git a/spreadjs/src/App.js b/spreadjs/src/App.js new file mode 100644 index 00000000..5a85f503 --- /dev/null +++ b/spreadjs/src/App.js @@ -0,0 +1,19 @@ +import { BackendProvider } from "@gooddata/sdk-ui"; + +import AppRouter from "./routes/AppRouter"; +import { useAuth } from "./contexts/Auth"; +import { WorkspaceListProvider } from "./contexts/WorkspaceList"; + +function App() { + const { backend } = useAuth(); + + return ( + + + + + + ); +} + +export default App; diff --git a/spreadjs/src/components/Auth/LoginForm.js b/spreadjs/src/components/Auth/LoginForm.js new file mode 100644 index 00000000..1852ed9b --- /dev/null +++ b/spreadjs/src/components/Auth/LoginForm.js @@ -0,0 +1,122 @@ +import React from "react"; +import cx from "classnames"; +import { withRouter } from "react-router-dom"; +import { useFormik } from "formik"; +import { string, object } from "yup"; + +import { backend } from "../../constants"; +import CustomLoading from "../CustomLoading"; +import Input from "../controls/Input"; +import Label from "../controls/Label"; +import Button from "../controls/Button"; + +import sharedStyles from "../../shared.module.scss"; +import styles from "./LoginForm.module.scss"; + +import logoUri from "../../media/logo-new.png"; + +const LoginFormComponent = (props) => { + const { values, touched, errors, isSubmitting, handleChange, handleBlur, handleSubmit } = useFormik({ + initialValues: { + email: props.email, + password: props.password, + }, + + validationSchema: object().shape({ + email: string().email("Invalid e-mail address").required("E-mail is required"), + password: string().required("Password is required"), + }), + + onSubmit: ({ email, password }, { setSubmitting, setFieldError }) => { + return props.login(email, password).then( + () => props.history.push("/"), + (error) => { + setSubmitting(false); + if (error.response && error.response.status === 401) { + setFieldError("password", "E-mail or password is invalid"); + } else { + setFieldError("password", "Unknown error"); + } + }, + ); + }, + }); + + return ( + <> + {props.loginError &&
{props.loginError}
} +
+
+ GoodData +
+

+ Please sign in to the{" "} + + {backend.replace(/https?:\/\//, "")} + {" "} + domain +

+
+ + + + {errors.email && touched.email &&
{errors.email}
} +
+
+ + + + {errors.password && touched.password && ( +
{errors.password}
+ )} +
+
+ +
+
+ + ); +}; + +export default withRouter(LoginFormComponent); diff --git a/spreadjs/src/components/Auth/LoginForm.module.scss b/spreadjs/src/components/Auth/LoginForm.module.scss new file mode 100644 index 00000000..a813288a --- /dev/null +++ b/spreadjs/src/components/Auth/LoginForm.module.scss @@ -0,0 +1,118 @@ +@import "../../theme.scss"; +@import "../../mixins.scss"; + +.Login { + padding: $spacing; + background-color: $color-box; + margin: $spacing auto; + display: flex; + max-width: 300px; + flex-direction: column; + justify-content: center; + align-items: stretch; + align-self: center; + text-align: center; + border-radius: $border-radius; + box-shadow: rgba(0, 0, 0, 0.25) 0px $spacing $spacing * 0.5 0px; + color: $color-text; +} + +.LoginLogo { + text-align: center; +} + +.InputBlock { + text-align: left; + margin: $spacing * 0.5 0; +} + +.Label { + margin-bottom: $spacing * 0.25; +} + +.Error { + position: relative; + box-sizing: border-box; + display: block; + max-width: 100%; + margin-top: $spacing * 0.25; + padding: $spacing * 0.25 $spacing * 0.5; + min-height: 1px; + border-radius: 3px; + font-family: inherit; + font-size: $font-size-body; + text-align: left; + line-height: in; + color: $color-error; + background: transparentize($color-error, 0.85); + pointer-events: all; +} + +.Action { + margin-top: $spacing * 0.5; +} + +.Input.Input { + max-width: 100%; + padding: $spacing * 0.25 $spacing * 0.5; + border: 1px solid $color-border; + color: $color-text; + background: $color-paper; + border-radius: $border-radius; + box-shadow: inset 0 1px 1px 0 rgba(31, 53, 74, 0.15); + transition: 0.25s border-color ease, 0.25s color ease, 0.25s box-shadow ease; + + &:focus, + &:active { + border-color: $color-primary; + outline: 0; + box-shadow: inset 0 1px 1px 0 rgba(31, 53, 74, 0.2); + } + &::placeholder { + @include reset-appearance; + color: $color-text-muted; + } +} + +.Error { + box-shadow: inset 0 0 2px 0 transparentize($color-error, 0.5); +} + +// This button is styled so that it matches the usual login forms of the GoodData platform +.SubmitButton { + background-color: #fcfcfd; + border-radius: 3px; + border: 1px solid #ccd8e2; + box-shadow: 0 1px 1px 0 rgba(20, 56, 93, 0.15); + color: #778491; + cursor: pointer; + display: block; + font-family: avenir, "Helvetica Neue", arial, sans-serif; + font-size: 16px; + font-weight: 700; + height: 38px; + line-height: 22px; + outline: none; + padding: 7px 19px; + text-align: center; + transition-duration: 0.25s; + transition-property: all; + transition-timing-function: ease-in-out; + width: 100%; + + &:hover { + border-color: rgba(31, 52, 73, 0.2); + box-shadow: 0 1px 1px 0 rgba(20, 56, 93, 0.15), inset 0 -1px 0 0 rgba(177, 193, 209, 0.6); + color: #464e56; + background: #f5f8fa; + } + + &:active, + &:focus { + border-color: #b1c1d1; + box-shadow: inset 0 1px 0 0 rgba(177, 193, 209, 0.65); + color: #464e56; + background: #ecf0f5; + background-image: linear-gradient(to top, #dee6ef, #ecf0f5); + } +} diff --git a/spreadjs/src/components/Auth/LogoutForm.js b/spreadjs/src/components/Auth/LogoutForm.js new file mode 100644 index 00000000..5ed5a3ee --- /dev/null +++ b/spreadjs/src/components/Auth/LogoutForm.js @@ -0,0 +1,18 @@ +import React, { useEffect } from "react"; +import { withRouter } from "react-router-dom"; + +import CustomLoading from "../CustomLoading"; + +const LogoutForm = ({ history, logout }) => { + useEffect( + () => { + logout().then(() => history.push("/login")); + }, + // only call the logout on initial mount -> the empty array is correct here + [], // eslint-disable-line react-hooks/exhaustive-deps + ); + + return ; +}; + +export default withRouter(LogoutForm); diff --git a/spreadjs/src/components/CustomLoading.js b/spreadjs/src/components/CustomLoading.js new file mode 100644 index 00000000..da4101d3 --- /dev/null +++ b/spreadjs/src/components/CustomLoading.js @@ -0,0 +1,72 @@ +import React from "react"; +import cx from "classnames"; + +import styles from "./CustomLoading.module.scss"; + +const baseAnimationDuration = 1.8; + +export const CustomLoading = ({ + label = null, + inline = false, + height = "100%", + width = undefined, + imageHeight = "38px", + imageWidth = undefined, + color = "#14b2e2", + speed = 1, + className = null, +}) => { + const barStyle = { + transformOrigin: "0 100%", + animation: `GDC-pump ${baseAnimationDuration / speed}s infinite`, + fill: color, + }; + + const barStyle1 = { + ...barStyle, + animationDelay: `${(baseAnimationDuration / speed) * (-2 / 3)}s`, + }; + + const barStyle2 = { + ...barStyle, + animationDelay: `${baseAnimationDuration / speed / -3}s`, + }; + + return ( +
+ + + + + + + {label ?

{label}

: null} +
+ ); +}; + +export default CustomLoading; diff --git a/spreadjs/src/components/CustomLoading.module.scss b/spreadjs/src/components/CustomLoading.module.scss new file mode 100644 index 00000000..e0c7124b --- /dev/null +++ b/spreadjs/src/components/CustomLoading.module.scss @@ -0,0 +1,19 @@ +@import "../theme.scss"; + +.CustomLoading { + display: flex; + text-align: center; + flex-direction: column; + align-content: center; + justify-content: center; +} + +.Inline { + display: inline-flex; +} + +.SVG { + max-height: 100%; + max-width: 100%; + flex: 0 1 auto; +} diff --git a/spreadjs/src/components/Footer.js b/spreadjs/src/components/Footer.js new file mode 100644 index 00000000..1501a2f5 --- /dev/null +++ b/spreadjs/src/components/Footer.js @@ -0,0 +1,63 @@ +import React from "react"; + +import styles from "./Footer.module.scss"; + +import githubUri from "../media/github-logo.png"; +import stackOverflowUri from "../media/stack-overflow-logo.png"; +import twitterUri from "../media/twitter-logo.png"; +import npmUri from "../media/npm-logo.png"; + +const SocialItem = ({ link, title, imageUri }) => ( + + + {title} + +); + +const Footer = () => { + return ( + + ); +}; + +export default Footer; diff --git a/spreadjs/src/components/Footer.module.scss b/spreadjs/src/components/Footer.module.scss new file mode 100644 index 00000000..a4aa33e1 --- /dev/null +++ b/spreadjs/src/components/Footer.module.scss @@ -0,0 +1,54 @@ +.Footer { + font-size: 15px; + line-height: 24px; + background: rgba(89, 98, 107, 0.11); + color: #6d7680; + text-align: center; + + &Link { + color: inherit; + text-decoration: none; + + &:hover, + &:visited, + &:active, + &:focus { + color: inherit; + text-decoration: underline; + } + } +} + +.FooterLinks { + padding: 20px; + + &Header { + font-size: 1.5rem; + font-weight: 500; + margin: 1.5rem 0; + } +} + +.Social { + display: inline-block; + border-top: 1px solid rgba(109, 118, 128, 0.5); + margin: 0 auto; + padding: 1.5rem 0 0; + + .FooterLink { + margin-left: 10px; + margin-right: 10px; + } + + img { + height: 1.875rem; + margin-right: 0.6rem; + vertical-align: middle; + } +} + +.Copyright { + padding: 1rem 20px; + color: rgba(255, 255, 255, 0.8); + background-color: #404040; +} diff --git a/spreadjs/src/components/Header/Aside.js b/spreadjs/src/components/Header/Aside.js new file mode 100644 index 00000000..d18385be --- /dev/null +++ b/spreadjs/src/components/Header/Aside.js @@ -0,0 +1,32 @@ +import React from "react"; +import { Link } from "react-router-dom"; +import cx from "classnames"; + +import { useAuth } from "../../contexts/Auth"; +import { AuthStatus } from "../../contexts/Auth/state"; +import InlineLoading from "../InlineLoading"; + +import styles from "./Header.module.scss"; + +const Aside = () => { + const { authStatus } = useAuth(); + const { AUTHORIZED, LOGGING_IN, LOGGING_OUT, AUTHORIZING } = AuthStatus; + + return ( +
+ {[LOGGING_IN, LOGGING_OUT, AUTHORIZING].includes(authStatus) ? ( + + ) : authStatus === AUTHORIZED ? ( + + Logout + + ) : ( + + Login + + )} +
+ ); +}; + +export default Aside; diff --git a/spreadjs/src/components/Header/Header.js b/spreadjs/src/components/Header/Header.js new file mode 100644 index 00000000..c16c6c03 --- /dev/null +++ b/spreadjs/src/components/Header/Header.js @@ -0,0 +1,96 @@ +import React, { useState, useEffect, useCallback } from "react"; +import throttle from "lodash/throttle"; + +import { useAuth } from "../../contexts/Auth"; +import { AuthStatus } from "../../contexts/Auth/state"; +// uncomment the next line to use WorkspacePicker +// import WorkspacePicker from "../controls/WorkspacePicker"; + +import Logo from "./Logo"; +import Links from "./Links"; + +import styles from "./Header.module.scss"; + +const VerticalDelimiter = ({ ...restProps }) =>
; + +// a wrapper for items visible to authenticated users only (e.g. WorkspacePicker) +const ProtectedItems = ({ children }) => { + const { authStatus } = useAuth(); + if (authStatus !== AuthStatus.AUTHORIZED) return null; + return <>{children || null}; +}; + +const BurgerMenu = () => { + const [isOpen, setIsOpen] = useState(false); + return ( +
+ + {isOpen && ( +
+ + + {/* Uncomment these lines to add a workspace picker into the burger menu */} + {/*
+ +
*/} +
+
+ )} +
+ ); +}; + +const Header = () => { + const [windowWidth, setWindowWidth] = useState(window ? window.innerWidth : null); + + // eslint-disable-next-line react-hooks/exhaustive-deps + const handleResize = useCallback( + throttle(() => { + if (window) { + setWindowWidth(window.innerWidth); + } + }, 200), + [], + ); + + useEffect(() => { + window.addEventListener("resize", handleResize); + return () => { + window.removeEventListener("resize", handleResize); + }; + }, [handleResize]); + + // You need to set this manually to the smallest window width that can still fit all menu items + const isTooSmall = windowWidth && windowWidth < 666; + return ( + + ); +}; + +export default Header; diff --git a/spreadjs/src/components/Header/Header.module.scss b/spreadjs/src/components/Header/Header.module.scss new file mode 100644 index 00000000..e9333e95 --- /dev/null +++ b/spreadjs/src/components/Header/Header.module.scss @@ -0,0 +1,121 @@ +@import "../../theme.scss"; +@import "../../mixins.scss"; + +.Header { + position: fixed; + top: 0px; + right: 0px; + left: 0px; + min-height: $header-height; + display: flex; + flex-direction: row; + align-items: stretch; + z-index: 101; // must be higher than z-index of the sdk-ui-dashboard header (which is 100 currently) + padding: 0; + color: #4a4a4a; + background: #fdfdfd; + border-bottom: 1px solid $color-active; +} + +.Aside { + flex: 1 0 auto; + display: flex; + flex-direction: row; + align-items: stretch; + justify-content: flex-end; + padding-right: 10px; +} + +.Logo { + font-weight: bold; + text-transform: uppercase; +} + +.LogoImage { + height: 35px; +} + +.VerticalDelimiter { + width: 2px; + background-color: $color-border; + align-self: stretch; + margin: $spacing 0; +} + +.Centered { + margin: 0 $spacing * 0.5; + padding: 0 $spacing; + display: flex; + flex: 0 0 auto; + flex-direction: column; + justify-content: center; +} + +.Link { + margin: 0 $spacing * 0.5; + padding: 0 $spacing; + display: flex; + flex: 0 0 auto; + flex-direction: column; + justify-content: center; + text-decoration: none; + color: rgba(0, 0, 0, 0.9); + font-size: 15px; + border-bottom: 5px solid transparent; + transition: $transition-fast; + + &:hover, + &:visited, + &:active, + &:focus { + color: inherit; + border-color: rgb(70, 78, 86); + } + + &Active, + &Active:hover, + &Active:visited { + border-color: $color-active; + } +} + +.BurgerMenu { + display: flex; + flex-direction: column; + justify-content: center; + position: relative; +} + +.BurgerToggle { + @include reset-appearance; + margin-left: $spacing; + font-size: 1.5em; + margin-top: -4px; + width: 2em; + height: 2em; + text-align: center; + cursor: pointer; + border-radius: $border-radius; + + &:hover { + background-color: $color-accent-lighter; + } +} + +.BurgerContent { + position: fixed; + left: 0; + top: 64px; + min-width: 230px; + max-width: 100vw; + background-color: $color-paper; + z-index: 1000; + padding-bottom: $spacing; + @include box-shadow; + + .Link, + .Centered { + padding-bottom: $spacing * 0.25; + margin-top: $spacing; + } +} diff --git a/spreadjs/src/components/Header/Links.js b/spreadjs/src/components/Header/Links.js new file mode 100644 index 00000000..bb82d4ba --- /dev/null +++ b/spreadjs/src/components/Header/Links.js @@ -0,0 +1,24 @@ +import React from "react"; +import cx from "classnames"; +import { NavLink } from "react-router-dom"; + +import styles from "./Header.module.scss"; + +const Links = () => { + return ( + <> + + Welcome + + + Home + + + ); +}; + +export default Links; diff --git a/spreadjs/src/components/Header/Logo.js b/spreadjs/src/components/Header/Logo.js new file mode 100644 index 00000000..078ef537 --- /dev/null +++ b/spreadjs/src/components/Header/Logo.js @@ -0,0 +1,17 @@ +import React from "react"; +import cx from "classnames"; +import { NavLink } from "react-router-dom"; + +import { appName } from "../../constants"; + +import styles from "./Header.module.scss"; + +const Logo = () => { + return ( + + {appName} + + ); +}; + +export default Logo; diff --git a/spreadjs/src/components/Header/tests/Logo.spec.js b/spreadjs/src/components/Header/tests/Logo.spec.js new file mode 100644 index 00000000..5d2a7ff2 --- /dev/null +++ b/spreadjs/src/components/Header/tests/Logo.spec.js @@ -0,0 +1,11 @@ +import { shallow } from "enzyme"; + +import Logo from "../Logo"; +import { appName } from "../../../constants"; + +describe("Logo component", () => { + it("should render correctly app name", () => { + const wrapper = shallow(); + expect(wrapper.children().text()).toEqual(appName); + }); +}); diff --git a/spreadjs/src/components/InlineLoading.js b/spreadjs/src/components/InlineLoading.js new file mode 100644 index 00000000..5f2609a5 --- /dev/null +++ b/spreadjs/src/components/InlineLoading.js @@ -0,0 +1,7 @@ +import React from "react"; + +import CustomLoading from "./CustomLoading"; + +const InlineLoading = () => ; + +export default InlineLoading; diff --git a/spreadjs/src/components/Page.js b/spreadjs/src/components/Page.js new file mode 100644 index 00000000..63baeed1 --- /dev/null +++ b/spreadjs/src/components/Page.js @@ -0,0 +1,23 @@ +import React from "react"; +import { Helmet } from "react-helmet"; +import cx from "classnames"; + +import Header from "./Header/Header"; +import Footer from "./Footer"; + +import styles from "./Page.module.scss"; + +const Page = ({ children, className = null, mainClassName = null, title = "GoodData App" }) => { + return ( +
+ + {title} + +
+
{children}
+
+
+ ); +}; + +export default Page; diff --git a/spreadjs/src/components/Page.module.scss b/spreadjs/src/components/Page.module.scss new file mode 100644 index 00000000..4504da7f --- /dev/null +++ b/spreadjs/src/components/Page.module.scss @@ -0,0 +1,35 @@ +@import "../theme.scss"; + +.Page { + display: flex; + flex-direction: column; + align-items: stretch; + min-height: 100vh; + + :global { + .gd-dash-header-wrapper { + // offset the header so that the dashboard top bar is not hidden behind the application header when scrolling + top: $header-height !important; + } + } +} + +.Main { + flex: 1 0 auto; + padding: $spacing * 2 + 56px $spacing $spacing * 2 $spacing; + max-width: 1200px; + width: calc(100% - (#{$spacing} * 2)); + margin: 0 auto; +} + +.VerticalCenter { + display: flex; + flex-direction: column; + justify-content: center; + align-items: stretch; +} + +.Inverse { + background-color: $color-paper-inverse; + color: $color-text-inverse; +} diff --git a/spreadjs/src/components/controls/Button.js b/spreadjs/src/components/controls/Button.js new file mode 100644 index 00000000..51801463 --- /dev/null +++ b/spreadjs/src/components/controls/Button.js @@ -0,0 +1,14 @@ +import React from "react"; +import cx from "classnames"; + +import styles from "./Button.module.scss"; + +const Button = ({ className = null, type = "button", active = false, children, ...restProps }) => { + return ( + + ); +}; + +export default Button; diff --git a/spreadjs/src/components/controls/Button.module.scss b/spreadjs/src/components/controls/Button.module.scss new file mode 100644 index 00000000..6fb44c6d --- /dev/null +++ b/spreadjs/src/components/controls/Button.module.scss @@ -0,0 +1,26 @@ +@import "../../theme.scss"; +@import "../../mixins.scss"; + +.Button { + @include reset-appearance; + min-width: calc(1em + #{$spacing * 0.5}); + padding: 0 ($spacing * 0.25); + text-align: center; + border-radius: $border-radius; + cursor: pointer; + color: $color-accent; + transition: 0.3 background-color ease, 0.3 color ease; + background: $color-paper; + + &.Active { + background-color: $color-accent; + color: $color-paper; + } + + &:hover, + :focus, + :active { + background-color: $color-accent-lighter; + color: $color-accent; + } +} diff --git a/spreadjs/src/components/controls/Input.js b/spreadjs/src/components/controls/Input.js new file mode 100644 index 00000000..44e1b41a --- /dev/null +++ b/spreadjs/src/components/controls/Input.js @@ -0,0 +1,12 @@ +import React from "react"; +import cx from "classnames"; + +import styles from "./Input.module.scss"; + +const Input = ({ className = null, type = "text", hasError = false, ...restProps }) => { + return ( + + ); +}; + +export default Input; diff --git a/spreadjs/src/components/controls/Input.module.scss b/spreadjs/src/components/controls/Input.module.scss new file mode 100644 index 00000000..3d7b5c17 --- /dev/null +++ b/spreadjs/src/components/controls/Input.module.scss @@ -0,0 +1,23 @@ +@import "../../theme.scss"; +@import "../../mixins.scss"; + +.Input { + @include reset-appearance; + width: 100%; + display: block; + font-size: inherit; + border-bottom: 2px solid $color-grey; + + &::placeholder { + color: $color-grey; + } + + &:hover, + &:focus { + border-color: $color-primary; + } +} + +.Error { + border-color: transparentize($color-error, 0.5); +} diff --git a/spreadjs/src/components/controls/Label.js b/spreadjs/src/components/controls/Label.js new file mode 100644 index 00000000..ab7af0f4 --- /dev/null +++ b/spreadjs/src/components/controls/Label.js @@ -0,0 +1,14 @@ +import React from "react"; +import cx from "classnames"; + +import styles from "./Label.module.scss"; + +const Label = ({ className = null, type = "text", children, hasError = false, ...restProps }) => { + return ( + + ); +}; + +export default Label; diff --git a/spreadjs/src/components/controls/Label.module.scss b/spreadjs/src/components/controls/Label.module.scss new file mode 100644 index 00000000..ca8a6e56 --- /dev/null +++ b/spreadjs/src/components/controls/Label.module.scss @@ -0,0 +1,13 @@ +@import "../../theme.scss"; + +.Label { + display: block; + color: $color-text-muted; + font-size: inherit; + text-transform: uppercase; + font-weight: 500; +} + +.Error { + color: desaturate($color-error, 25%); +} diff --git a/spreadjs/src/components/controls/WorkspacePicker.js b/spreadjs/src/components/controls/WorkspacePicker.js new file mode 100644 index 00000000..8f2d23e9 --- /dev/null +++ b/spreadjs/src/components/controls/WorkspacePicker.js @@ -0,0 +1,62 @@ +import React from "react"; +import last from "lodash/last"; + +import InlineLoading from "../InlineLoading"; +import { useWorkspace } from "../../contexts/Workspace"; +import { useWorkspaceList } from "../../contexts/WorkspaceList"; + +import styles from "./WorkspacePicker.module.scss"; + +const getWorkspaceId = (workspace) => workspace && last(workspace.id.split("/")); + +const isInList = (workspaceId, workspaceList) => { + return ( + workspaceId && + workspaceList && + workspaceList.some((workspace) => getWorkspaceId(workspace) === workspace.id) + ); +}; + +const workspaceOptions = (workspaces) => + workspaces.map((workspace) => { + const constWorkspace = getWorkspaceId(workspace); + return ( + + ); + }); + +const WorkspacePicker = () => { + const { workspace, setWorkspace } = useWorkspace(); + const workspaceList = useWorkspaceList(); + + if (workspaceList.isLoading) return ; + + if (workspaceList.error) return
{"Error loading workspaces"}
; + + if (!workspaceList.data || !workspaceList.data.length) return
{"No workspaces available."}
; + + if (workspaceList.data.length === 1) + return
{workspaceList.data[0].title}
; + + return ( +
+ +
+ ); +}; + +export default WorkspacePicker; diff --git a/spreadjs/src/components/controls/WorkspacePicker.module.scss b/spreadjs/src/components/controls/WorkspacePicker.module.scss new file mode 100644 index 00000000..c1e78a92 --- /dev/null +++ b/spreadjs/src/components/controls/WorkspacePicker.module.scss @@ -0,0 +1,36 @@ +@import "../../theme.scss"; + +$color-workspacepicker: rgba(75, 75, 75, 0.9); +$textsize: 15px; + +.WorkspacePickerContainer { + height: 100%; +} + +.WorkspacePicker { + width: 100%; + height: 100%; + font-size: $textsize; + cursor: pointer; + border-radius: 0; + background-color: #fdfdfd; + border: none; + color: $color-workspacepicker; + + &:hover, + &:visited, + &:active, + &:focus { + outline: none; + } + + /* For IE <= 11 */ + ::-ms-expand { + display: none; + } +} + +.OneWorkspace { + font-size: $textsize; + color: $color-workspacepicker; +} diff --git a/spreadjs/src/components/controls/tests/Button.spec.js b/spreadjs/src/components/controls/tests/Button.spec.js new file mode 100644 index 00000000..e2bc36c8 --- /dev/null +++ b/spreadjs/src/components/controls/tests/Button.spec.js @@ -0,0 +1,12 @@ +import { shallow } from "enzyme"; + +import Button from "../Button"; + +describe("Button component", () => { + it("should render children", () => { + const childrenClassName = "children"; + const children =
; + const wrapper = shallow(