Files
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

149 lines
4.7 KiB
TypeScript

import { Pagination } from '@rocket.chat/fuselage';
import { useDebouncedValue, useStableCallback } from '@rocket.chat/fuselage-hooks';
import {
GenericTable,
GenericTableHeaderCell,
GenericTableHeader,
GenericTableLoadingRow,
GenericTableBody,
GenericTableRow,
GenericTableCell,
usePagination,
useSort,
} from '@rocket.chat/ui-client';
import { useTranslation, useEndpoint, useRouter } from '@rocket.chat/ui-contexts';
import { useQuery, hashKey } from '@tanstack/react-query';
import type { MutableRefObject } from 'react';
import { useMemo, useState, useEffect } from 'react';
import RemoveSlaButton from './RemoveSlaButton';
import FilterByText from '../../../components/FilterByText';
import GenericNoResults from '../../../components/GenericNoResults/GenericNoResults';
import { links } from '../../../lib/links';
const SlaTable = ({ reload }: { reload: MutableRefObject<() => void> }) => {
const t = useTranslation();
const router = useRouter();
const [filter, setFilter] = useState('');
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
const { sortBy, sortDirection, setSort } = useSort<'name' | 'description' | 'dueTimeInMinutes'>('name');
const query = useDebouncedValue(
useMemo(
() => ({
text: filter,
sort: JSON.stringify({ [sortBy]: sortDirection === 'asc' ? 1 : -1 }),
...(itemsPerPage && { count: itemsPerPage }),
...(current && { offset: current }),
}),
[filter, itemsPerPage, current, sortBy, sortDirection],
),
500,
);
const getSlaData = useEndpoint('GET', '/v1/livechat/sla');
const { data, isSuccess, isLoading, refetch } = useQuery({
queryKey: ['/v1/livechat/sla', query],
queryFn: () => getSlaData(query),
});
const [defaultQuery] = useState(hashKey([query]));
const queryHasChanged = defaultQuery !== hashKey([query]);
useEffect(() => {
reload.current = refetch;
}, [reload, refetch]);
const handleAddNew = useStableCallback(() => router.navigate('/omnichannel/sla-policies/new'));
const onRowClick = useStableCallback((id: string) => () => router.navigate(`/omnichannel/sla-policies/edit/${id}`));
const headers = (
<>
<GenericTableHeaderCell key='name' direction={sortDirection} active={sortBy === 'name'} onClick={setSort} sort='name'>
{t('Name')}
</GenericTableHeaderCell>
<GenericTableHeaderCell
key='description'
direction={sortDirection}
active={sortBy === 'description'}
onClick={setSort}
sort='description'
>
{t('Description')}
</GenericTableHeaderCell>
<GenericTableHeaderCell
key='dueTimeInMinutes'
direction={sortDirection}
active={sortBy === 'dueTimeInMinutes'}
onClick={setSort}
sort='dueTimeInMinutes'
>
{t('Estimated_wait_time')}
</GenericTableHeaderCell>
<GenericTableHeaderCell key='remove' width='x60'>
{t('Remove')}
</GenericTableHeaderCell>
</>
);
return (
<>
{((isSuccess && data?.sla.length > 0) || queryHasChanged) && (
<FilterByText value={filter} onChange={(event) => setFilter(event.target.value)} />
)}
{isLoading && (
<GenericTable>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
<GenericTableLoadingRow cols={4} />
</GenericTableBody>
</GenericTable>
)}
{isSuccess && data?.sla.length === 0 && queryHasChanged && <GenericNoResults />}
{isSuccess && data?.sla.length === 0 && !queryHasChanged && (
<GenericNoResults
icon='flag'
title={t('No_SLA_policies_yet')}
description={t('No_SLA_policies_yet_description')}
buttonTitle={t('Create_SLA_policy')}
buttonAction={handleAddNew}
linkHref={links.go.omnichannelDocs}
linkText={t('Learn_more_about_SLA_policies')}
/>
)}
{isSuccess && data?.sla.length > 0 && (
<>
<GenericTable aria-label={t('SLA_Policies')}>
<GenericTableHeader>{headers}</GenericTableHeader>
<GenericTableBody>
{data?.sla.map(({ _id, name, description, dueTimeInMinutes }) => (
<GenericTableRow key={_id} tabIndex={0} onClick={onRowClick(_id)} action>
<GenericTableCell withTruncatedText>{name}</GenericTableCell>
<GenericTableCell withTruncatedText>{description}</GenericTableCell>
<GenericTableCell withTruncatedText>
{dueTimeInMinutes} {t('minutes')}
</GenericTableCell>
<RemoveSlaButton _id={_id} reload={refetch} />
</GenericTableRow>
))}
</GenericTableBody>
</GenericTable>
<Pagination
divider
current={current}
itemsPerPage={itemsPerPage}
count={data?.total || 0}
onSetItemsPerPage={onSetItemsPerPage}
onSetCurrent={onSetCurrent}
{...paginationProps}
/>
</>
)}
</>
);
};
export default SlaTable;