Skip to content

Commit

Permalink
lrs reports extract referrer better, uploads are not removed from sta…
Browse files Browse the repository at this point in the history
…te when complete (#309)
  • Loading branch information
aaronshiel authored Sep 28, 2023
1 parent faaf74c commit fad3dc7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
26 changes: 17 additions & 9 deletions client/src/hooks/graphql/use-with-record-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export function useWithRecordState(
return;
}
const { videoId, subject, category, status } = filter;
let answers = mentorAnswers;
let _answers = mentorAnswers;
if (videoId && !subject) {
const ids = Array.isArray(videoId) ? videoId : [videoId];
answers = answers.filter(
_answers = _answers.filter(
(a) => ids.includes(a.question) || ids.includes(a.questionClientId)
);
} else if (subject) {
Expand All @@ -132,22 +132,30 @@ export function useWithRecordState(
const sQuestions = s.questions.filter(
(q) => !category || `${q.category?.id}` === category
);
answers = answers.filter((a) =>
_answers = _answers.filter((a) =>
sQuestions.map((q) => q.question).includes(a.question)
);
}
}

const answerStates: AnswerState[] = [];
for (const a of answers) {
for (const a of _answers) {
const q = getValueIfKeyExists(a.question, mentorQuestions);
let checkStatus = !status;
// we don't want to remove questions that are already in the recording state
const answerAlreadyInState = Boolean(
answers.find((as) => as.answer.question === a.question)
);
let checkStatus = !status || answerAlreadyInState;
if (status === Status.COMPLETE) {
checkStatus = isAnswerComplete(a, q?.question?.name, mentorType);
checkStatus =
isAnswerComplete(a, q?.question?.name, mentorType) ||
answerAlreadyInState;
} else if (status === Status.INCOMPLETE) {
checkStatus = !isAnswerComplete(a, q?.question?.name, mentorType);
checkStatus =
!isAnswerComplete(a, q?.question?.name, mentorType) ||
answerAlreadyInState;
} else if (status === Status.NONE) {
checkStatus = a.status === Status.NONE;
checkStatus = a.status === Status.NONE || answerAlreadyInState;
}
if (
q?.question &&
Expand All @@ -166,7 +174,7 @@ export function useWithRecordState(
}
}
//if after filtering through the answers we end up with none, then go back to My Mentor page
if (!answers.length) {
if (!_answers.length) {
navigate("/");
}
setAnswers(answerStates);
Expand Down
47 changes: 42 additions & 5 deletions client/src/lrs-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ const getChatSessionId = (statement: Statement): string => {
key.includes("chatSessionId")
);
if (!targetKey) {
console.log("no chatSessionId key found in extensions");
return "";
}
const chatSessionIdFromExtensions = extensions[targetKey];
Expand All @@ -252,7 +251,6 @@ const getSessionId = (statement: Statement): string => {
key.includes("sessionId")
);
if (!targetKey) {
console.log("no sessionId key found in extensions");
return "";
}
const sessionIdFromExtensions = extensions[targetKey];
Expand Down Expand Up @@ -368,13 +366,52 @@ export const getVerb = (statement: Statement): string => {
* @returns The referrer of the statement.
*/
const getReferrer = (statement: Statement): string => {
const resultExtensions = statement.result?.extensions;
if (!resultExtensions) {
return "";
}
let referrer = "";
const verbList = [
"https://mentorpal.org/xapi/verb/initialized",
"https://mentorpal.org/xapi/verb/selected",
"https://mentorpal.org/xapi/verb/suspended",
"https://mentorpal.org/xapi/verb/answer-playback-started",
];
const verb = statement.verb?.id || "";

if (verb) {
try {
referrer = resultExtensions[verb]["referrer"] || "";
} catch (err) {
referrer = "";
}
}

if (!referrer) {
for (let i = 0; i < verbList.length; i++) {
try {
referrer = resultExtensions[verbList[i]]["referrer"] || "";
} catch (err) {
referrer = "";
}
if (referrer) {
break;
}
}
}

if (referrer && referrer !== "null" && referrer !== "no referrer") {
return referrer;
}

try {
// if no referrer found via extensions, try to find in url
const object: Activity = statement.object as Activity;
const url = object.id;
const referrer = new URLSearchParams(url).get("referrer") || "-";
return referrer;
const referrerFromUrl = new URLSearchParams(url).get("referrer") || "-";
return referrerFromUrl;
} catch (err) {
return "";
return "-";
}
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/store/slices/mentor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const mentorSlice = createSlice({
updateAnswer: (state, action: PayloadAction<Answer>) => {
if (state.data) {
state.data.answers = state.data.answers.map((a) =>
a._id === action.payload._id ? action.payload : a
a.question === action.payload.question ? action.payload : a
);
}
},
Expand Down

0 comments on commit fad3dc7

Please sign in to comment.