Skip to content

Commit 98b5cf9

Browse files
committed
fix: PR comments
1 parent 0bb89a1 commit 98b5cf9

6 files changed

Lines changed: 26 additions & 28 deletions

File tree

src/taxonomy/tag-list/TagListTable.test.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { AxiosError } from 'axios';
23
import {
34
render,
45
waitFor,
@@ -600,8 +601,7 @@ describe('<TagListTable />', () => {
600601

601602
it('should show failure feedback when creating a duplicate root tag name', async () => {
602603
axiosMock.onPost(createTagUrl).reply(() => {
603-
const error = new Error('Request failed with status code 400');
604-
error.name = 'AxiosError';
604+
const error = new AxiosError('Request failed with status code 400');
605605
error.response = {
606606
data: {
607607
tag: ['Tag with this name already exists'],
@@ -623,8 +623,7 @@ describe('<TagListTable />', () => {
623623

624624
it('should keep the inline row and show a failure toast when save request fails', async () => {
625625
axiosMock.onPost(createTagUrl).reply(() => {
626-
const error = new Error('Request failed with status code 500');
627-
error.name = 'AxiosError';
626+
const error = new AxiosError('Request failed with status code 500');
628627
error.response = {
629628
data: {
630629
tag: ['Internal server error'],

src/taxonomy/tag-list/UsageCountDisplay.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ import type {
66
TreeRowData,
77
} from '@src/taxonomy/tree-table/types';
88
import { TagListRowData } from './types';
9-
10-
const asTagListRowData = (row: Row<TreeRowData>): TagListRowData => (
11-
row.original as unknown as TagListRowData
12-
);
9+
import { getTagListRowData } from './utils';
1310

1411
const UsageCountDisplay = ({ row }: { row: Row<TreeRowData>; }) => {
15-
const count = asTagListRowData(row).usageCount ?? 0;
12+
const count = getTagListRowData(row).usageCount ?? 0;
1613

1714
if (count <= 0) {
1815
return null;

src/taxonomy/tag-list/tagColumns.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ import { TagListRowData } from './types';
2020
import messages from './messages';
2121
import OptionalExpandLink from './OptionalExpandLink';
2222
import UsageCountDisplay from './UsageCountDisplay';
23+
import { getTagListRowData } from './utils';
2324

2425
const EDITABLE_COLUMNS = ['value'];
2526

26-
const asTagListRowData = (row: Row<TreeRowData>): TagListRowData => (
27-
row.original as unknown as TagListRowData
28-
);
29-
3027
interface GetColumnsArgs {
3128
setIsCreatingTopTag: (isCreating: boolean) => void;
3229
setCreatingParentId: (id: RowId | null) => void;
@@ -157,7 +154,7 @@ function getColumns({
157154
cell: ({ row }) => {
158155
const {
159156
value,
160-
} = asTagListRowData(row);
157+
} = getTagListRowData(row);
161158

162159
return (
163160
<span className="d-flex align-items-center gap-2">
@@ -187,14 +184,14 @@ function getColumns({
187184
/>
188185
),
189186
cell: ({ row }) => {
190-
const rowData = asTagListRowData(row);
187+
const rowData = getTagListRowData(row);
191188

192189
if (rowData.isNew || rowData.isEditing) {
193190
return <div className="d-flex gap-2" />;
194191
}
195192

196193
const disableAddSubtag = hasOpenDraft || !canAddTag;
197-
const disableEditTag = hasOpenDraft || row.original.canChangeTag === false;
194+
const disableEditTag = hasOpenDraft || rowData.canChangeTag === false;
198195

199196
const startSubtagDraft = () => {
200197
onStartDraft();

src/taxonomy/tag-list/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Row } from '@openedx/paragon';
2+
import { TreeRowData } from '@src/taxonomy/tree-table/types';
3+
import { TagListRowData } from './types';
4+
5+
/** getTagListRowData
6+
*
7+
* Minimal getter function for `row.original`. Mainly because the naming of `original` is not expressive,
8+
* and it needs to be cast to the correct type.
9+
*/
10+
export const getTagListRowData = (row: Row<TreeRowData>): TagListRowData => (
11+
row.original as unknown as TagListRowData
12+
);

src/taxonomy/tree-table/DraftRow.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ const DraftRow: React.FC<DraftRowProps> = ({
6969
}
7070
};
7171

72-
const indentClass = indent > 0 ? `tree-table-indent tree-table-indent-${indent}` : '';
73-
7472
return (
7573
<tr id={rowId} data-testid={rowTestId}>
76-
<td colSpan={1} className="py-2 pr-2 pl-0">
77-
<div className={indentClass}>
74+
<td className="py-2 pr-2 pl-0">
75+
<div className={`tree-table-indent-${indent}`}>
7876
<EditableCell
7977
initialValue={initialValue}
8078
errorMessage={draftError}
@@ -85,12 +83,11 @@ const DraftRow: React.FC<DraftRowProps> = ({
8583
/>
8684
</div>
8785
</td>
88-
<td colSpan={1} aria-label="Usage Count">
86+
<td aria-label="Usage Count">
8987
{row ? <UsageCountDisplay row={row} /> : null}
9088
</td>
9189
<td
92-
colSpan={1}
93-
className="tree-table-create-row-actions-cell p-2 align-top"
90+
className="tree-table-create-row-actions-cell p-2"
9491
>
9592
<span className="d-flex justify-content-end">
9693
<span className="mr-2">

src/taxonomy/tree-table/TableView.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
overflow-wrap: anywhere;
1111
}
1212

13-
.tree-table-indent {
14-
padding-inline-start: var(--pgn-spacing-spacer-base);
15-
}
16-
17-
@for $depth from 2 through 10 {
13+
@for $depth from 0 through 10 {
1814
.tree-table-indent-#{$depth} {
1915
padding-inline-start: calc(var(--pgn-spacing-spacer-base) * #{$depth});
2016
}

0 commit comments

Comments
 (0)