Skip to content

Commit

Permalink
Fix error on explorer not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nana-boateng committed Jul 18, 2024
1 parent 4ea7894 commit c02876f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion configure-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scope": "file",
"type": "configure",
"contentType": "text/tab-separated-values",
"toolUrl": "http://localhost:4200",
"toolUrl": "http://localhost:4200/",
"toolParameters": {
"queryParameters": [
{
Expand Down
17 changes: 8 additions & 9 deletions src/app/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,20 @@ export class HeaderComponent implements OnInit {
const fileID = datasetInfo()?.info?.fileID;
const apiKey = datasetInfo()?.info?.apiKey;
const secureUploadURL = datasetInfo()?.info?.secureUploadUrl || '';
if (siteURL && fileID && apiKey && ddiData) {
if (ddiData && !!secureUploadURL) {
this.store.dispatch(
DataverseFetchActions.startDatasetUpload({
DataverseFetchActions.startSecureDatasetUpload({
ddiData,
siteURL,
fileID,
apiKey,
secureUploadURL,
}),
);
}
if (ddiData && !!secureUploadURL) {
} else if (siteURL && fileID && apiKey && ddiData) {
this.store.dispatch(
DataverseFetchActions.startSecureDatasetUpload({
DataverseFetchActions.startDatasetUpload({
ddiData,
secureUploadURL,
siteURL,
fileID,
apiKey,
}),
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/new.state/xml/xml.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ export interface XmlState {
info: {
siteURL?: string;
fileID?: number;
apiKey?: string | undefined;
apiKey: string | null;
importedSuccess?: boolean;
secureUploadUrl?: string;
secureUploadUrl: string | null;
} | null;
}

Expand Down
26 changes: 23 additions & 3 deletions src/app/new.state/xml/xml.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
changeSingleVariable,
createNewVariables,
deleteVariableGroup,
extractUrlAndToken,
matchVariableIDs,
removeVariablesFromGroups,
renameVariableGroup,
Expand All @@ -26,9 +27,27 @@ export const xmlReducer = createReducer(
on(
DataverseFetchActions.decodeAndFetchDDISuccess,
(state, { data, apiResponse }) => {
let info = {
secureUploadUrl: apiResponse.data.signedUrls[1].signedUrl,
let info: {
siteURL?: string;
apiKey: string | null;
fileID: number;
secureUploadUrl: string | null;
} = {
apiKey: null,
fileID: apiResponse.data.queryParameters.fileId,
secureUploadUrl: null,
};
const extractedData = extractUrlAndToken(
apiResponse.data.signedUrls[0].signedUrl,
);
if (extractedData) {
info = {
...info,
siteURL: extractedData.siteURL,
apiKey: extractedData.apiKey ? extractedData.apiKey : null,
secureUploadUrl: apiResponse.data.signedUrls[1]?.signedUrl || null,
};
}
return {
...state,
dataset: data,
Expand All @@ -48,8 +67,9 @@ export const xmlReducer = createReducer(
dataset: data,
info: {
siteURL,
apiKey,
apiKey: apiKey ? apiKey : null,
fileID,
secureUploadUrl: null,
},
header: {
citation: data.codeBook.stdyDscr?.citation.biblCit,
Expand Down
2 changes: 1 addition & 1 deletion src/app/new.state/xml/xml.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const selectDatasetState = createSelector(

export const selectDatasetHasApiKey = createSelector(
selectXmlFeature,
(state) => !!state.info?.apiKey || !!state.info?.secureUploadUrl,
(state) => !!state.info?.apiKey,
);

export const selectDatasetInfo = createSelector(
Expand Down
14 changes: 14 additions & 0 deletions src/app/new.state/xml/xml.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,17 @@ function editSingleVariable(
console.log(currentVariableCloned);
return currentVariableCloned;
}

export function extractUrlAndToken(url: string) {
try {
const parsedUrl = new URL(url);
const siteURL = `${parsedUrl.protocol}//${parsedUrl.host}`;
const apiKey = parsedUrl.searchParams.get('token');
return {
siteURL: siteURL,
apiKey: apiKey,
};
} catch (e) {
return null;
}
}
2 changes: 1 addition & 1 deletion src/app/services/ddi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class DdiService {
}),
};
const xml = this.JSONtoXML(jsonData);
return this.http.put(secureUploadURL, xml, httpOptions);
return this.http.post(secureUploadURL, xml, httpOptions);
}

fetchCrossTabulationFromVariables(variable: string) {
Expand Down

0 comments on commit c02876f

Please sign in to comment.