Skip to content

Commit

Permalink
Minor: added support for edit assign button in incident manager (#17646)
Browse files Browse the repository at this point in the history
* Minor: Added support for assignee edit in incident manager

* minor change

* minor fix
  • Loading branch information
ShaileshParmar11 authored Aug 30, 2024
1 parent 08a212e commit b618bb5
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const testCases = [
];
const user1 = generateRandomUser();
const user2 = generateRandomUser();
const user3 = generateRandomUser();
const userData1 = {
displayName: `${user1.firstName}${user1.lastName}`,
name: user1.email.split('@')[0],
Expand All @@ -44,6 +45,10 @@ const userData2 = {
displayName: `${user2.firstName}${user2.lastName}`,
name: user2.email.split('@')[0],
};
const userData3 = {
displayName: `${user3.firstName}${user3.lastName}`,
name: user3.email.split('@')[0],
};
const userIds: string[] = [];

const goToProfilerTab = () => {
Expand Down Expand Up @@ -132,22 +137,16 @@ describe('Incident Manager', { tags: 'Observability' }, () => {
const token = getToken(data);

// Create a new user
cy.request({
method: 'POST',
url: `/api/v1/users/signup`,
headers: { Authorization: `Bearer ${token}` },
body: user1,
}).then((response) => {
userIds.push(response.body.id);
});
cy.request({
method: 'POST',
url: `/api/v1/users/signup`,
headers: { Authorization: `Bearer ${token}` },
body: user2,
}).then((response) => {
userIds.push(response.body.id);
});
for (const user of [user1, user2, user3]) {
cy.request({
method: 'POST',
url: `/api/v1/users/signup`,
headers: { Authorization: `Bearer ${token}` },
body: user,
}).then((response) => {
userIds.push(response.body.id);
});
}

createEntityTableViaREST({
token,
Expand Down Expand Up @@ -297,6 +296,38 @@ describe('Incident Manager', { tags: 'Observability' }, () => {
.should('be.visible');
});

it("Re-assign incident from test case page's header", () => {
interceptURL(
'GET',
'/api/v1/dataQuality/testCases/name/*?fields=*',
'getTestCase'
);
interceptURL('GET', '/api/v1/feed?entityLink=*&type=Task', 'getTaskFeed');
cy.sidebarClick(SidebarItem.INCIDENT_MANAGER);
cy.get(`[data-testid="test-case-${testCaseName}"]`).click();
verifyResponseStatusCode('@getTestCase', 200);
interceptURL('GET', '/api/v1/users?*', 'getUsers');
cy.get('[data-testid="assignee"] [data-testid="edit-owner"]').click();
verifyResponseStatusCode('@getUsers', 200);
cy.get('[data-testid="loader"]').should('not.exist');
interceptURL('GET', `api/v1/search/query?q=*`, 'searchOwner');
cy.get('[data-testid="owner-select-users-search-bar"]').type(
userData3.displayName
);
verifyResponseStatusCode('@searchOwner', 200);
interceptURL(
'POST',
'/api/v1/dataQuality/testCases/testCaseIncidentStatus',
'updateTestCaseIncidentStatus'
);
cy.get(`.ant-popover [title="${userData3.displayName}"]`).click();
verifyResponseStatusCode('@updateTestCaseIncidentStatus', 200);
cy.get('[data-testid="assignee"] [data-testid="owner-link"]').should(
'contain',
userData3.displayName
);
});

it('Resolve incident', () => {
interceptURL(
'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ import { usePermissionProvider } from '../../../../context/PermissionProvider/Pe
import { ResourceEntity } from '../../../../context/PermissionProvider/PermissionProvider.interface';
import { EntityTabs, EntityType } from '../../../../enums/entity.enum';
import { ThreadType } from '../../../../generated/api/feed/createThread';
import { CreateTestCaseResolutionStatus } from '../../../../generated/api/tests/createTestCaseResolutionStatus';
import {
Thread,
ThreadTaskStatus,
} from '../../../../generated/entity/feed/thread';
import { Operation } from '../../../../generated/entity/policies/policy';
import { EntityReference } from '../../../../generated/tests/testCase';
import {
Severities,
TestCaseResolutionStatus,
TestCaseResolutionStatusTypes,
} from '../../../../generated/tests/testCaseResolutionStatus';
import {
getListTestCaseIncidentByStateId,
postTestCaseIncidentStatus,
updateTestCaseIncidentById,
} from '../../../../rest/incidentManagerAPI';
import { getNameFromFQN } from '../../../../utils/CommonUtils';
Expand Down Expand Up @@ -97,11 +100,49 @@ const IncidentManagerPageHeader = ({
}
};

const updateAssignee = async (data: CreateTestCaseResolutionStatus) => {
try {
await postTestCaseIncidentStatus(data);
} catch (error) {
showErrorToast(error as AxiosError);
}
};

const onIncidentStatusUpdate = (data: TestCaseResolutionStatus) => {
setTestCaseStatusData(data);
updateTestCaseIncidentStatus([...testCaseResolutionStatus, data]);
};

const handleAssigneeUpdate = (assignee?: EntityReference[]) => {
if (isUndefined(testCaseStatusData)) {
return;
}

const assigneeData = assignee?.[0];

const updatedData: TestCaseResolutionStatus = {
...testCaseStatusData,
testCaseResolutionStatusDetails: {
...testCaseStatusData?.testCaseResolutionStatusDetails,
assignee: assigneeData,
},
testCaseResolutionStatusType: TestCaseResolutionStatusTypes.Assigned,
};

const createTestCaseResolutionStatus: CreateTestCaseResolutionStatus = {
severity: testCaseStatusData.severity,
testCaseReference:
testCaseStatusData.testCaseReference?.fullyQualifiedName ?? '',
testCaseResolutionStatusType: TestCaseResolutionStatusTypes.Assigned,
testCaseResolutionStatusDetails: {
assignee: assigneeData,
},
};

updateAssignee(createTestCaseResolutionStatus);
onIncidentStatusUpdate(updatedData);
};

const fetchTestCaseResolution = async (id: string) => {
try {
const { data } = await getListTestCaseIncidentByStateId(id);
Expand Down Expand Up @@ -220,14 +261,25 @@ const IncidentManagerPageHeader = ({
/>
</Typography.Text>
<Divider className="self-center m-x-sm" type="vertical" />
<Typography.Text className="d-flex items-center gap-2 text-xs whitespace-nowrap">
<Typography.Text
className="d-flex items-center gap-2 text-xs whitespace-nowrap"
data-testid="assignee">
<span className="text-grey-muted">{`${t('label.assignee')}: `}</span>

<OwnerLabel
hasPermission={hasEditPermission}
multiple={{
user: false,
team: false,
}}
owners={details?.assignee ? [details.assignee] : []}
placeHolder={t('label.no-entity', {
entity: t('label.assignee'),
})}
tooltipText={t('label.edit-entity', {
entity: t('label.assignee'),
})}
onUpdate={handleAssigneeUpdate}
/>
</Typography.Text>
<Divider className="self-center m-x-sm" type="vertical" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export const OwnerLabel = ({
ownerDisplayName,
placeHolder,
maxVisibleOwners = 3, // Default to 3 if not provided
multiple = {
user: true,
team: false,
},
tooltipText,
}: {
owners?: EntityReference[];
className?: string;
Expand All @@ -47,6 +52,11 @@ export const OwnerLabel = ({
ownerDisplayName?: ReactNode[];
placeHolder?: string;
maxVisibleOwners?: number;
multiple?: {
user: boolean;
team: boolean;
};
tooltipText?: string;
}) => {
const { t } = useTranslation();
const [showAllOwners, setShowAllOwners] = useState(false);
Expand Down Expand Up @@ -162,11 +172,9 @@ export const OwnerLabel = ({
{onUpdate && (
<UserTeamSelectableList
hasPermission={Boolean(hasPermission)}
multiple={{
user: true,
team: false,
}}
multiple={multiple}
owner={owners}
tooltipText={tooltipText}
onUpdate={(updatedUsers) => {
onUpdate(updatedUsers);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const UserTeamSelectableList = ({
label,
previewSelected = false,
listHeight = ADD_USER_CONTAINER_HEIGHT,
tooltipText,
}: UserSelectDropdownProps) => {
const { t } = useTranslation();
const [popupVisible, setPopupVisible] = useState(false);
Expand Down Expand Up @@ -371,9 +372,10 @@ export const UserTeamSelectableList = ({
<Tooltip
title={
!popupVisible &&
t('label.edit-entity', {
entity: t('label.owner'),
})
(tooltipText ??
t('label.edit-entity', {
entity: t('label.owner'),
}))
}>
<Button
className="flex-center p-0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export interface UserSelectDropdownProps {
label?: string;
previewSelected?: boolean;
listHeight?: number;
tooltipText?: string;
}

0 comments on commit b618bb5

Please sign in to comment.