Skip to content

Commit 3ccc809

Browse files
committed
fix: update type declaration and validation
1 parent 411e3d3 commit 3ccc809

49 files changed

Lines changed: 221 additions & 176 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
run: npm ci
2424
- name: Lint
2525
run: npm run lint
26+
- name: Types
27+
run: npm run types
2628
- name: Test
2729
run: npm run test
2830
- name: Build

src/authz-module/audit-user/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const AuditUserPage = () => {
3232

3333
useEffect(() => {
3434
if (!user && !isLoadingUser) {
35-
// @ts-ignore
36-
if (!isErrorUser || errorUser?.customAttributes?.httpErrorStatus === 404) {
35+
const err = errorUser as { customAttributes?: { httpErrorStatus?: number } } | null;
36+
if (!isErrorUser || err?.customAttributes?.httpErrorStatus === 404) {
3737
navigate(AUTHZ_HOME_PATH);
3838
}
3939
}

src/authz-module/components/AuthZTitle.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('AuthZTitle', () => {
1717

1818
it('renders without optional fields', () => {
1919
render(<AuthZTitle {...defaultProps} />);
20-
expect(screen.getByText(defaultProps.activeLabel)).toBeInTheDocument();
20+
expect(screen.getByText(defaultProps.activeLabel as string)).toBeInTheDocument();
2121
expect(screen.getByText(defaultProps.pageTitle)).toBeInTheDocument();
2222
expect(screen.getByText(defaultProps.pageSubtitle as string)).toBeInTheDocument();
2323
});
@@ -35,7 +35,7 @@ describe('AuthZTitle', () => {
3535
expect(screen.getByText(label)).toHaveAttribute('href', expect.stringContaining(to));
3636
});
3737

38-
expect(screen.getByText(defaultProps.activeLabel)).toBeInTheDocument();
38+
expect(screen.getByText(defaultProps.activeLabel as string)).toBeInTheDocument();
3939
});
4040

4141
it('renders page title', () => {

src/authz-module/components/PermissionTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Card, Icon, OverlayTrigger, Tooltip,
66
} from '@openedx/paragon';
77
import { PermissionsResourceGrouped, Role } from '@src/types';
8-
import { actionsDictionary } from './RoleCard/constants';
8+
import { actionsDictionary, ActionKey } from './RoleCard/constants';
99
import ResourceTooltip from './ResourceTooltip';
1010
import messages from './messages';
1111

@@ -66,7 +66,7 @@ const PermissionTable = ({ permissionsTable, roles, title }: PermissionTableProp
6666
{resourceGroup.permissions.map(permission => (
6767
<tr key={permission.key} className="border-top">
6868
<td className="text-start d-flex align-items-center small px-4 py-3">
69-
<Icon className="d-inline-block mr-2" size="sm" src={actionsDictionary[permission.actionKey]} />
69+
<Icon className="d-inline-block mr-2" size="sm" src={actionsDictionary[permission.actionKey as ActionKey]} />
7070
{permission.label}
7171
</td>
7272
{roles.map(role => (

src/authz-module/components/ResourceTooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const ResourceTooltip = ({ resourceGroup }:ResourceTooltipProps) => (
1717
<p className="small">{resourceGroup.description}</p>
1818
<ul className="small">
1919
{resourceGroup.permissions.map(permission => (
20-
<li><b>{permission.label.trim()}:</b> {permission.description}</li>
20+
<li><b>{permission.label?.trim()}:</b> {permission.description}</li>
2121
))}
2222
</ul>
2323
</Popover.Content>

src/authz-module/components/RoleCard/index.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ describe('RoleCard', () => {
2626
{
2727
key: 'library',
2828
label: 'Library Resource',
29+
description: 'Library resource description',
2930
permissions: [
3031
{
31-
key: 'view', label: 'View', actionKey: 'view', disabled: false,
32+
key: 'view', resource: 'library', label: 'View', actionKey: 'view', disabled: false,
3233
},
3334
{
34-
key: 'manage', label: 'Manage', actionKey: 'manage', disabled: true,
35+
key: 'manage', resource: 'library', label: 'Manage', actionKey: 'manage', disabled: true,
3536
},
3637
],
3738
},

src/authz-module/components/RoleCard/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Card, Collapsible, Container, Icon, IconButton,
44
} from '@openedx/paragon';
55
import { Delete, Person } from '@openedx/paragon/icons';
6+
import { RoleResourceGroup } from '@src/types';
67
import PermissionRow from './PermissionsRow';
78
import messages from './messages';
89

@@ -15,7 +16,7 @@ interface RoleCardProps extends CardTitleProps {
1516
objectName?: string | null;
1617
description: string;
1718
handleDelete?: () => void;
18-
permissionsByResource: any[];
19+
permissionsByResource: RoleResourceGroup[];
1920
}
2021

2122
const CardTitle = ({ title, userCounter = null }: CardTitleProps) => {

src/authz-module/components/TableCells.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { ContextType, useContext, useMemo } from 'react';
2+
import { useNavigate } from 'react-router-dom';
13
import { useIntl } from '@edx/frontend-platform/i18n';
24
import { Icon, IconButton } from '@openedx/paragon';
35
import { AppContext } from '@edx/frontend-platform/react';
46
import {
57
RemoveRedEye,
68
Delete, ExpandMore,
79
} from '@openedx/paragon/icons';
8-
import { TableCellValue, AppContextType, UserRole } from '@src/types';
9-
import { useNavigate } from 'react-router-dom';
10-
import { useContext, useMemo } from 'react';
10+
import { UserRole } from '@src/types';
11+
import type { TableCellValue } from '@src/paragon';
1112
import { DJANGO_MANAGED_ROLES, MAP_ROLE_KEY_TO_LABEL } from '@src/authz-module/constants';
1213
import { RESOURCE_ICONS } from './constants';
1314
import messages from './messages';
@@ -25,7 +26,7 @@ type ExtendedCellProps = CellPropsWithValue & {
2526

2627
const NameCell = ({ row }: CellProps) => {
2728
const intl = useIntl();
28-
const { authenticatedUser } = useContext(AppContext) as AppContextType;
29+
const { authenticatedUser } = useContext(AppContext) as ContextType<typeof AppContext>;
2930
const username = authenticatedUser?.username;
3031

3132
if (row.original.username === username) {
@@ -36,7 +37,7 @@ const NameCell = ({ row }: CellProps) => {
3637
</span>
3738
);
3839
}
39-
return row.original.fullName || row.original.username;
40+
return <span>{row.original.fullName || row.original.username}</span>;
4041
};
4142

4243
const ViewActionCell = ({ row }: CellProps) => {

src/authz-module/components/TableControlBar/MultipleChoiceFilter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const MultipleChoiceFilter = ({
2222
const { formatMessage } = useIntl();
2323

2424
const checkedBoxes = filterValue || [];
25-
const handleClickCheckbox = (value, displayName) => {
25+
const handleClickCheckbox = (value: string, displayName: string) => {
2626
const newValue = {
2727
groupName: filterButtonText?.toLocaleLowerCase() || '',
2828
value,
@@ -71,7 +71,7 @@ const MultipleChoiceFilter = ({
7171
type="text"
7272
trailingElement={<Icon src={Search} />}
7373
placeholder={formatMessage(messages['authz.table.controlbar.search'])}
74-
onChange={(e) => {
74+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
7575
setSearchValue(e.target.value);
7676
onSearchChange?.(e.target.value);
7777
}}

src/authz-module/components/TableControlBar/SearchFilter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Search } from '@openedx/paragon/icons';
66

77
interface SearchFilterProps {
88
filterValue: string;
9-
setFilter: (value: string) => void;
9+
setFilter: (value: string | undefined) => void;
1010
placeholder: string;
1111
}
1212

@@ -19,7 +19,7 @@ const SearchFilter = ({
1919
trailingElement={<Icon src={Search} />}
2020
value={filterValue || ''}
2121
type="text"
22-
onChange={e => {
22+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
2323
setFilter(e.target.value || undefined); // Set undefined to remove the filter entirely
2424
}}
2525
placeholder={placeholder}

0 commit comments

Comments
 (0)