Skip to content

Commit f111cf0

Browse files
authored
Merge pull request #25 from blue-core-lod/t18-export-button
Updates Transfer to use BC API export endpoint
2 parents 8f2d7dd + a3b61e3 commit f111cf0

File tree

4 files changed

+20
-36
lines changed

4 files changed

+20
-36
lines changed

src/Config.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,7 @@ class Config {
122122
return {
123123
ils: {
124124
// group: label
125-
stanford: "Catalog",
126-
cornell: "Catalog",
127-
penn: "Catalog",
128-
ucdavis: "Catalog",
129-
princeton: "Catalog",
130-
northwestern: "Catalog",
131-
dnal: "Catalog",
132-
miami: "Catalog",
133-
harvard: "Catalog",
134-
emory: "Catalog",
135-
newcastle: "Catalog",
136-
leeds: "Catalog",
137-
memorial: "Catalog",
138-
jmu: "Catalog",
139-
brandeis: "Catalog",
140-
PUC: "Catalog",
141-
utoronto: "Catalog",
142-
ucf: "Catalog",
143-
usf: "Catalog",
125+
"blue core": "Catalog",
144126
},
145127
// Can add additional transfer targets, e.g., discovery
146128
}

src/actionCreators/transfer.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { postTransfer } from "../sinopiaApi"
22
import { addError } from "actions/errors"
33

4-
export const transfer =
5-
(resourceUri, group, target, errorKey) => (dispatch) => {
6-
postTransfer(resourceUri, group, target).catch((err) => {
7-
dispatch(
8-
addError(errorKey, `Error requesting transfer: ${err.message || err}`)
9-
)
10-
})
11-
}
4+
export const transfer = (resourceUri, keycloak, errorKey) => (dispatch) => {
5+
postTransfer(resourceUri, keycloak).catch((err) => {
6+
dispatch(
7+
addError(errorKey, `Error requesting transfer: ${err.message || err}`)
8+
)
9+
})
10+
}
1211

1312
export const noop = () => {}

src/components/editor/actions/TransferButtons.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import TransferButton from "./TransferButton"
88
import { transfer } from "actionCreators/transfer"
99
import useAlerts from "hooks/useAlerts"
1010
import { isBfInstance } from "utilities/Bibframe"
11+
import { useKeycloak } from "../../../KeycloakContext"
1112
import _ from "lodash"
1213

1314
const TransferButtons = ({ resourceKey }) => {
1415
const dispatch = useDispatch()
1516
const errorKey = useAlerts()
1617
const resource = useSelector((state) => selectNormSubject(state, resourceKey))
1718
const userGroups = useSelector((state) => selectGroups(state))
19+
const { keycloak } = useKeycloak()
1820

1921
const transferTargets = useMemo(() => {
2022
const newTargets = []
@@ -35,16 +37,16 @@ const TransferButtons = ({ resourceKey }) => {
3537
// Must be targets
3638
if (_.isEmpty(transferTargets)) return null
3739

38-
const handleClick = (event, group, target) => {
39-
dispatch(transfer(resource.uri, group, target, errorKey))
40+
const handleClick = (event) => {
41+
dispatch(transfer(resource.uri, keycloak, errorKey))
4042
event.preventDefault()
4143
}
4244

4345
const buttons = transferTargets.map(([target, group, label]) => (
4446
<TransferButton
4547
key={`${group}-${target}`}
4648
label={`Export to ${label}`}
47-
handleClick={(event) => handleClick(event, group, target)}
49+
handleClick={(event) => handleClick(event)}
4850
/>
4951
))
5052

src/sinopiaApi.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export const fetchResourceRelationships = (uri) => {
105105
}
106106

107107
// Fetches list of groups
108-
export const getGroups = () => Promise.resolve([{ id: "blue core", label: "Blue Core" }])
108+
export const getGroups = () =>
109+
Promise.resolve([{ id: "blue core", label: "Blue Core" }])
109110

110111
// Publishes (saves) a new resource
111112
export const postResource = (
@@ -227,17 +228,17 @@ export const putUserHistory = (
227228
}).then((resp) => checkResp(resp).then(() => resp.json()))
228229
}
229230

230-
export const postTransfer = (resourceUri, group, target, keycloak) => {
231-
const url = `${resourceUri.replace(
232-
"resource",
233-
"transfer"
234-
)}/${group}/${target}`
231+
export const postTransfer = (resourceUri, keycloak) => {
232+
const url = `${Config.sinopiaApiBase}/export`
235233
const jwt = getJwt(keycloak)
234+
236235
return fetch(url, {
237236
method: "POST",
238237
headers: {
239238
Authorization: `Bearer ${jwt}`,
239+
"Content-Type": "application/json",
240240
},
241+
body: JSON.stringify({ instance_uri: resourceUri }),
241242
}).then((resp) => checkResp(resp))
242243
}
243244

0 commit comments

Comments
 (0)