From b45c70bd52713902a15b03bd7f0f9704cb5f0eb3 Mon Sep 17 00:00:00 2001 From: Alexander Andrews <45926661+alexander-e-andrews@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:08:18 -0400 Subject: [PATCH 1/6] CEC-2654: Map polls for curren visible area (#222) Update index.jsx Added some tests, still don't meet threshold Co-authored-by: Alexander Andrews --- src/components/Contexts/VehicleContext.jsx | 4 +- .../Contexts/VehicleContext.test.jsx | 53 +++++++ .../__snapshots__/index.test.jsx.snap | 130 ++++++++++++++++++ .../__snapshots__/popup.test.jsx.snap | 7 + src/components/VehicleMap/index.jsx | 85 +++++++----- src/components/VehicleMap/index.test.jsx | 30 ++++ src/components/VehicleMap/popup.jsx | 4 +- src/components/VehicleMap/popup.test.jsx | 43 ++++++ src/services/__mocks__/vehiclesAPI.js | 8 +- src/services/vehiclesAPI.js | 5 +- 10 files changed, 324 insertions(+), 45 deletions(-) create mode 100644 src/components/VehicleMap/__snapshots__/index.test.jsx.snap create mode 100644 src/components/VehicleMap/__snapshots__/popup.test.jsx.snap create mode 100644 src/components/VehicleMap/index.test.jsx create mode 100644 src/components/VehicleMap/popup.test.jsx diff --git a/src/components/Contexts/VehicleContext.jsx b/src/components/Contexts/VehicleContext.jsx index 3896f9d..e525ef7 100644 --- a/src/components/Contexts/VehicleContext.jsx +++ b/src/components/Contexts/VehicleContext.jsx @@ -89,10 +89,10 @@ export const VehicleProvider = ({ children }) => { } }; - const getLocations = async (token) => { + const getLocations = async (token, mapLocationInfo) => { try { setBusy(true); - const result = await api.getLocations(token); + const result = await api.getLocations(token, mapLocationInfo); if (result.error) throw new Error(`Get locations error. ${result.message}`); return result; diff --git a/src/components/Contexts/VehicleContext.test.jsx b/src/components/Contexts/VehicleContext.test.jsx index a8c79d5..867d8d9 100644 --- a/src/components/Contexts/VehicleContext.test.jsx +++ b/src/components/Contexts/VehicleContext.test.jsx @@ -9,6 +9,7 @@ import { } from "@testing-library/react"; import { VehicleProvider, useVehicleContext } from "./VehicleContext"; import { StatusProvider, useStatusContext } from "./StatusContext"; +import { act } from "react-dom/test-utils"; const checkVehicleResult = (error, busy, vehicle) => { checkBaseResults(error, busy); @@ -437,6 +438,56 @@ describe("VehicleContext", () => { checkBaseResults("", "false"); }); }); + + describe("Get Locations", () => { + var locationFilter = { + center: { + longitude: 0, + latitude: 0 + }, + width: 0, + height: 0 + } + + var locations; + beforeEach(() => { + const TestComp = () => { + const { busy, error, getLocations } = useVehicleContext(); + + return ( + <> +
{error}
+
{busy.toString()}
+ + + + + + + +`; diff --git a/src/components/Manifest/Update/index.jsx b/src/components/Manifest/Update/index.jsx new file mode 100644 index 0000000..e4897f5 --- /dev/null +++ b/src/components/Manifest/Update/index.jsx @@ -0,0 +1,185 @@ +import React, {useEffect, useState} from "react"; +import {useParams} from "react-router-dom"; +import { Redirect } from "react-router"; +import useStyles from "../../useStyles"; +import {ManifestsProvider, useManifestsContext} from "../../Contexts/ManifestsContext"; +import {useUserContext} from "../../Contexts/UserContext"; +import {useStatusContext} from "../../Contexts/StatusContext"; +import {Button, FormControl, InputLabel, Select, TextField} from "@material-ui/core"; + +const manifestTypes = [ + {value: "standard", label: "Standard"}, + {value: "forced", label: "Forced"}, +]; + +const emptyManifest = { + name: "", + version: "", +}; + +const MainForm = () => { + + const {manifest_id} = useParams(); + const classes = useStyles(); + + const [manifest, setManifest] = useState(null); + const [redirect, setRedirect] = useState(null); + + const {getManifest, busy, updateManifest} = useManifestsContext(); + const { + token: { + idToken: {jwtToken: token}, + }, + } = useUserContext(); + + const {setMessage, setTitle, setSitePath} = useStatusContext(); + + const [name, setName] = useState(""); + const [type, setType] = useState(""); + + + const changeName = (e) => { + setName(e.target.value); + } + + const changeType = (e) => { + setType(e.target.value); + }; + + const onSubmit = async (e) => { + e.preventDefault(); + try { + const data = {name, type}; + console.log(data); + const result = await updateManifest(manifest_id, data, token); + if (!result || result.error) return; + + setMessage(`Updated manifest ${manifest_id}`); + setRedirect(`/package-status/${manifest_id}`); + + } catch (e) { + setMessage(`Failed to update manifest ${manifest_id}`); + } + } + + useEffect(() => { + (async () => { + try { + const result = await getManifest(manifest_id, token); + if (result.error) { + throw new Error(`Get manifest error. ${result.message}`); + } else { + setManifest(result); + setName(result.name); + setType(result.type); + } + } catch (e) { + setMessage(e.message); + } + })(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [token]); + + useEffect(() => { + const curManifest = manifest ? manifest : emptyManifest; + + setTitle("Update Package"); + setSitePath([ + { + label: "Deployments", + link: "/packages", + }, + { + label: `Update Package ${curManifest.name} ${curManifest.version}`, + }, + ]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [manifest]); + + if (redirect && redirect.length > 0) { + return ; + } + + if (manifest === null) return
Loading Manifest...
; + + return ( +
+ + + + + + Type + + + + + + +
+ ); +} + +const ManifestUpdate = () => ( + + + +); + +export default ManifestUpdate; \ No newline at end of file diff --git a/src/components/Manifest/Update/index.test.jsx b/src/components/Manifest/Update/index.test.jsx new file mode 100644 index 0000000..d851193 --- /dev/null +++ b/src/components/Manifest/Update/index.test.jsx @@ -0,0 +1,45 @@ +jest.mock("../../Contexts/ManifestsContext"); +jest.mock("../../Contexts/UserContext"); + +import React from "react"; +import { render, waitFor } from "@testing-library/react"; +import { BrowserRouter } from "react-router-dom"; + +import { ManifestsProvider } from "../../Contexts/ManifestsContext"; +import { UserProvider, setToken } from "../../Contexts/UserContext"; +import { StatusProvider } from "../../Contexts/StatusContext"; +import ManifestUpdate from "."; +import { TEST_AUTH_OBJECT } from "../../../utils/testing"; +import addSnapshotSerializer from "../../../utils/snapshot"; + +const renderManifestUpdate = async () => { + const { container } = render( + + + + + + + + + ); + await waitFor(() => { + /* render */ + }); + + return container; +} + + +describe("Manifest Details Component", () => { + beforeAll(() => { + setToken(TEST_AUTH_OBJECT); + addSnapshotSerializer(expect); + }); + + it("Render", async () => { + setToken(TEST_AUTH_OBJECT); + const view = await renderManifestUpdate(); + expect(view).toMatchSnapshot(); + }); +}); diff --git a/src/components/Routes/SiteRoutes.jsx b/src/components/Routes/SiteRoutes.jsx index 626b014..1bb32fb 100644 --- a/src/components/Routes/SiteRoutes.jsx +++ b/src/components/Routes/SiteRoutes.jsx @@ -28,6 +28,7 @@ const Home = React.lazy(() => import("../Home")); const Manifests = React.lazy(() => import("../Manifest/List")); const ManifestDeploy = React.lazy(() => import("../Manifest/Deploy")); const ManifestStatus = React.lazy(() => import("../Manifest/Status")); +const ManifestUpdate = React.lazy(() => import("../Manifest/Update")); const PageNotFound = React.lazy(() => import("../404")); const SSOForm = React.lazy(() => import("../SSOForm")); const VehicleAddForm = React.lazy(() => import("../Cars/Add")); @@ -152,6 +153,14 @@ const SiteRoutes = () => { groups={groups} roles={[Roles.READ, Roles.CREATE]} /> + } + type={TYPES.PROTECTED} + token={token} + groups={groups} + roles={[Roles.READ, Roles.CREATE]} + /> } diff --git a/src/services/__mocks__/manifestsAPI.js b/src/services/__mocks__/manifestsAPI.js index 16adcdb..6404bc5 100644 --- a/src/services/__mocks__/manifestsAPI.js +++ b/src/services/__mocks__/manifestsAPI.js @@ -57,6 +57,13 @@ const manifestsAPI = { return { statuses: [] }; }, + updateManifest: async (id, data, token) => { + return { + id, + ...data, + } + }, + getManifest: async (id, token) => { return { id, diff --git a/src/services/manifestsAPI.js b/src/services/manifestsAPI.js index 6ad7205..33a6436 100644 --- a/src/services/manifestsAPI.js +++ b/src/services/manifestsAPI.js @@ -32,6 +32,19 @@ const manifestsAPI = { .catch(errorHandler); }, + updateManifest: async (manifest_id, data, token) => { + return fetch(`${API_ENDPOINT}/manifest?id=${manifest_id}`, { + method: "PUT", + headers: Object.assign( + { "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + body: JSON.stringify(data), + }) + .then(fetchRespHandler) + .catch(errorHandler); + }, + getManifests: async (search, token) => { const u = addQueryParams(`${API_ENDPOINT}/manifests`, search); return fetch(u, { From c5a86a5e6139dff73237416f6f65209d47fe40e5 Mon Sep 17 00:00:00 2001 From: Alexander Andrews <45926661+alexander-e-andrews@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:51:12 -0400 Subject: [PATCH 5/6] CEC-2269: Embdeded Superset (#228) Co-authored-by: Alexander Andrews --- .env.dev | 3 +- .env.local | 3 +- .env.prd | 3 +- .env.stg | 3 +- .env.template | 1 + package-lock.json | 119 +++++++++++++++++++++++++++++ package.json | 3 + src/components/Dashboard/index.css | 4 + src/components/Dashboard/index.jsx | 34 ++++++--- src/components/useStyles.jsx | 9 +++ src/services/superset.js | 36 ++++++++- 11 files changed, 201 insertions(+), 17 deletions(-) create mode 100644 src/components/Dashboard/index.css diff --git a/.env.dev b/.env.dev index a3ecbae..d342cd3 100644 --- a/.env.dev +++ b/.env.dev @@ -2,4 +2,5 @@ REACT_APP_CERT_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/certificate REACT_APP_AUTH_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/compute_auth REACT_APP_UPLOAD_SERVICE_URL=https://dev-gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://dev-ota-admin.cloud.fiskerinc.com -REACT_APP_SUPERSET_URL=https://dev-superset.cloud.fiskerinc.com/superset/dashboard/8/?native_filters_key=KPnPthpLQ8rT--6PUdsPzQAcwnleRGHk_3dg0PVYfrXc3SE6zZ2x0p7JuerAZ0Pg +REACT_APP_SUPERSET_URL=https://dev-superset-new.cloud.fiskerinc.com +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc \ No newline at end of file diff --git a/.env.local b/.env.local index 3a7953b..8647c32 100644 --- a/.env.local +++ b/.env.local @@ -2,4 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=http://localhost/compute_auth REACT_APP_CERT_SERVICE_URL=http://localhost/certificate REACT_APP_UPLOAD_SERVICE_URL=http://localhost/ota_update REACT_APP_AUTH_CALLBACK_URL=http://localhost:3000 -REACT_APP_SUPERSET_URL=https://dev-superset.cloud.fiskerinc.com/superset/dashboard/8/?native_filters_key=KPnPthpLQ8rT--6PUdsPzQAcwnleRGHk_3dg0PVYfrXc3SE6zZ2x0p7JuerAZ0Pg +REACT_APP_SUPERSET_URL=https://dev-superset-new.cloud.fiskerinc.com +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/.env.prd b/.env.prd index b8da28c..8ce4e7b 100644 --- a/.env.prd +++ b/.env.prd @@ -2,4 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=https://gw.cloud.fiskerinc.com/compute_auth REACT_APP_CERT_SERVICE_URL=https://gw.cloud.fiskerinc.com/certificate REACT_APP_UPLOAD_SERVICE_URL=https://gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://ota-admin.cloud.fiskerinc.com -REACT_APP_SUPERSET_URL=https://superset.cloud.fiskerinc.com/superset/dashboard/9/?native_filters_key=mfJ1VjGTcLUKz7gQs_DgClZhjcdNucYMrPruNibcyDnhkDwdHbAumBRVTpA5tFH_ +REACT_APP_SUPERSET_URL=https://superset.cloud.fiskerinc.com +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/.env.stg b/.env.stg index 46937f3..f8f36c8 100644 --- a/.env.stg +++ b/.env.stg @@ -2,4 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/compute_auth REACT_APP_CERT_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/certificate REACT_APP_UPLOAD_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://stg-ota-admin.cloud.fiskerinc.com -REACT_APP_SUPERSET_URL=https://stg-superset.cloud.fiskerinc.com/superset/dashboard/11/?native_filters_key=Vsj5MqKEPxPnyCgVzFWSSI3E_KgEJxD30afm_URlamPqBi6ypNKsaQ90YhQ6Fc54 +REACT_APP_SUPERSET_URL=https://stg-superset.cloud.fiskerinc.com +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/.env.template b/.env.template index 7d919f2..e79b9ab 100644 --- a/.env.template +++ b/.env.template @@ -3,3 +3,4 @@ REACT_APP_UPLOAD_SERVICE_URL=http://localhost/ota_update REACT_APP_AUTH_CALLBACK_URL=http://localhost:3000 REACT_APP_SUPERSET_URL=https://dev-superset.cloud.fiskerinc.com REACT_APP_CERT_SERVICE_URL=http://localhost/certificate +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/package-lock.json b/package-lock.json index 5c1f620..7211f78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,14 +16,17 @@ "@material-ui/core": "^4.12.4", "@material-ui/icons": "^4.11.3", "@material-ui/pickers": "^3.3.10", + "@superset-ui/embedded-sdk": "^0.1.0-alpha.7", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^12.1.4", "@testing-library/user-event": "^13.5.0", "axios": "^0.26.1", + "buffer": "^6.0.3", "clsx": "^1.1.1", "date-fns": "^2.29.2", "email-validator": "^2.0.4", "env-cmd": "^10.1.0", + "jwt-decode": "^3.1.2", "leaflet": "^1.8.0", "material-ui-dropzone": "^3.5.0", "moment": "^2.29.4", @@ -4540,6 +4543,19 @@ "@sinonjs/commons": "^1.7.0" } }, + "node_modules/@superset-ui/embedded-sdk": { + "version": "0.1.0-alpha.7", + "resolved": "https://registry.npmjs.org/@superset-ui/embedded-sdk/-/embedded-sdk-0.1.0-alpha.7.tgz", + "integrity": "sha512-sBzfSnPvRw15D6A053t4gpKDydHaAjyn88By1Z3Vl3PWZScW6sTHh8n/5A69qMSJVorqFQ3g0IUquTF8sutGEQ==", + "dependencies": { + "@superset-ui/switchboard": "^0.18.26-0" + } + }, + "node_modules/@superset-ui/switchboard": { + "version": "0.18.26-0", + "resolved": "https://registry.npmjs.org/@superset-ui/switchboard/-/switchboard-0.18.26-0.tgz", + "integrity": "sha512-MYvigrspA0EgNU6tA9UrsXcrUYid9YktsbIPx/D4Xd5cWWrJrJl303imQ/SIZbC25faJCd2gL30ORll60Yz3Ww==" + }, "node_modules/@surma/rollup-plugin-off-main-thread": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz", @@ -6343,6 +6359,25 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -6497,6 +6532,29 @@ "node-int64": "^0.4.0" } }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -10007,6 +10065,25 @@ "node": ">=4" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -11682,6 +11759,11 @@ "node": ">=4.0" } }, + "node_modules/jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -20612,6 +20694,19 @@ "@sinonjs/commons": "^1.7.0" } }, + "@superset-ui/embedded-sdk": { + "version": "0.1.0-alpha.7", + "resolved": "https://registry.npmjs.org/@superset-ui/embedded-sdk/-/embedded-sdk-0.1.0-alpha.7.tgz", + "integrity": "sha512-sBzfSnPvRw15D6A053t4gpKDydHaAjyn88By1Z3Vl3PWZScW6sTHh8n/5A69qMSJVorqFQ3g0IUquTF8sutGEQ==", + "requires": { + "@superset-ui/switchboard": "^0.18.26-0" + } + }, + "@superset-ui/switchboard": { + "version": "0.18.26-0", + "resolved": "https://registry.npmjs.org/@superset-ui/switchboard/-/switchboard-0.18.26-0.tgz", + "integrity": "sha512-MYvigrspA0EgNU6tA9UrsXcrUYid9YktsbIPx/D4Xd5cWWrJrJl303imQ/SIZbC25faJCd2gL30ORll60Yz3Ww==" + }, "@surma/rollup-plugin-off-main-thread": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz", @@ -21979,6 +22074,11 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, "batch": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz", @@ -22107,6 +22207,15 @@ "node-int64": "^0.4.0" } }, + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -24686,6 +24795,11 @@ "harmony-reflect": "^1.4.6" } }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, "ignore": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", @@ -25913,6 +26027,11 @@ "object.assign": "^4.1.2" } }, + "jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", diff --git a/package.json b/package.json index 6117d3b..18caa41 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,17 @@ "@material-ui/core": "^4.12.4", "@material-ui/icons": "^4.11.3", "@material-ui/pickers": "^3.3.10", + "@superset-ui/embedded-sdk": "^0.1.0-alpha.7", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^12.1.4", "@testing-library/user-event": "^13.5.0", "axios": "^0.26.1", + "buffer": "^6.0.3", "clsx": "^1.1.1", "date-fns": "^2.29.2", "email-validator": "^2.0.4", "env-cmd": "^10.1.0", + "jwt-decode": "^3.1.2", "leaflet": "^1.8.0", "material-ui-dropzone": "^3.5.0", "moment": "^2.29.4", diff --git a/src/components/Dashboard/index.css b/src/components/Dashboard/index.css new file mode 100644 index 0000000..da22955 --- /dev/null +++ b/src/components/Dashboard/index.css @@ -0,0 +1,4 @@ +iframe { + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/src/components/Dashboard/index.jsx b/src/components/Dashboard/index.jsx index c58dbe6..3570980 100644 --- a/src/components/Dashboard/index.jsx +++ b/src/components/Dashboard/index.jsx @@ -1,27 +1,41 @@ import React, { useEffect } from "react"; -import ResponsiveIFrame from "../Controls/ResponsiveIFrame"; -import { SupersetDashboardURL } from "../../services/superset"; +import api from "../../services/superset"; import { useStatusContext } from "../Contexts/StatusContext"; -import useStyles from "../useStyles"; +import { useUserContext } from "../Contexts/UserContext"; +import './index.css' +import { embedDashboard } from "@superset-ui/embedded-sdk"; + const Dashboard = () => { - const classes = useStyles(); const { setTitle, setSitePath } = useStatusContext(); + const { + token: { + idToken: { jwtToken: token }, + }, + } = useUserContext(); + useEffect(() => { setTitle("Datascope"); setSitePath([]); + embedDashboard({ + id: api.SupersetDashboardID(), // given by the Superset embedding UI + supersetDomain: api.SupersetDashboardURL(), + mountPoint: document.getElementById("my-superset-container"), // any html element that can contain an iframe + fetchGuestToken: () => api.getGuestToken(token), + dashboardUiConfig: { hideTab: true, hideTitle: true }, // dashboard UI config: hideTitle, hideTab, hideChartControls (optional) + }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return ( - +
+
); }; +//style={{position:'absolute', top:0, left:0, bottom:0, right:0, width:'100%', height:'100%', border:'none', margin:0, padding:0, overflow:'hidden'}} export default Dashboard; diff --git a/src/components/useStyles.jsx b/src/components/useStyles.jsx index 9e81aa7..3b3a752 100644 --- a/src/components/useStyles.jsx +++ b/src/components/useStyles.jsx @@ -180,6 +180,15 @@ const useStyles = makeStyles((theme) => ({ width: "100%", height: "100%", }, + iframe: { + position: "absolute", + top: 0, + left: 0, + bottom: 0, + right: 0, + width: "100%", + height: "100%", + }, embeddedWrapper: { marginTop: 10, position: "relative", diff --git a/src/services/superset.js b/src/services/superset.js index f2ee331..3c13b81 100644 --- a/src/services/superset.js +++ b/src/services/superset.js @@ -1,5 +1,35 @@ -const SUPERSET_BASE_URL = process.env.REACT_APP_SUPERSET_URL; +import { + getAuthHeaderOptions, + addQueryParams, +} from "../utils/http"; -const SupersetDashboardURL = `${SUPERSET_BASE_URL}/r/3`; +//Added the token we got from the first authorization and set it as the auth token, and that allowed us to hit the request -export { SupersetDashboardURL }; +const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL; + +const supersetAPI = { + getGuestToken: async(token) => { + const u = addQueryParams(`${API_ENDPOINT}/dashboard/guest-token`); + let res = await fetch(u, { + method: "GET", + headers: Object.assign( + //{ "Content-Type": "application/json" }, + getAuthHeaderOptions(token) + ), + }) + let r = await res.json() + let q = r["token"] + return q + }, + SupersetDashboardURL: () => { + const SUPERSET_BASE_URL = process.env.REACT_APP_SUPERSET_URL; + return SUPERSET_BASE_URL + }, + SupersetDashboardID: () => { + const SUPERSET_BASE_ID = process.env.REACT_APP_SUPERSET_KEYS_LIST; + return SUPERSET_BASE_ID + } + +} + +export default supersetAPI; \ No newline at end of file From 843fddd0b7b2e976f891307e0dc280c1c174da61 Mon Sep 17 00:00:00 2001 From: Alexander Andrews <45926661+alexander-e-andrews@users.noreply.github.com> Date: Tue, 1 Nov 2022 12:55:04 -0400 Subject: [PATCH 6/6] CEC-3058: Update superset url (#230) Co-authored-by: Alexander Andrews --- .env.cec-prd | 3 ++- .env.prd | 2 +- .env.stg | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.env.cec-prd b/.env.cec-prd index e19a5b5..51200bb 100644 --- a/.env.cec-prd +++ b/.env.cec-prd @@ -2,4 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=https://gw.cec-prd.fiskerinc.com/compute_auth REACT_APP_CERT_SERVICE_URL=https://gw.cec-prd.fiskerinc.com/certificate REACT_APP_UPLOAD_SERVICE_URL=https://gw.cec-prd.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://ota-admin.cec-prd.fiskerinc.com -REACT_APP_SUPERSET_URL=https://superset.cec-prd.fiskerinc.com/superset/dashboard/9/?native_filters_key=mfJ1VjGTcLUKz7gQs_DgClZhjcdNucYMrPruNibcyDnhkDwdHbAumBRVTpA5tFH_ +REACT_APP_SUPERSET_URL=https://dev-superset-new.cloud.fiskerinc.com +REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/.env.prd b/.env.prd index 8ce4e7b..16c180c 100644 --- a/.env.prd +++ b/.env.prd @@ -2,5 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=https://gw.cloud.fiskerinc.com/compute_auth REACT_APP_CERT_SERVICE_URL=https://gw.cloud.fiskerinc.com/certificate REACT_APP_UPLOAD_SERVICE_URL=https://gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://ota-admin.cloud.fiskerinc.com -REACT_APP_SUPERSET_URL=https://superset.cloud.fiskerinc.com +REACT_APP_SUPERSET_URL=https://dev-superset-new.cloud.fiskerinc.com REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc diff --git a/.env.stg b/.env.stg index f8f36c8..ebe7bc6 100644 --- a/.env.stg +++ b/.env.stg @@ -2,5 +2,5 @@ REACT_APP_AUTH_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/compute_auth REACT_APP_CERT_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/certificate REACT_APP_UPLOAD_SERVICE_URL=https://stg-gw.cloud.fiskerinc.com/ota_update REACT_APP_AUTH_CALLBACK_URL=https://stg-ota-admin.cloud.fiskerinc.com -REACT_APP_SUPERSET_URL=https://stg-superset.cloud.fiskerinc.com +REACT_APP_SUPERSET_URL=https://dev-superset-new.cloud.fiskerinc.com REACT_APP_SUPERSET_KEYS_LIST=0b01ac72-9ef4-4a5f-be34-b1ac0bf972cc