Skip to content

Commit 3098e4b

Browse files
fix: header table change to avoid key error due to paragon, missing flag added
1 parent adf92ef commit 3098e4b

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/authz-module/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ export const rolesObject = [
495495
userCount: 1,
496496
name: 'Course Editor',
497497
description: 'building and maintaining course content and supporting assets, without operational controls or high impact actions that can affect a live course.',
498+
disabled: true,
498499
},
499500
{
500501
role: 'course_auditor',
@@ -513,6 +514,7 @@ export const rolesObject = [
513514
userCount: 1,
514515
name: 'Course Auditor',
515516
description: ' QA, compliance review, content review, and general oversight, no changes in Studio.',
517+
disabled: true,
516518
},
517519

518520
];

src/authz-module/utils.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { getCellHeader, getScopeManageAction, getScopeManageActionPermission } f
66
import { CONTENT_COURSE_PERMISSIONS, CONTENT_LIBRARY_PERMISSIONS } from './constants';
77

88
const renderCellHeader = (columnId: string, columnTitle: string, filtersApplied: string[]) => {
9-
const component = getCellHeader(columnId, columnTitle, filtersApplied);
10-
return renderWrapper(<div>{component}</div>);
9+
const result = getCellHeader(columnId, columnTitle, filtersApplied);
10+
if (typeof result === 'function') {
11+
const Component = result;
12+
return renderWrapper(<Component />);
13+
}
14+
return renderWrapper(<div>{result}</div>);
1115
};
1216

1317
describe('utils', () => {

src/authz-module/utils.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@ import { Icon } from '@openedx/paragon';
22
import { FilterList } from '@openedx/paragon/icons';
33
import { CONTENT_COURSE_PERMISSIONS, CONTENT_LIBRARY_PERMISSIONS } from './constants';
44

5+
/**
6+
* Returns a header value for a DataTable column that shows a filter icon
7+
* when the column has an active filter.
8+
*
9+
* When a filter is active, returns a **component function** with a custom
10+
* toString() override. This is necessary because Paragon's TableRow builds
11+
* cell keys via: `${cell.column.Header}${row.id}`
12+
*
13+
* - A JSX element stringifies to "[object Object]", causing duplicate keys.
14+
* - A function with a custom toString() produces a unique string per column.
15+
*
16+
* react-table's render('Header') calls the function as a component, so the
17+
* JSX is still rendered correctly in the table header.
18+
*/
519
export const getCellHeader = (columnId: string, columnTitle: string, filtersApplied: string[]) => {
620
if (filtersApplied.includes(columnId)) {
7-
return (
21+
const FilteredHeader = () => (
822
<span className="d-flex flex-row align-items-center">
923
<Icon src={FilterList} size="sm" className="mr-2" />
1024
{columnTitle}
1125
</span>
1226
);
27+
FilteredHeader.displayName = `FilteredHeader_${columnId}`;
28+
FilteredHeader.toString = () => `FilteredHeader_${columnId}`;
29+
return FilteredHeader;
1330
}
1431
return columnTitle;
1532
};

0 commit comments

Comments
 (0)