Skip to content

Commit

Permalink
handled edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jagadeeswaran-zipstack committed Dec 19, 2024
1 parent cee369e commit 825f51e
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,12 @@ function ManageDocsModal({
const doc = newListOfDocs[0];
handleDocChange(doc);
}
const updatedPromptOutput = removeIdFromCoverage(promptOutputs, docId);
const updatedPromptDetails = removeIdFromCoverage(details, docId);
const updatedPromptOutput = removeIdFromCoverageOfPromptOutput(
promptOutputs,
docId
);
updateCustomTool({ details: updatedPromptDetails });
updatePromptOutput(updatedPromptOutput);
})
.catch((err) => {
Expand All @@ -558,6 +563,17 @@ function ManageDocsModal({
};

const removeIdFromCoverage = (data, idToRemove) => {
if (data.prompts && Array.isArray(data.prompts)) {
data.prompts.forEach((prompt) => {
if (Array.isArray(prompt.coverage)) {
prompt.coverage = prompt.coverage.filter((id) => id !== idToRemove);
}
});
}
return data; // Return the updated data
};

const removeIdFromCoverageOfPromptOutput = (data, idToRemove) => {
return Object.entries(data).reduce((updatedData, [key, value]) => {
// Create a new object for the current entry
updatedData[key] = {
Expand Down

0 comments on commit 825f51e

Please sign in to comment.