Skip to content

Commit

Permalink
feat: update harvest request license information
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Sep 4, 2024
1 parent 0368c12 commit d37634e
Show file tree
Hide file tree
Showing 11 changed files with 590 additions and 409 deletions.
10 changes: 10 additions & 0 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
CollectionResource,
ConductorBaseResponse,
ConductorSearchResponse,
HarvestRequest,
Homework,
HomeworkSearchParams,
PeerReview,
Expand Down Expand Up @@ -437,6 +438,15 @@ class API {
return res;
}

// Harvest Requests
async createHarvestRequest(data: HarvestRequest) {
const res = await axios.post<ConductorBaseResponse>(
"/harvestingrequest",
data
);
return res;
}

// Search
async getAutoCompleteSuggestions(query: string, limit?: number) {
const res = await axios.get<
Expand Down
1 change: 1 addition & 0 deletions client/src/components/ControlledInputs/CtlTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface CtlTextInputProps extends FormInputProps {
required?: boolean;
showErrorMsg?: boolean;
helpText?: string;
placeholder?: string;
}

/**
Expand Down
40 changes: 3 additions & 37 deletions client/src/components/FilesManager/EditFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import AuthorsForm from "./AuthorsForm";
import FilePreview from "./FilePreview";
import ManageCaptionsModal from "./ManageCaptionsModal";
import { useQuery } from "@tanstack/react-query";
import useCentralIdentityLicenses from "../../hooks/useCentralIdentityLicenses";
const FilesUploader = React.lazy(() => import("./FilesUploader"));
const FileRenderer = React.lazy(() => import("./FileRenderer"));

Expand Down Expand Up @@ -130,15 +131,8 @@ const EditFile: React.FC<EditFileProps> = ({
// Frameworks
const [selectedFramework, setSelectedFramework] =
useState<AssetTagFramework | null>(null);

const { data: licenseOptions, isFetching: licensesLoading } = useQuery<
CentralIdentityLicense[]
>({
queryKey: ["centralIdentityLicenses"],
queryFn: loadLicenseOptions,
staleTime: Infinity,
refetchOnWindowFocus: false,
});

const { licenseOptions, isFetching: licensesLoading } = useCentralIdentityLicenses();

const {
data: projectLicenseSettings,
Expand Down Expand Up @@ -292,34 +286,6 @@ const EditFile: React.FC<EditFileProps> = ({
}
}

async function loadLicenseOptions() {
try {
const res = await api.getCentralIdentityLicenses();
if (res.data.err) {
throw new Error(res.data.errMsg);
}
if (!res.data.licenses) {
throw new Error("Failed to load license options");
}

const versionsSorted = res.data.licenses.map((l) => {
return {
...l,
versions: l.versions?.sort((a, b) => {
if (a === b) return 0;
if (!a) return -1;
if (!b) return 1;
return b.localeCompare(a);
}),
};
});
return versionsSorted;
} catch (err) {
handleGlobalError(err);
return [];
}
}

/**
* Submits the file edit request to the server (if form is valid) and
* closes the modal on completion.
Expand Down
28 changes: 20 additions & 8 deletions client/src/components/controlpanel/HarvestingRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,25 @@ const HarvestingRequests = (props) => {
break;
case 'license':
sorted = [...harvestingRequests].sort((a, b) => {
if (a.license < b.license) {
return -1;
}
if (a.license > b.license) {
return 1;
if (typeof a.license === 'string' && typeof b.license === 'string') {
if (a.license < b.license) {
return -1;
}
if (a.license > b.license) {
return 1;
}
return 0;
} else if (typeof a.license === 'object' && typeof b.license === 'object') {
if (a.license.name < b.license.name) {
return -1;
}
if (a.license.name > b.license.name) {
return 1;
}
return 0;
} else {
return 0;
}
return 0;
});
break;
case 'status':
Expand Down Expand Up @@ -496,7 +508,7 @@ const HarvestingRequests = (props) => {
<span>{getLibraryName(item.library)}</span>
</Table.Cell>
<Table.Cell>
<span>{getLicenseText(item.license)}</span>
<span>{typeof item.license === 'object' ? `${item.license.name} ${item.license.version}` : item.license}</span>
</Table.Cell>
<Table.Cell>
<span>{item.institution}</span>
Expand Down Expand Up @@ -548,7 +560,7 @@ const HarvestingRequests = (props) => {
<Grid.Row columns={2}>
<Grid.Column>
<Header sub>Resource License</Header>
<p>{getLicenseText(currentRequest.license)}</p>
<p>{typeof currentRequest.license === 'object' ? `${currentRequest.license.name} ${currentRequest.license.version}` : currentRequest.license}</p>
</Grid.Column>
<Grid.Column>
<Header sub>Resource URL</Header>
Expand Down
Loading

0 comments on commit d37634e

Please sign in to comment.