Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions mfes/workspace/src/components/KaTableComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ const KaTableComponent: React.FC<CustomTableProps> = ({
break;

case 'all-content':
mode =
content?.status === 'Draft' || content?.status === 'Live'
? 'edit'
: getLocalStoredUserRole() === Role.SCTA ? 'read' : 'review';
if (content?.status === 'Draft' || content?.status === 'Live') {
mode = 'edit';
} else if (content?.status === 'Processing') {
mode = 'review';
} else {
mode = getLocalStoredUserRole() === Role.SCTA ? 'read' : 'review';
}
break;

default:
Expand All @@ -152,16 +155,23 @@ const KaTableComponent: React.FC<CustomTableProps> = ({
query: { identifier },
});
} else if (tableTitle === 'all-content' && mode === 'review') {
content.contentType === 'Course'
? router.push({
pathname: `/course-hierarchy/${identifier}`,
query: {
identifier,
isReadOnly: true,
previousPage: 'allContents',
},
})
: router.push({
console.log('Opening all-content review for identifier:', identifier);
if (content?.status === 'Processing') {
const pathname =

`/workspace/content/review`
router.push({ pathname, query: { identifier } });
}
content.contentType === 'Course'
? router.push({
pathname: `/course-hierarchy/${identifier}`,
query: {
identifier,
isReadOnly: true,
previousPage: 'allContents',
},
})
: router.push({
pathname: `/workspace/content/review`,
query: { identifier, isReadOnly: true, isAllContents: true },
});
Comment on lines +158 to 177
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation introduces several issues that should be addressed:

  • Double Routing: When content?.status === 'Processing', the code executes a router.push at line 163 and then immediately proceeds to evaluate the ternary operator at line 165, which triggers a second router.push. This results in redundant navigation and potential race conditions in the router.
  • Debug Logging: The console.log statement at line 158 should be removed before merging to production.
  • Defensive Programming: At line 165, content.contentType is accessed without a null check, even though content is treated as potentially nullable at line 159 (content?.status).
  • Code Quality: The indentation and line breaks within the if block (lines 160-162) are inconsistent and hinder readability.

Using an if...else if...else structure resolves the double routing and improves code clarity.

Suggested change
console.log('Opening all-content review for identifier:', identifier);
if (content?.status === 'Processing') {
const pathname =
`/workspace/content/review`
router.push({ pathname, query: { identifier } });
}
content.contentType === 'Course'
? router.push({
pathname: `/course-hierarchy/${identifier}`,
query: {
identifier,
isReadOnly: true,
previousPage: 'allContents',
},
})
: router.push({
pathname: `/workspace/content/review`,
query: { identifier, isReadOnly: true, isAllContents: true },
});
if (content?.status === 'Processing') {
router.push({
pathname: `/workspace/content/review`,
query: { identifier },
});
} else if (content?.contentType === 'Course') {
router.push({
pathname: `/course-hierarchy/${identifier}`,
query: {
identifier,
isReadOnly: true,
previousPage: 'allContents',
},
});
} else {
router.push({
pathname: `/workspace/content/review`,
query: { identifier, isReadOnly: true, isAllContents: true },
});
}

Expand Down