Skip to content

Commit

Permalink
#14486 : fix current user appearing while editing task assignees (#14557
Browse files Browse the repository at this point in the history
)

* fix current user appering while editing task assignees

* added unit test to filter current user

* minor changes
  • Loading branch information
Ashish8689 authored Jan 3, 2024
1 parent 6bb0161 commit a0d8513
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ export const TaskTab = ({
onChange={(values) =>
assigneesForm.setFieldValue('assignees', values)
}
onSearch={(query) => fetchOptions(query, setOptions)}
onSearch={(query) =>
fetchOptions(query, setOptions, currentUser?.id)
}
/>
</InlineEdit>
</Form.Item>
Expand Down
175 changes: 175 additions & 0 deletions openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,178 @@ export const TASK_COLUMNS: Column[] = [
ordinalPosition: 3,
},
];

export const MOCK_ASSIGNEE_DATA = {
suggest: {
'metadata-suggest': [
{
text: 'ash',
offset: 0,
length: 3,
options: [
{
text: 'Ashish Gupta',
_index: 'user_search_index',
_type: '_doc',
_id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4',
_score: 30,
_ignored: ['description.keyword'],
_source: {
id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4',
name: 'ashish',
fullyQualifiedName: 'ashish',
description:
'this is test description. this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!',
displayName: 'Ashish Gupta',
version: 0.8,
updatedAt: 1699428544440,
updatedBy: 'ashish',
email: 'ashish@getcollate.io',
isBot: false,
isAdmin: true,
profile: {
images: {
image:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s96-c',
image24:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s24-c',
image32:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s32-c',
image48:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s48-c',
image72:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s72-c',
image192:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s192-c',
image512:
'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s512-c',
},
},
teams: [
{
id: '9efbccd7-3d0b-485d-89c4-ac0f8fc80da5',
type: 'team',
name: 'Organization',
fullyQualifiedName: 'Organization',
description:
'Organization under which all the other team hierarchy is created',
displayName: 'Organization',
deleted: false,
href: 'http://sandbox-beta.open-metadata.org/api/v1/teams/9efbccd7-3d0b-485d-89c4-ac0f8fc80da5',
},
],
personas: [],
deleted: false,
roles: [],
inheritedRoles: [
{
id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25',
type: 'role',
name: 'DataConsumer',
fullyQualifiedName: 'DataConsumer',
description:
'Users with Data Consumer role use different data assets for their day to day work.',
displayName: 'Data Consumer',
deleted: false,
},
],
isEmailVerified: true,
domain: {
id: '9545569e-9b4e-4be0-8142-ce5d502fbab7',
type: 'domain',
name: 'Product',
fullyQualifiedName: 'Product',
description:
'A Domain producing and serving Product Master Data.',
displayName: 'Product Name',
inherited: true,
},
fqnParts: ['ashish', 'Ashish Gupta'],
suggest: [
{
input: 'ashish',
weight: 5,
},
{
input: 'Ashish Gupta',
weight: 10,
},
],
entityType: 'user',
},
contexts: {
deleted: ['false'],
},
},
{
text: 'Ashley King',
_index: 'user_search_index',
_type: '_doc',
_id: '0c83a592-7ced-4156-b235-01726259a0e7',
_score: 30,
_source: {
id: '0c83a592-7ced-4156-b235-01726259a0e7',
name: 'ashley_king5',
fullyQualifiedName: 'ashley_king5',
displayName: 'Ashley King',
version: 0.2,
updatedAt: 1702647808915,
updatedBy: 'ingestion-bot',
email: 'ashley_king5@gmail.com',
isAdmin: false,
teams: [
{
id: 'dfa05a46-eb4f-4c68-8cd6-140b0d330b8d',
type: 'team',
name: 'Compute',
fullyQualifiedName: 'Compute',
deleted: false,
},
],
personas: [],
deleted: false,
roles: [],
inheritedRoles: [
{
id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25',
type: 'role',
name: 'DataConsumer',
fullyQualifiedName: 'DataConsumer',
description:
'Users with Data Consumer role use different data assets for their day to day work.',
displayName: 'Data Consumer',
deleted: false,
},
],
domain: {
id: '52fc9c67-78b7-42bf-8147-69278853c230',
type: 'domain',
name: 'Design',
fullyQualifiedName: 'Design',
description: "Here' the description for Product Design",
displayName: 'Product Design ',
inherited: true,
},
fqnParts: ['ashley_king5', 'Ashley King'],
suggest: [
{
input: 'ashley_king5',
weight: 5,
},
{
input: 'Ashley King',
weight: 10,
},
],
entityType: 'user',
isBot: false,
},
contexts: {
deleted: ['false'],
},
},
],
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
* limitations under the License.
*/

import { act } from '@testing-library/react';
import { EntityType } from '../enums/entity.enum';
import { mockTableData } from '../mocks/TableVersion.mock';
import { getEntityTableName, getTaskMessage } from './TasksUtils';
import { MOCK_ASSIGNEE_DATA } from '../mocks/Task.mock';
import { getUserSuggestions } from '../rest/miscAPI';
import { fetchOptions, getEntityTableName, getTaskMessage } from './TasksUtils';

jest.mock('../rest/miscAPI', () => ({
getUserSuggestions: jest
.fn()
.mockImplementation(() => Promise.resolve(MOCK_ASSIGNEE_DATA)),
}));

describe('Tests for DataAssetsHeaderUtils', () => {
it('function getEntityTableName should return name if no data found', () => {
Expand Down Expand Up @@ -157,3 +166,57 @@ describe('Tests for getTaskMessage', () => {
);
});
});

describe('Tests for fetchOptions', () => {
it('function fetchOptions should trigger setOptions without filtered options', async () => {
const mockSetOptions = jest.fn();

(getUserSuggestions as jest.Mock).mockImplementationOnce(() =>
Promise.resolve({ data: MOCK_ASSIGNEE_DATA })
);

await act(async () => {
fetchOptions('test_user', mockSetOptions);
});

expect(mockSetOptions).toHaveBeenCalledWith([
{
label: 'ashish',
name: 'ashish',
type: 'user',
value: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4',
},
{
label: 'ashley_king5',
name: 'ashley_king5',
type: 'user',
value: '0c83a592-7ced-4156-b235-01726259a0e7',
},
]);
});

it('function fetchOptions should trigger setOptions with filtered options', async () => {
const mockSetOptions = jest.fn();

(getUserSuggestions as jest.Mock).mockImplementationOnce(() =>
Promise.resolve({ data: MOCK_ASSIGNEE_DATA })
);

await act(async () => {
fetchOptions(
'test_user',
mockSetOptions,
'18ca6cd1-d696-4a22-813f-c7a42fc09dc4'
);
});

expect(mockSetOptions).toHaveBeenCalledWith([
{
label: 'ashley_king5',
name: 'ashley_king5',
type: 'user',
value: '0c83a592-7ced-4156-b235-01726259a0e7',
},
]);
});
});
5 changes: 3 additions & 2 deletions openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export const getDescriptionDiff = (

export const fetchOptions = (
query: string,
setOptions: (value: React.SetStateAction<Option[]>) => void
setOptions: (value: React.SetStateAction<Option[]>) => void,
currentUserId?: string
) => {
getUserSuggestions(query)
.then((res) => {
Expand All @@ -200,7 +201,7 @@ export const fetchOptions = (
name: hit._source.name,
}));

setOptions(suggestOptions);
setOptions(suggestOptions.filter((item) => item.value !== currentUserId));
})
.catch((err: AxiosError) => showErrorToast(err));
};
Expand Down

0 comments on commit a0d8513

Please sign in to comment.