Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display tasks assigned to archived users #1038

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions __tests__/Unit/Components/Tabs/Tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe('Tabs Component', () => {
const presentTabs = screen.queryAllByRole('button');
expect(presentTabs.length).toBe(
TABS.filter(
(tab) => tab != 'BLOCKED' && !newTaskStatus.includes(tab)
(tab) =>
tab != Tab.BLOCKED &&
tab != Tab.ASSIGNEE_ARCHIVED &&
!newTaskStatus.includes(tab)
).length
);
});
Expand Down Expand Up @@ -118,7 +121,10 @@ describe('Tabs Component', () => {
);
const presentTabs = screen.getAllByRole('button');
const OLDTABS = TABS.filter(
(tab) => tab != 'BLOCKED' && !newTaskStatus.includes(tab)
(tab) =>
tab != Tab.BLOCKED &&
tab != Tab.ASSIGNEE_ARCHIVED &&
!newTaskStatus.includes(tab)
);
for (let i = 0; i < presentTabs.length; i++) {
expect(presentTabs[i].textContent).toBe(changeName(OLDTABS[i]));
Expand Down
44 changes: 44 additions & 0 deletions __tests__/Unit/Components/Tasks/FilterModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,48 @@ describe('FilterModal', () => {
const doneButton = screen.getByText(/done/i);
expect(doneButton).not.toHaveClass('status-button-active');
});
test('Assignee Archived Modal should be visibel in tasks page when dev=true', () => {
render(
<FilterModal
dev={true}
tabs={[Tab.ASSIGNEE_ARCHIVED, Tab.ALL]}
onSelect={mockOnSelect}
activeTab={Tab.ALL}
onClose={mockOnClose}
/>
);

const assignee_archivedButton = screen.getByText(/assignee archived/i);
expect(assignee_archivedButton).toBeInTheDocument();
});
test('Assignee Archived should not be visible when dev!=true', () => {
render(
<FilterModal
dev={false}
tabs={[Tab.ASSIGNEE_ARCHIVED, Tab.ALL]}
onSelect={mockOnSelect}
activeTab={Tab.ALL}
onClose={mockOnClose}
/>
);

expect(
screen.queryByText(/assignee archived/i)
).not.toBeInTheDocument();
});
test('Clicking on Assignee Archived from filter modal should call hte onSelect function with the right props', () => {
render(
<FilterModal
dev={true}
tabs={[Tab.ASSIGNEE_ARCHIVED, Tab.ALL]}
onSelect={mockOnSelect}
activeTab={Tab.ALL}
onClose={mockOnClose}
/>
);

const assignee_archivedButton = screen.getByText(/assignee archived/i);
fireEvent.click(assignee_archivedButton);
expect(mockOnSelect).toBeCalledWith(Tab.ASSIGNEE_ARCHIVED);
});
});
1 change: 1 addition & 0 deletions __tests__/Unit/utils/getActiveTab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Unit | Util | Get Active Tab', () => {
expect(getActiveTab('merged')).toEqual(Tab.MERGED);
expect(getActiveTab('completed')).toEqual(Tab.COMPLETED);
expect(getActiveTab('in-progress')).toEqual(Tab.IN_PROGRESS);
expect(getActiveTab('archived')).toEqual(Tab.ASSIGNEE_ARCHIVED);
expect(getActiveTab('someRandomSection')).toEqual(Tab.ALL);
});

Expand Down
14 changes: 13 additions & 1 deletion __tests__/Utils/taskQueryParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ describe('extractQueryParams', () => {
expect(result.assignees).toEqual(['sunny-s']);
expect(result.title).toBe('Develop feature');
});

