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

Chore: fix e2e Omnichannel tests #28097

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Box, Table } from '@rocket.chat/fuselage';
import type { ReactNode } from 'react';
import type { ReactNode, TableHTMLAttributes } from 'react';
import React, { forwardRef } from 'react';

import ScrollableContentWrapper from '../../ScrollableContentWrapper';

type GenericTableProps = {
fixed?: boolean;
children: ReactNode;
};
} & TableHTMLAttributes<HTMLTableElement>;

export const GenericTable = forwardRef<HTMLElement, GenericTableProps>(function GenericTable({ fixed = true, children }, ref) {
export const GenericTable = forwardRef<HTMLElement, GenericTableProps>(function GenericTable({ fixed = true, children, ...props }, ref) {
return (
<Box mi='neg-x24' pi='x24' flexShrink={1} flexGrow={1} ref={ref} overflow='hidden'>
<ScrollableContentWrapper overflowX>
<Table fixed={fixed} sticky>
{/* TODO: Fix fuselage */}
<Table fixed={fixed} sticky {...(props as any)}>
{children}
</Table>
</ScrollableContentWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { useMemo, useState } from 'react';
import React, { useState } from 'react';

import FilterByText from '../../../components/FilterByText';
import { usePagination } from '../../../components/GenericTable/hooks/usePagination';
Expand All @@ -13,34 +13,41 @@ import DepartmentsTable from './DepartmentsTable';

const DepartmentsPageWithData = (): ReactElement => {
const [text, setText] = useState('');

const [debouncedText = ''] = useDebouncedValue(text, 500);
const pagination = usePagination();
const sort = useSort<'name' | 'email' | 'active'>('name');

const query = useDebouncedValue(
useMemo(() => {
return {
onlyMyDepartments: 'true' as const,
text,
const getDepartments = useEndpoint('GET', '/v1/livechat/department');

const result = useQuery(
['omnichannel', 'departments', debouncedText, pagination, sort],
() =>
getDepartments({
onlyMyDepartments: 'true',
text: debouncedText,
sort: JSON.stringify({ [sort.sortBy]: sort.sortDirection === 'asc' ? 1 : -1 }),
...(pagination.current && { offset: pagination.current }),
...(pagination.itemsPerPage && { count: pagination.itemsPerPage }),
fields: JSON.stringify({ name: 1, username: 1, emails: 1, avatarETag: 1 }),
};
}, [pagination, sort.sortBy, sort.sortDirection, text]),
500,
}),
{
keepPreviousData: true,
},
);

const getDepartments = useEndpoint('GET', '/v1/livechat/department');

const { data, isLoading } = useQuery(['omnichannel', 'departments', query], () => getDepartments(query));

const removeButton = (dep: Omit<ILivechatDepartment, '_updatedAt'>) => <DepartmentItemMenu dep={dep} />;

return (
<>
<FilterByText onChange={({ text }): void => setText(text)} />
<DepartmentsTable data={data} sort={sort} pagination={pagination} removeButton={removeButton} loading={isLoading}></DepartmentsTable>
<DepartmentsTable
aria-busy={text !== debouncedText}
aria-live='assertive'
data={result.data}
sort={sort}
pagination={pagination}
removeButton={removeButton}
loading={result.isLoading && result.isInitialLoading}
></DepartmentsTable>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ILivechatDepartment } from '@rocket.chat/core-typings';
import { Pagination } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import type { ReactElement, TableHTMLAttributes } from 'react';
import React, { useMemo } from 'react';

import {
Expand All @@ -20,9 +20,9 @@ type DepartmentsTableProps = {
pagination: any;
sort: any;
loading: boolean;
};
} & TableHTMLAttributes<HTMLTableElement>;

function DepartmentsTable({ data, removeButton, pagination, sort, loading }: DepartmentsTableProps) {
function DepartmentsTable({ data, removeButton, pagination, sort, loading, ...props }: DepartmentsTableProps) {
const t = useTranslation();

const { departments } = data || {};
Expand All @@ -46,14 +46,14 @@ function DepartmentsTable({ data, removeButton, pagination, sort, loading }: Dep
<GenericTableHeaderCell key='showOnRegistration' direction={sortDirection} active={sortBy === 'showOnRegistration'} onClick={setSort}>
{t('Show_on_registration_page')}
</GenericTableHeaderCell>,
<GenericTableHeaderCell w={40} />,
<GenericTableHeaderCell key='spacer' w={40} />,
],
[setSort, sortBy, sortDirection, t],
);

return (
<>
<GenericTable>
<GenericTable {...props}>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{departments && !loading ? (
Expand Down
4 changes: 0 additions & 4 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,6 @@ const LivechatDepartmentSchema = {
type: 'string',
nullable: true,
},
fields: {
type: 'string',
nullable: true,
},
},
additionalProperties: false,
};
Expand Down