Skip to content

Commit

Permalink
GQL data request updated with new media and task shapes (#182)
Browse files Browse the repository at this point in the history
* GQL data request updated with new media and task shapes
  • Loading branch information
aaronshiel authored Apr 28, 2022
1 parent 8cf3c4f commit 4cb45d9
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 2,364 deletions.
116 changes: 86 additions & 30 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
This software is Copyright ©️ 2020 The University of Southern California. All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and subject to the full license file found in the root of this software deliverable. Permission to make commercial use of this software may be obtained by contacting: USC Stevens Center for Innovation University of Southern California 1150 S. Olive Street, Suite 2300, Los Angeles, CA 90115, USA Email: [email protected]
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/
/*
This software is Copyright ©️ 2020 The University of Southern California. All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and subject to the full license file found in the root of this software deliverable. Permission to make commercial use of this software may be obtained by contacting: USC Stevens Center for Innovation University of Southern California 1150 S. Olive Street, Suite 2300, Los Angeles, CA 90115, USA Email: [email protected]
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/
import axios, {
Expand All @@ -22,7 +27,6 @@ import {
TaskStatus,
TrainingInfo,
VideoInfo,
CancelJob,
FollowUpQuestion,
User,
Config,
Expand Down Expand Up @@ -842,7 +846,19 @@ export async function fetchMentorById(
transcript
status
hasUntransferredMedia
media {
webMedia {
type
tag
url
needsTransfer
}
mobileMedia{
type
tag
url
needsTransfer
}
vttMedia{
type
tag
url
Expand Down Expand Up @@ -1120,28 +1136,6 @@ export async function fetchVideoBlobFromUrl(url: string): Promise<Blob> {
return result.data;
}

export async function cancelUploadVideo(
mentorId: string,
question: string,
taskIds: string[],
accessToken: string
): Promise<CancelJob> {
const result = await uploadRequest.post(
"/answer/cancel",
{
mentor: mentorId,
question: question,
task_ids_to_cancel: taskIds,
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
}
);
return getDataFromAxiosResponse(result, []);
}

export async function fetchUploadVideoStatus(
statusUrl: string
): Promise<TaskStatus<VideoInfo>> {
Expand Down Expand Up @@ -1209,13 +1203,39 @@ export async function fetchUploadTasks(
_id
question
}
taskList{
trimUploadTask{
task_name
status
}
transcodeWebTask{
task_name
status
}
transcodeMobileTask{
task_name
status
}
transcribeTask{
task_name
task_id
status
}
transcript
media {
originalMedia {
type
tag
url
}
webMedia {
type
tag
url
}
mobileMedia{
type
tag
url
}
vttMedia{
type
tag
url
Expand Down Expand Up @@ -1321,7 +1341,19 @@ export async function exportMentor(mentor: string): Promise<MentorExportJson> {
transcript
status
hasUntransferredMedia
media {
webMedia {
type
tag
url
needsTransfer
}
mobileMedia{
type
tag
url
needsTransfer
}
vttMedia{
type
tag
url
Expand Down Expand Up @@ -1495,7 +1527,19 @@ export async function importMentorPreview(
transcript
status
hasUntransferredMedia
media {
webMedia {
type
tag
url
needsTransfer
}
mobileMedia{
type
tag
url
needsTransfer
}
vttMedia{
type
tag
url
Expand All @@ -1517,7 +1561,19 @@ export async function importMentorPreview(
status
hasEditedTranscript
hasUntransferredMedia
media {
webMedia {
type
tag
url
needsTransfer
}
mobileMedia{
type
tag
url
needsTransfer
}
vttMedia{
type
tag
url
Expand Down
14 changes: 8 additions & 6 deletions client/src/components/import-export/import-answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "@material-ui/icons";
import { EditType, ImportPreview, Media } from "types";
import { ChangeIcon } from "./icons";
import { AnswerGQL } from "types-gql";
import { AnswerGQL, getAnswerGQLMediaList } from "types-gql";

const useStyles = makeStyles(() => ({
root: {
Expand Down Expand Up @@ -69,8 +69,10 @@ export default function AnswerImport(props: {
}

const media: ImportPreview<Media>[] = [];
answer?.media?.forEach((m) => {
const curMedia = curAnswer?.media?.find(
const importAnswerMedia = answer ? getAnswerGQLMediaList(answer) : [];
const curAnswerMedia = curAnswer ? getAnswerGQLMediaList(curAnswer) : [];
importAnswerMedia.forEach((m) => {
const curMedia = curAnswerMedia.find(
(mm) => mm.tag === m.tag && mm.type === m.type
);
media.push({
Expand All @@ -79,10 +81,10 @@ export default function AnswerImport(props: {
curData: curMedia,
});
});
curAnswer?.media
?.filter(
curAnswerMedia
.filter(
(mm) =>
!answer?.media?.find((m) => m.type === mm.type && m.tag === mm.tag)
!importAnswerMedia.find((m) => m.type === mm.type && m.tag === mm.tag)
)
.forEach((m) => {
media.push({
Expand Down
11 changes: 0 additions & 11 deletions client/src/hooks/graphql/upload-status-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ export function areAllTasksDone(task: UploadTask): boolean {
return compareTaskStatusesToValue(task, UploadTaskStatuses.DONE, true);
}

export function fetchIncompleteTaskIds(task: UploadTask): string[] {
if (!task.taskList.length) return [];
return task.taskList
.filter(
(task) =>
task.status !== UploadTaskStatuses.FAILED &&
task.status !== UploadTaskStatuses.DONE
)
.map((task) => task.task_id);
}

export function compareTaskStatusesToValue(
task: UploadTask,
value: UploadTaskStatuses,
Expand Down
10 changes: 0 additions & 10 deletions client/src/hooks/graphql/use-with-record-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export function useWithRecordState(
isUploading,
pollStatusCount,
upload,
cancelUpload,
removeCompletedOrFailedTask,
} = useWithUploadStatus(
accessToken,
Expand Down Expand Up @@ -575,13 +574,6 @@ export function useWithRecordState(
downloadVideoForQuestion(curAnswer?.answer.question);
}

function cancelUploadVideo(task: UploadTask) {
if (!mentorId) {
return;
}
cancelUpload(mentorId, task);
}

return {
mentorQuestions,
mentorSubjects,
Expand Down Expand Up @@ -611,7 +603,6 @@ export function useWithRecordState(
uploadVideo,
downloadCurAnswerVideo,
downloadVideoFromUpload,
cancelUpload: cancelUploadVideo,
setMinVideoLength,
clearError,
};
Expand Down Expand Up @@ -646,7 +637,6 @@ export interface UseWithRecordState {
uploadVideo: (trim?: { start: number; end: number }) => void;
downloadCurAnswerVideo: () => void;
downloadVideoFromUpload: (upload: UploadTask) => void;
cancelUpload: (task: UploadTask) => void;
setMinVideoLength: (length: number) => void;
clearError: () => void;
}
62 changes: 1 addition & 61 deletions client/src/hooks/graphql/use-with-upload-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ The full terms of this copyright and license should always be found in the root
*/
import { useEffect, useState } from "react";
import axios from "axios";
import {
cancelUploadVideo,
deleteUploadTask,
fetchUploadTasks,
uploadVideo,
} from "api";
import { deleteUploadTask, fetchUploadTasks, uploadVideo } from "api";
import { UploadTask, UploadTaskStatuses } from "types";
import { copyAndSet } from "helpers";
import useInterval from "hooks/task/use-interval";
Expand All @@ -23,7 +18,6 @@ import {
isATaskFailed,
areAllTasksDoneOrOneFailed,
whichTaskFailed,
fetchIncompleteTaskIds,
} from "./upload-status-helpers";
import { useActiveMentor } from "store/slices/mentor/useActiveMentor";

Expand Down Expand Up @@ -188,7 +182,6 @@ export function useWithUploadStatus(
taskList: [
{
task_name: "upload",
task_id: "",
status: UploadTaskStatuses.QUEUED,
},
],
Expand Down Expand Up @@ -217,7 +210,6 @@ export function useWithUploadStatus(
taskList: [
{
task_name: "trim_upload",
task_id: "",
status: UploadTaskStatuses.FAILED,
},
],
Expand All @@ -227,62 +219,11 @@ export function useWithUploadStatus(
});
}

function cancelUpload(mentorId: string, task: UploadTask) {
if (!task.taskList.length) {
task.tokenSource?.cancel(UploadTaskStatuses.CANCELLED);
addOrEditTask({
...task,
taskList: [
{
task_name: "trim_upload",
task_id: "",
status: UploadTaskStatuses.CANCELLED,
},
],
isCancelling: true,
});
return;
}
addOrEditTask({
...task,
isCancelling: true,
});
cancelUploadVideo(
mentorId,
task.question,
fetchIncompleteTaskIds(task),
accessToken
)
.then(() => {
addOrEditTask({
...task,
taskList: [
{
task_name: "trim_upload",
task_id: "",
status: UploadTaskStatuses.CANCELLED,
},
],
isCancelling: true,
});
})
.catch((err) => {
console.error(err);
addOrEditTask({
...task,
isCancelling: true,
});
});
}

// function deleteUpload() {}

return {
pollStatusCount,
uploads,
isUploading,
upload,
cancelUpload,
removeCompletedOrFailedTask,
};
}
Expand All @@ -298,6 +239,5 @@ export interface UseWithUploadStatus {
trim?: { start: number; end: number },
hasEditedTranscript?: boolean
) => void;
cancelUpload: (mentorId: string, task: UploadTask) => void;
removeCompletedOrFailedTask: (tasks: UploadTask) => void;
}
Loading

0 comments on commit 4cb45d9

Please sign in to comment.