Skip to content

Commit

Permalink
Implement function for retrieving environment variables
Browse files Browse the repository at this point in the history
Implement function for retrieving environment variables
  • Loading branch information
TomDijkema committed Dec 6, 2024
1 parent d3cadcb commit 76d67c1
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 46 deletions.
5 changes: 4 additions & 1 deletion src/api/annotation/DeleteAnnotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import axios from 'axios';
import KeycloakService from 'app/Keycloak';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Types */
import { Dict } from 'app/Types';

Expand All @@ -22,7 +25,7 @@ const DeleteAnnotation = async ({ annotationId }: { annotationId: string }): Pro
try {
const result = await axios({
method: 'delete',
url: `annotation/${annotationId.replace(import.meta.env.VITE_HANDLE_URL, '')}`,
url: `annotation/${annotationId.replace(RetrieveEnvVariable('HANDLE_URL'), '')}`,
responseType: 'json',
headers: {
'Content-type': 'application/json',
Expand Down
5 changes: 4 additions & 1 deletion src/api/annotation/PatchAnnotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import axios from 'axios';
import KeycloakService from 'app/Keycloak';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Types */
import { Annotation } from 'app/types/Annotation';
import { AnnotationTemplate, JSONResult } from 'app/Types';
Expand Down Expand Up @@ -37,7 +40,7 @@ const PatchAnnotation = async ({ annotationId, updatedAnnotation }: { annotation
try {
const result = await axios({
method: 'patch',
url: `annotation/${annotationId.replace(import.meta.env.VITE_HANDLE_URL, '')}`,
url: `annotation/${annotationId.replace(RetrieveEnvVariable('HANDLE_URL'), '')}`,
responseType: 'json',
data: patchAnnotation,
headers: {
Expand Down
5 changes: 4 additions & 1 deletion src/api/digitalMedia/GetDigitalMediaMasJobRecords.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import axios from 'axios';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Types */
import { MasJobRecord, JSONResultArray, Dict } from 'app/Types';

Expand All @@ -23,7 +26,7 @@ const GetDigitalMediaMasJobRecords = async ({ handle, pageSize, pageNumber, stat
};

if (handle) {
const endPoint: string = `/digital-media/${handle.replace(import.meta.env.VITE_DOI_URL, '')}/mjr`;
const endPoint: string = `/digital-media/${handle.replace(RetrieveEnvVariable('DOI_URL'), '')}/mjr`;

try {
const result = await axios({
Expand Down
5 changes: 4 additions & 1 deletion src/api/digitalMedia/ScheduleDigitalMediaMas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import axios from 'axios';
import KeycloakService from 'app/Keycloak';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Exceptions */
import { PostException } from 'app/Exceptions';

Expand Down Expand Up @@ -42,7 +45,7 @@ const ScheduleDigitalMediaMas = async ({ handle, masList }: { handle: string, ma
try {
const result = await axios({
method: 'post',
url: `digital-media/${handle.replace(import.meta.env.VITE_DOI_URL, '')}/mas`,
url: `digital-media/${handle.replace(RetrieveEnvVariable('DOI_URL'), '')}/mas`,
responseType: 'json',
data: masRecord,
headers: {
Expand Down
5 changes: 4 additions & 1 deletion src/api/digitalSpecimen/GetDigitalSpecimenMasJobRecords.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import axios from 'axios';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Types */
import { MasJobRecord, JSONResultArray, Dict } from 'app/Types';

Expand All @@ -23,7 +26,7 @@ const GetDigitalSpecimenMasJobRecords = async ({ handle, pageSize, pageNumber, s
};

if (handle) {
const endPoint: string = `/digital-specimen/${handle.replace(import.meta.env.VITE_DOI_URL, '')}/mjr`;
const endPoint: string = `/digital-specimen/${handle.replace(RetrieveEnvVariable('DOI_URL'), '')}/mjr`;

try {
const result = await axios({
Expand Down
5 changes: 4 additions & 1 deletion src/api/digitalSpecimen/ScheduleDigitalSpecimenMas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import axios from 'axios';
import KeycloakService from 'app/Keycloak';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Exceptions */
import { PostException } from 'app/Exceptions';

Expand Down Expand Up @@ -42,7 +45,7 @@ const ScheduleDigitalSpecimenMas = async ({ handle, masList }: { handle: string,
try {
const result = await axios({
method: 'post',
url: `digital-specimen/${handle.replace(import.meta.env.VITE_DOI_URL, '')}/mas`,
url: `digital-specimen/${handle.replace(RetrieveEnvVariable('DOI_URL'), '')}/mas`,
responseType: 'json',
data: masRecord,
headers: {
Expand Down
13 changes: 11 additions & 2 deletions src/app/Utilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Import Dependencies */
import { startCase } from "lodash";
import { startCase, toUpper } from "lodash";


/**
Expand Down Expand Up @@ -40,7 +40,16 @@ const MobileCheck = (): boolean => {
return isMobile;
};

/**
* Function for retieving an environment variable by name
* @param name The name of the environment variable
*/
const RetrieveEnvVariable = (name: string) => {
return import.meta.env[`VITE_${toUpper(name)}`];
};

export {
MobileCheck,
MakeReadableString
MakeReadableString,
RetrieveEnvVariable
};
5 changes: 4 additions & 1 deletion src/app/config/table/SearchResultsTableConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { createColumnHelper } from '@tanstack/react-table';
import { useState } from 'react';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Hooks */
import { useAppSelector } from 'app/Hooks';

Expand Down Expand Up @@ -74,7 +77,7 @@ const SearchResultsTableConfig = () => {
}
}),
columnHelper.accessor('DOI', {
cell: info => info.getValue()?.replace(import.meta.env.VITE_DOI_URL as string, ''),
cell: info => info.getValue()?.replace(RetrieveEnvVariable('DOI_URL') as string, ''),
meta: {
widthInRem: 10,
pinned: true
Expand Down
9 changes: 6 additions & 3 deletions src/components/demo/DOITooltipDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import { useState, useEffect, useRef } from "react";

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Styles */
import './DOITooltip.css';

Expand Down Expand Up @@ -105,14 +108,14 @@ const DOITooltipDemo = (props: Props) => {
if (doi.includes('TEST') || doi.includes('SANDBOX')) {
let environment: string = doi.includes('SANDBOX') ? 'sandbox' : 'dev';

const response = await fetch(`https://${environment}.dissco.tech/handle-manager/api/v1/pids/${doi.replace(import.meta.env.VITE_DOI_URL as string, '')}`);
const response = await fetch(`https://${environment}.dissco.tech/handle-manager/api/v1/pids/${doi.replace(RetrieveEnvVariable('DOI_URL') as string, '')}`);
const record = await response.json();

if (record.data) {
setRecord(record);
}
} else if (doi.includes('20.5000.1025')) {
const respone = await fetch(`https://hdl.handle.net/api/handles/${doi.replace(import.meta.env.VITE_DOI_URL as string, '')}`);
const respone = await fetch(`https://hdl.handle.net/api/handles/${doi.replace(RetrieveEnvVariable('DOI_URL') as string, '')}`);
const responseRecord = await respone.json();

if (responseRecord.values.length) {
Expand All @@ -121,7 +124,7 @@ const DOITooltipDemo = (props: Props) => {
setRecord(record);
}
} else if (doi.includes('10.3535')) {
const response = await fetch(`https://doi.org/api/handles/${doi.replace(import.meta.env.VITE_DOI_URL as string, '')}`);
const response = await fetch(`https://doi.org/api/handles/${doi.replace(RetrieveEnvVariable('DOI_URL') as string, '')}`);
const responseRecord = await response.json();

if (responseRecord.values.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import { Annotorious } from "@annotorious/react";

/* Import Utilities */
import { RetrieveEnvVariable } from "app/Utilities";

/* Import Components */
import { ImageViewer } from "components/elements/Elements";

Expand Down Expand Up @@ -34,7 +37,7 @@ const DigitalMediaFrame = (props: Props) => {
<Annotorious>
<ImageViewer digitalMedia={digitalMedia}
annotoriousMode={annotoriousMode}
GetAnnotations={() => GetDigitalMediaAnnotations({ handle: digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '') })}
GetAnnotations={() => GetDigitalMediaAnnotations({ handle: digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '') })}
SetAnnotoriousMode={SetAnnotoriousMode}
/>
</Annotorious>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import { useState } from "react";

/* Import Utilities */
import { RetrieveEnvVariable } from "app/Utilities";

/* Import Hooks */
import { useNavigate } from "react-router-dom";
import { useFetch } from "app/Hooks";
Expand Down Expand Up @@ -44,7 +47,7 @@ const DigitalMediaList = (props: Props) => {
params: {
handle: digitalMedia["ods:hasEntityRelationships"]?.find(
entityRelationship => entityRelationship['dwc:relationshipOfResource'] === 'hasDigitalSpecimen'
)?.["dwc:relatedResourceID"].replace(import.meta.env.VITE_DOI_URL, '')
)?.["dwc:relatedResourceID"].replace(RetrieveEnvVariable('DOI_URL'), '')
},
Method: GetDigitalSpecimenDigitalMedia,
Handler: (digitalSpecimenDigitalMedia: DigitalMedia[]) => setDigitalSpecimenDigitalMedia(digitalSpecimenDigitalMedia)
Expand All @@ -60,7 +63,7 @@ const DigitalMediaList = (props: Props) => {
<Button type="button"
variant="blank"
className="h-100 w-100 px-0 py-0"
OnClick={() => navigate(`/dm/${digitalSpecimenDigitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '')}`)}
OnClick={() => navigate(`/dm/${digitalSpecimenDigitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')}`)}
>
<DigitalMediaItem digitalMedia={digitalSpecimenDigitalMedia} />
</Button>
Expand Down
13 changes: 8 additions & 5 deletions src/components/digitalMedia/components/topBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useState } from "react";
import { Row, Col } from "react-bootstrap";
import { useNavigate } from "react-router-dom";

/* Import Utilities */
import { RetrieveEnvVariable } from "app/Utilities";

/* Import Hooks */
import { useFetch } from "app/Hooks";

Expand Down Expand Up @@ -71,7 +74,7 @@ const TopBar = (props: Props) => {
/* OnLoad: fetch digital media versions */
fetch.Fetch({
params: {
handle: digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '')
handle: digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')
},
Method: GetDigitalMediaVersions,
Handler: (versions: number[]) => {
Expand All @@ -84,7 +87,7 @@ const TopBar = (props: Props) => {
*/
const ViewDigitalMediaJSON = () => {
window.open(`${window.location.protocol}//${window.location.hostname}${window.location.port ? ':' + window.location.port : ''}` +
`/api/v1/digital-media/${digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '')}`
`/api/v1/digital-media/${digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')}`
);
};

Expand All @@ -102,7 +105,7 @@ const TopBar = (props: Props) => {
const link = document.createElement("a");
link.href = URL.createObjectURL(jsonFile);

link.download = `${digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL as string, '')}_${digitalMedia['ods:version']}.json`;
link.download = `${digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL') as string, '')}_${digitalMedia['ods:version']}.json`;

link.click();
};
Expand All @@ -113,7 +116,7 @@ const TopBar = (props: Props) => {
<Row>
<Col>
<h2 className="fs-pageTitle">
{digitalMedia["dcterms:title"] ?? digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '')}
{digitalMedia["dcterms:title"] ?? digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')}
</h2>
</Col>
</Row>
Expand All @@ -136,7 +139,7 @@ const TopBar = (props: Props) => {
borderRadius: '999px'
}}
OnChange={(dropdownItem: DropdownItem) =>
navigate(`/dm/${digitalMedia["@id"].replace(import.meta.env.VITE_DOI_URL, '')}/${dropdownItem.value}`)}
navigate(`/dm/${digitalMedia["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')}/${dropdownItem.value}`)}
/>
</Col>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Row, Col, Card } from 'react-bootstrap';
import { useNavigate } from 'react-router-dom';

/* Import Utilities */
import { MakeReadableString } from 'app/Utilities';
import { MakeReadableString, RetrieveEnvVariable } from 'app/Utilities';

/* Import Types */
import { DigitalMedia } from 'app/types/DigitalMedia';
Expand Down Expand Up @@ -44,7 +44,7 @@ const DigitalSpecimenDigitalMedia = (props: Props) => {
<Button type="button"
variant="blank"
className="h-100 w-100 px-0 py-0 object-fit-contain"
OnClick={() => navigate(`/dm/${digitalMedia['@id'].replace(import.meta.env.VITE_DOI_URL, '')}`)}
OnClick={() => navigate(`/dm/${digitalMedia['@id'].replace(RetrieveEnvVariable('DOI_URL'), '')}`)}
>
<Image accessURI={digitalMedia['ac:accessURI']}
sizeOrientation="height"
Expand Down
9 changes: 5 additions & 4 deletions src/components/digitalSpecimen/components/topBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Row, Col } from "react-bootstrap";
import { useNavigate } from "react-router-dom";

/* Import Utilities */
import { RetrieveEnvVariable } from "app/Utilities";
import { GetSpecimenNameHTMLLabel } from "app/utilities/NomenclaturalUtilities";

/* Import Hooks */
Expand Down Expand Up @@ -71,7 +72,7 @@ const TopBar = (props: Props) => {
/* OnLoad: fetch digital specimen versions */
fetch.Fetch({
params: {
handle: digitalSpecimen['@id'].replace(import.meta.env.VITE_DOI_URL, '')
handle: digitalSpecimen['@id'].replace(RetrieveEnvVariable('DOI_URL'), '')
},
Method: GetDigitalSpecimenVersions,
Handler: (versions: number[]) => {
Expand All @@ -84,7 +85,7 @@ const TopBar = (props: Props) => {
*/
const ViewDigitalSpecimenJSON = () => {
window.open(`${window.location.protocol}//${window.location.hostname}${window.location.port ? ':' + window.location.port : ''}` +
`/api/v1/digital-specimen/${digitalSpecimen['@id'].replace(import.meta.env.VITE_DOI_URL, '')}`
`/api/v1/digital-specimen/${digitalSpecimen['@id'].replace(RetrieveEnvVariable('DOI_URL'), '')}`
);
};

Expand All @@ -102,7 +103,7 @@ const TopBar = (props: Props) => {
const link = document.createElement("a");
link.href = URL.createObjectURL(jsonFile);

link.download = `${digitalSpecimen['@id'].replace(import.meta.env.VITE_DOI_URL as string, '')}_${digitalSpecimen['ods:version']}.json`;
link.download = `${digitalSpecimen['@id'].replace(RetrieveEnvVariable('DOI_URL') as string, '')}_${digitalSpecimen['ods:version']}.json`;

link.click();
};
Expand Down Expand Up @@ -150,7 +151,7 @@ const TopBar = (props: Props) => {
borderRadius: '999px'
}}
OnChange={(dropdownItem: DropdownItem) =>
navigate(`/ds/${digitalSpecimen["@id"].replace(import.meta.env.VITE_DOI_URL, '')}/${dropdownItem.value}`)}
navigate(`/ds/${digitalSpecimen["@id"].replace(RetrieveEnvVariable('DOI_URL'), '')}/${dropdownItem.value}`)}
/>
</Col>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import classNames from 'classnames';
import { useState } from 'react';
import { Row, Col } from 'react-bootstrap';

/* Import Utilities */
import { RetrieveEnvVariable } from 'app/Utilities';

/* Import Hooks */
import { useAppDispatch, useAppSelector, useFetch } from 'app/Hooks';

Expand Down Expand Up @@ -79,7 +82,7 @@ const AnnotationSidePanel = (props: Props) => {
/* OnLoad: fetch annotations of super class with provided method */
fetch.Fetch({
params: {
handle: superClass?.['@id'].replace(import.meta.env.VITE_DOI_URL, '')
handle: superClass?.['@id'].replace(RetrieveEnvVariable('DOI_URL'), '')
},
triggers: [superClass, annotationWizardToggle],
Method: GetAnnotations,
Expand All @@ -95,7 +98,7 @@ const AnnotationSidePanel = (props: Props) => {
setLoading(true);

const annotations = await GetAnnotations({
handle: superClass?.['@id'].replace(import.meta.env.VITE_DOI_URL, '')
handle: superClass?.['@id'].replace(RetrieveEnvVariable('DOI_URL'), '')
});

setAnnotations(annotations);
Expand Down
Loading

0 comments on commit 76d67c1

Please sign in to comment.