Skip to content

Commit efd7824

Browse files
Fix the UI breaking in case of any failures during json parsing of feed data (#26553)
* Fix the UI breaking in case of any failures during json parsing of feed data * Worked on comments
1 parent 0334d46 commit efd7824

3 files changed

Lines changed: 99 additions & 14 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.test.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
* See the License for the specific language governing permissions and
1111
* limitations under the License.
1212
*/
13-
import { act, fireEvent, render, screen } from '@testing-library/react';
13+
import { fireEvent, render, screen } from '@testing-library/react';
14+
import { act } from 'react';
1415
import { MemoryRouter } from 'react-router-dom';
1516
import { EntityType } from '../../../../enums/entity.enum';
1617
import {
18+
APPROVAL_TASK_FEED,
1719
TASK_FEED,
1820
TASK_FEED_RECOGNIZER_FEEDBACK,
1921
} from '../../../../mocks/Task.mock';
22+
import { TaskTabProps } from './TaskTab.interface';
2023
import { TaskTabNew } from './TaskTabNew.component';
2124

2225
jest.mock('react-router-dom', () => ({
@@ -162,7 +165,7 @@ jest.mock(
162165
}
163166
);
164167

165-
const mockProps = {
168+
const mockProps: TaskTabProps = {
166169
taskThread: TASK_FEED,
167170
owners: [],
168171
entityType: EntityType.TABLE,
@@ -518,4 +521,26 @@ describe('TaskTabNew Component', () => {
518521

519522
expect(screen.getByTestId('feed-replies')).toBeInTheDocument();
520523
});
524+
525+
it('should display the task information for approval tasks with suggestion data', async () => {
526+
const {
527+
isTagsTask,
528+
isDescriptionTask,
529+
} = require('../../../../utils/TasksUtils');
530+
isTagsTask.mockReturnValue(false);
531+
isDescriptionTask.mockReturnValue(false);
532+
533+
await act(async () => {
534+
render(<TaskTabNew {...mockProps} taskThread={APPROVAL_TASK_FEED} />, {
535+
wrapper: MemoryRouter,
536+
});
537+
});
538+
539+
expect(
540+
screen.getByText('message.request-approval-message')
541+
).toBeInTheDocument();
542+
expect(screen.getByTestId('entity-link')).toHaveTextContent('entityName');
543+
expect(screen.getByText('label.created-by')).toBeInTheDocument();
544+
expect(screen.getByText('label.assignee-plural')).toBeInTheDocument();
545+
});
521546
});

openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,21 @@ export const TaskTabNew = ({
174174

175175
const showAddSuggestionButton = useMemo(() => {
176176
const taskType = taskDetails?.type ?? ('' as TaskType);
177-
const parsedSuggestion = [
178-
TaskType.UpdateDescription,
179-
TaskType.RequestDescription,
180-
].includes(taskType)
181-
? taskDetails?.suggestion
182-
: JSON.parse(taskDetails?.suggestion || '[]');
177+
let parsedSuggestion: string | TagLabel[] = taskDetails?.suggestion ?? '';
178+
179+
if (isTaskTags) {
180+
try {
181+
parsedSuggestion = JSON.parse(taskDetails?.suggestion || '[]');
182+
} catch {
183+
parsedSuggestion = [];
184+
}
185+
}
183186

184187
return (
185188
[TaskType.RequestTag, TaskType.RequestDescription].includes(taskType) &&
186189
isEmpty(parsedSuggestion)
187190
);
188-
}, [taskDetails]);
191+
}, [taskDetails, isTaskTags]);
189192

190193
const noSuggestionTaskMenuOptions = useMemo(() => {
191194
let label;
@@ -815,14 +818,22 @@ export const TaskTabNew = ({
815818
taskDetails?.suggestion ?? taskDetails?.oldValue ?? '';
816819

817820
return { description };
818-
} else {
819-
const updatedTags = JSON.parse(
820-
taskDetails?.suggestion ?? taskDetails?.oldValue ?? '[]'
821-
);
821+
} else if (isTaskTags) {
822+
let updatedTags: TagLabel[] = [];
823+
824+
try {
825+
updatedTags = JSON.parse(
826+
taskDetails?.suggestion ?? taskDetails?.oldValue ?? '[]'
827+
);
828+
} catch {
829+
updatedTags = [];
830+
}
822831

823832
return { updatedTags };
824833
}
825-
}, [taskDetails, isTaskDescription]);
834+
835+
return {};
836+
}, [taskDetails, isTaskDescription, isTaskTags]);
826837

827838
const handleAssigneeUpdate = async () => {
828839
setIsAssigneeLoading(true);

openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
DataType,
1717
} from '../generated/entity/data/container';
1818
import {
19+
CardStyle,
1920
FeedbackType,
21+
FieldOperation,
22+
GeneratedBy,
2023
Post,
2124
RecognizerFeedback,
2225
TaskType,
@@ -60,6 +63,52 @@ export const TASK_FEED: Thread = {
6063
},
6164
};
6265

66+
export const APPROVAL_TASK_FEED: Thread = {
67+
id: '4569705b-78b9-448f-8d1a-060401f03d9d',
68+
type: ThreadType.Task,
69+
href: 'https://nbndatacatalogue-np.getcollate.io//v1/feed/4569705b-78b9-448f-8d1a-060401f03d9d',
70+
threadTs: 1773708257515,
71+
about:
72+
'<#E::table::starburst.cdl.sharp_incnet.v_incnet_location::columns::location_id>',
73+
entityRef: {
74+
id: '1bf67076-346e-46a6-b7ad-4914d89f7a3a',
75+
type: 'table',
76+
name: 'v_incnet_location',
77+
fullyQualifiedName: 'starburst.cdl.sharp_incnet.v_incnet_location',
78+
displayName: 'v_incnet_location',
79+
deleted: false,
80+
},
81+
domains: ['19cf92da-baa0-4000-84a1-3b8b25da8d01'],
82+
generatedBy: GeneratedBy.User,
83+
cardStyle: CardStyle.Default,
84+
fieldOperation: FieldOperation.Updated,
85+
createdBy: 'calebknight',
86+
updatedAt: 1773708257515,
87+
updatedBy: 'calebknight',
88+
resolved: false,
89+
message: 'this is a test, I am a very good programmer',
90+
postsCount: 0,
91+
posts: [],
92+
reactions: [],
93+
task: {
94+
id: 1803,
95+
type: TaskType.RequestApproval,
96+
assignees: [
97+
{
98+
id: 'ce782180-36f6-4d4a-9fbe-ee6103d4146f',
99+
type: 'user',
100+
name: 'calebknight',
101+
fullyQualifiedName: 'calebknight',
102+
displayName: 'Caleb Knight',
103+
deleted: false,
104+
},
105+
],
106+
status: ThreadTaskStatus.Open,
107+
oldValue: 'this is a test suggestion',
108+
suggestion: 'this is a different test suggestion2',
109+
},
110+
};
111+
63112
export const TASK_POST: Post = {
64113
message: 'Request tags for table dim.shop columns/shop_id',
65114
postTs: 1701686127533,

0 commit comments

Comments
 (0)