From d49768f3cb10651074921667cb997cf3dcbf65d7 Mon Sep 17 00:00:00 2001 From: Mario Rodeghiero Date: Fri, 11 Sep 2020 11:28:21 -0300 Subject: [PATCH] [refactor][m]: refactor code to use the new skd adjustments - #17 --- package.json | 2 +- src/App.css | 2 +- src/components/Upload/index.jsx | 26 +++++++------------------- yarn.lock | 4 ++-- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 203f9a3..cbc8b23 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "dependencies": { "axios": "^0.19.2", - "ckan3-js-sdk": "datopian/ckan3-js-sdk", + "ckanClient": "git+https://github.com/datopian/ckan-client-js", "data.js": "git+https://github.com/datopian/data.js.git", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/src/App.css b/src/App.css index a32b2c5..d1d146a 100644 --- a/src/App.css +++ b/src/App.css @@ -31,7 +31,7 @@ code { min-height: 60%; display: grid; grid-template-columns: 1fr 1fr; - grid-template-rows: auto 500px auto auto; + grid-template-rows: auto 300px auto auto; grid-template-areas: "header header" "uploadArea uploadArea" diff --git a/src/components/Upload/index.jsx b/src/components/Upload/index.jsx index 70064be..bf93f23 100644 --- a/src/components/Upload/index.jsx +++ b/src/components/Upload/index.jsx @@ -1,5 +1,5 @@ import React from "react"; -import { Uploader, FileAPI } from "ckan3-js-sdk"; +import { Client, Open } from "ckanClient"; import data from "data.js"; import toArray from "stream-to-array"; import PropTypes from "prop-types"; @@ -74,9 +74,9 @@ class Upload extends React.Component { const { authToken, api, organizationId, datasetId } = config; // create an instance of a object - const file = new FileAPI.HTML5File(selectedFile); + const file = new Open.HTML5File(selectedFile); - const uploader = new Uploader( + const client = new Client( `${authToken}`, `${organizationId}`, `${datasetId}`, @@ -90,21 +90,9 @@ class Upload extends React.Component { }); // Get the JWT token from authz and upload file to the storage - fetch(`${authzUrl}`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: authToken, - }, - body: JSON.stringify(scopes), - }) - .then((response) => response.json()) - .then((response) => - uploader.push(file, response.result.token, this.onUploadProgress) - ) - .then((response) => - this.setState({ success: response.success, loading: false }) - ) + client.ckanAuthz(`${authzUrl}`) + .then((response) => client.push(file, response.result.token, this.onUploadProgress)) + .then((response) => this.setState({ success: response.success, loading: false })) .catch((error) => this.setState({ error: true, loading: false })); }; @@ -170,7 +158,7 @@ Upload.defaultProps = { scopes: { scopes: [`obj:myorg/data-test-2/*:read,write`], }, - authzUrl: "http://localhost:5000/api/action/authz_authorize", + authzUrl: "http://localhost:5000", }; Upload.propTypes = { diff --git a/yarn.lock b/yarn.lock index 8c122fc..9a66a88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6224,9 +6224,9 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: inherits "^2.0.1" safe-buffer "^5.0.1" -ckan3-js-sdk@datopian/ckan3-js-sdk: +"ckanClient@git+https://github.com/datopian/ckan-client-js": version "1.0.0" - resolved "https://codeload.github.com/datopian/ckan3-js-sdk/tar.gz/010eb8bbc4eb81ffbaefccc9245db8d596ffe8c3" + resolved "git+https://github.com/datopian/ckan-client-js#1edf3373dce9449c453b44aae25bda6c1284f538" dependencies: axios "^0.19.2" crypto-js "^4.0.0"