it('should extract assignee-role and title assignee role from query param', () => {
const queryParam =
'assignee-role:archived assignee:sunny-s Develop feature';
const result = extractQueryParams(queryParam);
expect(result.assignees).toEqual(['sunny-s']);
expect(result.title).toBe('Develop feature');
expect(result.assigneeRole).toBe('archived');
});
it('should extract status, multiple assignees, and title from query param', () => {
const queryParam =
'status:in-progress assignee:sunny-s assignee:ajoy-kumar Develop feature';
Expand All @@ -42,6 +49,11 @@ describe('getQueryParamTab', () => {
const result = getQueryParamTab(tab);
expect(result).toBe('status:in-progress');
});
it('should generate a query param for assignee archived tab', () => {
const tab = Tab.ASSIGNEE_ARCHIVED;
const result = getQueryParamTab(tab);
expect(result).toBe('assignee-role:archived');
});
});

describe('getAPIQueryParamAssignee', () => {
Expand Down
10 changes: 7 additions & 3 deletions src/app/services/tasksApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ export const tasksApi = api.injectEndpoints({
prevTasks,
assignee,
title,
assigneeRole,
}) => {
const baseQuery = `/tasks?size=${size}&dev=true`;

let url =
!status || status === 'ALL'
!status ||
status === 'ALL' ||
status === 'ASSIGNEE_ARCHIVED'
? baseQuery
: `${baseQuery}&status=${status}`;

if (assigneeRole || status === 'ASSIGNEE_ARCHIVED') {
url += `&assignee-role=${assigneeRole}`;
}
if (assignee) {
url += `&assignee=${assignee}`;
}
Expand All @@ -43,7 +48,6 @@ export const tasksApi = api.injectEndpoints({
if (prevTasks) {
url = prevTasks;
}

return { url };
},
providesTags: ['Tasks'],
Expand Down
12 changes: 11 additions & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const Header = () => {
router.pathname === pathName &&
(router.pathname === '/pull-requests'
? queryState === state
: true) &&
(router.pathname === '/tasks' && dev
? !router?.asPath?.includes('assignee-role%3A')
: true)
}
/>
Expand All @@ -53,7 +56,14 @@ export const Header = () => {
key={index}
title={title}
link={refURL}
isActive={router.pathname === pathName}
isActive={
router.pathname === pathName &&
(router.pathname === '/tasks'
? router?.asPath?.includes(
'assignee-role%3A'
)
: true)
}
/>
)
)}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const Tabs = ({ dev, tabs, onSelect, activeTab }: TabsProps) => (
.filter((tab: Tab) =>
dev
? !depreciatedTaskStatus.includes(tab)
: tab != 'BLOCKED' && !newTaskStatus.includes(tab)
: tab != Tab.BLOCKED &&
tab != Tab.ASSIGNEE_ARCHIVED &&
!newTaskStatus.includes(tab)
)
.map((tab: Tab) => (
<button
Expand Down
3 changes: 2 additions & 1 deletion src/components/tasks/TaskSearch/FilterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const FilterModal = ({
.filter((tab: Tab) =>
dev
? !depreciatedTaskStatus.includes(tab)
: tab != 'BLOCKED' &&
: tab != Tab.BLOCKED &&
tab != Tab.ASSIGNEE_ARCHIVED &&
!newTaskStatus.includes(tab)
)
.map((tab) => (
Expand Down
13 changes: 10 additions & 3 deletions src/components/tasks/TasksContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const TasksContent = ({ dev }: { dev?: boolean }) => {
status: taskStatus,
assignees: queryAssignees,
title: queryTitle,
assigneeRole,
} = extractQueryParams(qQueryParam);
const selectedTab = getActiveTab(taskStatus);
const apiQueryAssignees = getAPIQueryParamAssignee(queryAssignees);
Expand All @@ -56,6 +57,7 @@ export const TasksContent = ({ dev }: { dev?: boolean }) => {
status: selectedTab,
assignee: apiQueryAssignees,
title: queryTitle,
assigneeRole: assigneeRole,
nextTasks,
});

Expand Down Expand Up @@ -83,11 +85,16 @@ export const TasksContent = ({ dev }: { dev?: boolean }) => {
};

const searchButtonHandler = (searchString?: string) => {
const { status, assignees, title } = extractQueryParams(
const { status, assignees, title, assigneeRole } = extractQueryParams(
searchString || inputValue
);
(searchString || inputValue) &&
searchNewTasks(status as Tab, assignees, title);
if (searchString || inputValue) {
if (assigneeRole) {
searchNewTasks(Tab.ASSIGNEE_ARCHIVED, assignees, title);
} else {
searchNewTasks(status as Tab, assignees, title);
}
}
};

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const TASK_STATUS_MAPING = {
APPROVED: 'Approved',
IN_REVIEW: 'In Review',
NEEDS_REVIEW: 'Needs Review',
ASSIGNEE_ARCHIVED: 'Assignee Archived',
};
export const SEARCH_OPTIONS = ['title', 'assignee', 'status'];
export const STATUSES = [
Expand Down
5 changes: 5 additions & 0 deletions src/constants/header-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ export const devHeaderCategories = [
refURL: '/availability-panel?dev=true',
pathName: '/availability-panel',
},
{
title: 'Tasks Assigned to Archived users',
refURL: '/tasks?q=assignee-role%3Aarchived&dev=true',
pathName: '/tasks',
},
];
1 change: 1 addition & 0 deletions src/constants/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const EMPTY_TASKS_DATA = {
COMPLETED: [],
OVERDUE: [],
DONE: [],
ASSIGNEE_ARCHIVED: [],
};

export const TASK_REQUEST_TYPES = {
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/task.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum Tab {
COMPLETED = 'COMPLETED',
OVERDUE = 'OVERDUE',
DONE = 'DONE',
ASSIGNEE_ARCHIVED = 'ASSIGNEE_ARCHIVED',
}

const TABS = Object.values(Tab);
Expand Down Expand Up @@ -123,6 +124,7 @@ export type GetAllTaskParamType = {
size?: number;
assignee?: string;
title?: string;
assigneeRole?: string;
};

export type TabTasksData = {
Expand All @@ -139,6 +141,7 @@ export type TabTasksData = {
COMPLETED: task[];
OVERDUE: task[];
DONE: task[];
ASSIGNEE_ARCHIVED: task[];
};

export type CardTaskDetails = task & {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/getActiveTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const getActiveTab = (section?: string): Tab => {
return Tab.OVERDUE;
case 'done':
return Tab.DONE;
case 'archived':
return Tab.ASSIGNEE_ARCHIVED;
default:
return Tab.ALL;
}
Expand Down
13 changes: 12 additions & 1 deletion src/utils/taskQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export function extractQueryParams(queryParam: string) {
let isValue = '';
const assigneeValues: string[] = [];
let titleValue = '';
let assigneeRole = '';

if (!queryParamsArray) {
return {
status: isValue,
assignees: assigneeValues,
title: titleValue,
assigneeRole: assigneeRole,
};
}

Expand All @@ -21,6 +23,9 @@ export function extractQueryParams(queryParam: string) {
isValue = param.replace('status:', '');
} else if (param.startsWith('assignee:')) {
assigneeValues.push(param.replace('assignee:', ''));
} else if (param.startsWith('assignee-role:')) {
assigneeRole = param.replace('assignee-role:', '');
isValue = param.replace('assignee-role:', '');
} else {
titleValue += param + ' ';
}
Expand All @@ -32,10 +37,16 @@ export function extractQueryParams(queryParam: string) {
status: isValue,
assignees: assigneeValues,
title: titleValue,
assigneeRole: assigneeRole,
};
}

export const getQueryParamTab = (tab: Tab) => `status:${tabToUrlParams(tab)}`;
export const getQueryParamTab = (tab: Tab) => {
if (tab === Tab.ASSIGNEE_ARCHIVED) {
return 'assignee-role:archived';
}
return `status:${tabToUrlParams(tab)}`;
};
export const getAPIQueryParamAssignee = (assignees: string[]) => {
if (assignees.length === 0) return '';
const apiqueryParamAssignee = assignees.join(',');
Expand Down
Loading