feat(web): 同步预约演示与兜底渠道优化
This commit is contained in:
@@ -34,6 +34,22 @@
|
||||
- **回滚**:按关联文件还原本条对应的布局、样式和焦点处理。
|
||||
- **关联**:`src/pages/WeyAiDownload/{index.jsx,weyai-download.css}`、`docs/ui/GLOBAL_UI_BASELINE.md` 第 5 节。
|
||||
|
||||
### 优化 · 兜底渠道选择器
|
||||
|
||||
- **范围** 控制台「渠道管理」的渠道编辑抽屉。
|
||||
- **变更** 下拉项和已选标签显示渠道 ID 与名称,禁用状态以灰态和悬停提示表达。
|
||||
- **影响** 可按 ID、名称、分组和地域搜索。写入兜底链时仍按选择顺序提交数字 ID。
|
||||
- **回滚** 还原渠道编辑抽屉的选项标签和搜索字段。
|
||||
- **关联** `src/components/table/channels/modals/EditChannelModal.jsx`。
|
||||
|
||||
### 功能 · 预约演示列表管理
|
||||
|
||||
- **范围** 控制台「预约演示」。
|
||||
- **变更** 支持当前页多选、导出选中行的 CSV、逐条启停与确认删除。列宽按常见字段长度分配,表头字段居中,需求列随窗口加宽,窄屏下固定复选框和操作列。
|
||||
- **影响** 历史和新提交记录默认启用,删除记录从预约列表中移除并保留在数据库中。
|
||||
- **回滚** 还原本次前后端变更。旧版列表会重新显示软删除记录。
|
||||
- **关联** `src/pages/DemoReservations/` 和 `website_demo_requests`。
|
||||
|
||||
## 2026-11-21
|
||||
|
||||
### 修复 · 视频生成任务队列分页
|
||||
|
||||
@@ -270,17 +270,21 @@ const EditChannelModal = (props) => {
|
||||
res.data.data
|
||||
.filter((ch) => ch.id !== selfId)
|
||||
.map((ch) => {
|
||||
const label = `${formatIdReference(ch.id)} ${ch.name}`;
|
||||
if (ch.status !== 1) {
|
||||
const searchLabel = `${label}${t('(已禁用)')}`;
|
||||
return {
|
||||
value: ch.id,
|
||||
label: `${formatIdReference(ch.id)} ${ch.name}${t('(已禁用)')}`,
|
||||
label,
|
||||
searchLabel,
|
||||
title: searchLabel,
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
const parts = [`${formatIdReference(ch.id)} ${ch.name}`];
|
||||
if (ch.group) parts.push(ch.group);
|
||||
if (ch.region) parts.push(ch.region);
|
||||
return { value: ch.id, label: parts.join(' · ') };
|
||||
const searchLabel = [label, ch.group, ch.region]
|
||||
.filter(Boolean)
|
||||
.join(' · ');
|
||||
return { value: ch.id, label, searchLabel };
|
||||
}),
|
||||
);
|
||||
setFallbackCandidatesLoaded(true);
|
||||
@@ -2993,6 +2997,9 @@ const EditChannelModal = (props) => {
|
||||
filter
|
||||
showClear
|
||||
max={20}
|
||||
showSearch={{
|
||||
optionFilterProp: ['searchLabel', 'label'],
|
||||
}}
|
||||
optionList={fallbackOptionList}
|
||||
// Semi 对 disabled option 的已选标签不给关闭按钮;
|
||||
// 已禁用/已删除的渠道需要能从链中移除,故自绘可关闭标签
|
||||
@@ -3004,9 +3011,20 @@ const EditChannelModal = (props) => {
|
||||
color='white'
|
||||
size='large'
|
||||
onClose={onClose}
|
||||
style={{ maxWidth: '100%' }}
|
||||
title={
|
||||
option.disabled ? option.searchLabel : undefined
|
||||
}
|
||||
style={{
|
||||
maxWidth: '100%',
|
||||
color: option.disabled
|
||||
? 'var(--text-secondary)'
|
||||
: undefined,
|
||||
}}
|
||||
>
|
||||
{option.label}
|
||||
{option.disabled && option.searchLabel && (
|
||||
<span className='sr-only'>{t('(已禁用)')}</span>
|
||||
)}
|
||||
</Tag>
|
||||
),
|
||||
})}
|
||||
|
||||
@@ -6,14 +6,15 @@ export async function requestWebsite(
|
||||
url,
|
||||
body,
|
||||
fallback = '请求失败,请稍后重试',
|
||||
{ params, signal } = {},
|
||||
) {
|
||||
let response;
|
||||
try {
|
||||
const options = { skipErrorHandler: true, timeout: 20000 };
|
||||
const options = { skipErrorHandler: true, timeout: 20000, params, signal };
|
||||
response =
|
||||
method === 'get'
|
||||
? await API.get(url, options)
|
||||
: await API.post(url, body, options);
|
||||
method === 'get' || method === 'delete'
|
||||
? await API[method](url, options)
|
||||
: await API[method](url, body, options);
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
showError(error);
|
||||
|
||||
@@ -569,6 +569,7 @@ export const useVideoGeneration = ({ disableQuote = false } = {}) => {
|
||||
const res = await API.get('/api/video/tasks', {
|
||||
params: { p: query.page, page_size: query.pageSize },
|
||||
skipErrorHandler: true,
|
||||
disableDuplicate: true,
|
||||
});
|
||||
// 快速翻页时只采纳最后一次请求的结果
|
||||
if (requestId !== taskRequestRef.current || !mountedRef.current) return;
|
||||
@@ -811,6 +812,7 @@ export const useVideoGeneration = ({ disableQuote = false } = {}) => {
|
||||
);
|
||||
}
|
||||
trackTasks([task.task_id]);
|
||||
loadTasks();
|
||||
}
|
||||
showInfo(t('视频生成任务已提交,请稍候...'));
|
||||
return true;
|
||||
@@ -837,7 +839,7 @@ export const useVideoGeneration = ({ disableQuote = false } = {}) => {
|
||||
setSubmitting(false);
|
||||
}
|
||||
},
|
||||
[selectedModel, trackTasks, t],
|
||||
[selectedModel, trackTasks, loadTasks, t],
|
||||
);
|
||||
|
||||
const handleGenerate = useCallback(async () => {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# 预约演示列表
|
||||
|
||||
页面复用 CardPro、CardTable、CompactModeToggle 和 createCardProPagination。
|
||||
桌面端搜索栏靠左,移动端沿用系统的操作区展开和卡片展示方式。
|
||||
页面复用 CardPro、CardTable 和 createCardProPagination。
|
||||
需求列使用表格剩余宽度。窄屏在表格内横向滚动,复选框和操作列分别固定在两侧。
|
||||
|
||||
## 已接入接口
|
||||
|
||||
GET /api/website/demo-requests,通过项目共享 API 实例发送 Cookie 和 New-Api-User。
|
||||
不再使用本地演示列表。业务 success 必须严格为 true,否则显示后端 message 或错误提示。
|
||||
|
||||
筛选字段:name、contact、companyName,去除首尾空白并以 URLSearchParams 编码。
|
||||
筛选字段为 name、contact、companyName。去除首尾空白后通过共享 API 实例的 `params` 发送。
|
||||
模糊搜索由后端执行,三个条件为 AND。请求分页为 p 和 page_size;
|
||||
响应读取 data.items、data.total、data.page 和 data.page_size。
|
||||
|
||||
@@ -17,6 +17,13 @@ GET /api/website/demo-requests,通过项目共享 API 实例发送 Cookie 和
|
||||
公司名称与需求分别使用 companyName 和 requirement,不使用原型字段 company/requirements。
|
||||
需求列表最多显示三行,保留内部换行,不提供查看完整需求按钮或弹窗。
|
||||
|
||||
## 记录操作
|
||||
|
||||
- 可在当前页勾选或全选预约,导出所选记录的列表业务字段及启用状态。重新筛选或翻页时清空勾选。
|
||||
- `PUT /api/website/demo-requests/:id/status` 接收布尔值 `enabled`。历史和新提交的预约默认启用。
|
||||
- `DELETE /api/website/demo-requests/:id` 在确认后软删除记录。列表会刷新并在当前页变空时回退到有效页。
|
||||
- 写接口沿用列表的超管或「预约演示」委派权限。
|
||||
|
||||
## 模拟提交与验收
|
||||
|
||||
本地脚本 scripts/seed-demo-requests.mjs 默认仅预览,添加 --submit 才真实新增三条联调测试预约。
|
||||
|
||||
@@ -1,25 +1,46 @@
|
||||
import TableEmpty from '../../components/common/table/TableEmpty';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Banner, Button, Form, Spin } from '@/components/ui';
|
||||
import { Button as AntButton, Popconfirm, Switch } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import CardPro from '../../components/common/ui/CardPro';
|
||||
import CardTable from '../../components/common/ui/CardTable';
|
||||
import CompactModeToggle from '../../components/common/ui/CompactModeToggle';
|
||||
import FilterSearchButton from '../../components/common/table/FilterSearchButton';
|
||||
import '../../components/common/table/log-filters.css';
|
||||
|
||||
import { createCardProPagination } from '../../helpers/utils';
|
||||
import { exportToCsv } from '../../helpers/exportCsv';
|
||||
import { createCardProPagination, showError } from '../../helpers/utils';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { useTableCompactMode } from '../../hooks/common/useTableCompactMode';
|
||||
import { fetchDemoReservations } from './reservationsApi';
|
||||
import {
|
||||
deleteDemoReservation,
|
||||
fetchDemoReservations,
|
||||
setDemoReservationEnabled,
|
||||
} from './reservationsApi';
|
||||
|
||||
const EMPTY_FILTERS = { name: '', contact: '', companyName: '' };
|
||||
const RESERVATION_TABLE_MIN_WIDTH = 1280;
|
||||
const RESERVATION_FIELDS = [
|
||||
['name', '姓名', 96],
|
||||
['contact', '联系方式', 172],
|
||||
['companyName', '公司名称', 174],
|
||||
['position', '职位', 108],
|
||||
['industry', '行业', 112],
|
||||
['interest', '关注方向', 144],
|
||||
// Leave the longest field flexible so it takes the remaining width.
|
||||
['requirement', '需求'],
|
||||
];
|
||||
|
||||
function reservationCsvValue(value) {
|
||||
const text = String(value ?? '');
|
||||
// Detect spreadsheet formula prefixes, including full-width variants.
|
||||
return /^(?:\s*[=+@-]|[\t\r\n])/.test(text.normalize('NFKC'))
|
||||
? `'${text}`
|
||||
: text;
|
||||
}
|
||||
|
||||
export default function DemoReservations() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const [compactMode, setCompactMode] =
|
||||
useTableCompactMode('demo-reservations');
|
||||
const formRef = useRef(null);
|
||||
const [query, setQuery] = useState({
|
||||
...EMPTY_FILTERS,
|
||||
@@ -29,44 +50,56 @@ export default function DemoReservations() {
|
||||
const [result, setResult] = useState({ items: [], total: 0 });
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
||||
const [savingId, setSavingId] = useState(null);
|
||||
const busy = loading || savingId !== null;
|
||||
|
||||
const changeQuery = (update) => {
|
||||
setSelectedRowKeys([]);
|
||||
setLoading(true);
|
||||
setQuery(update);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
const controller = new AbortController();
|
||||
const { signal } = controller;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
fetchDemoReservations(query)
|
||||
let changedPage = false;
|
||||
fetchDemoReservations(query, { signal })
|
||||
.then((data) => {
|
||||
if (active) setResult(data);
|
||||
if (signal.aborted) return;
|
||||
const lastPage = Math.max(1, Math.ceil(data.total / data.page_size));
|
||||
if (data.items.length === 0 && query.page > lastPage) {
|
||||
changedPage = true;
|
||||
setSelectedRowKeys([]);
|
||||
setQuery((previous) => ({ ...previous, page: lastPage }));
|
||||
return;
|
||||
}
|
||||
setResult(data);
|
||||
setSelectedRowKeys((previous) =>
|
||||
previous.filter((id) => data.items.some((item) => item.id === id)),
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (active) {
|
||||
if (!signal.aborted) {
|
||||
setError(error.message || '预约信息加载失败,请重新查询');
|
||||
setResult({ items: [], total: 0 });
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (active) setLoading(false);
|
||||
if (!signal.aborted && !changedPage) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
return () => controller.abort();
|
||||
}, [query]);
|
||||
|
||||
const columns = useMemo(
|
||||
const fieldColumns = useMemo(
|
||||
() =>
|
||||
[
|
||||
['name', '姓名', 100],
|
||||
['contact', '联系方式', 210],
|
||||
['companyName', '公司名称', 180],
|
||||
['position', '职位', 140],
|
||||
['industry', '行业', 160],
|
||||
['interest', '关注方向', 190],
|
||||
['requirement', '需求', 360],
|
||||
].map(([dataIndex, title, width]) => ({
|
||||
RESERVATION_FIELDS.map(([dataIndex, title, width]) => ({
|
||||
title: t(title),
|
||||
dataIndex,
|
||||
key: dataIndex,
|
||||
...(compactMode ? {} : { width }),
|
||||
width,
|
||||
render: (value) =>
|
||||
dataIndex === 'requirement' && value ? (
|
||||
<div>
|
||||
@@ -89,12 +122,97 @@ export default function DemoReservations() {
|
||||
</span>
|
||||
),
|
||||
})),
|
||||
[t, compactMode],
|
||||
[t],
|
||||
);
|
||||
|
||||
const saveReservation = async (id, save) => {
|
||||
if (busy) return;
|
||||
setSavingId(id);
|
||||
try {
|
||||
await save();
|
||||
setLoading(true);
|
||||
setQuery((previous) => ({ ...previous }));
|
||||
} catch (error) {
|
||||
showError(t(error.message || '操作失败'));
|
||||
} finally {
|
||||
setSavingId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const columns = [
|
||||
...fieldColumns,
|
||||
{
|
||||
title: t('状态'),
|
||||
key: 'enabled',
|
||||
width: 88,
|
||||
align: 'center',
|
||||
render: (_, record) => (
|
||||
<Switch
|
||||
aria-label={t('状态')}
|
||||
checked={record.enabled !== false}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
disabled={busy}
|
||||
onChange={(enabled) =>
|
||||
saveReservation(record.id, () =>
|
||||
setDemoReservationEnabled(record.id, enabled),
|
||||
)
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
key: 'actions',
|
||||
width: 84,
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Popconfirm
|
||||
title={t('确认删除')}
|
||||
okText={t('删除')}
|
||||
cancelText={t('取消')}
|
||||
okButtonProps={{ danger: true }}
|
||||
disabled={busy}
|
||||
onConfirm={() =>
|
||||
saveReservation(record.id, () => deleteDemoReservation(record.id))
|
||||
}
|
||||
>
|
||||
<AntButton type='link' size='small' danger disabled={busy}>
|
||||
{t('删除')}
|
||||
</AntButton>
|
||||
</Popconfirm>
|
||||
),
|
||||
},
|
||||
].map((column) => ({
|
||||
...column,
|
||||
onHeaderCell: () => ({ style: { textAlign: 'center' } }),
|
||||
}));
|
||||
|
||||
const selectedRows = result.items.filter(({ id }) =>
|
||||
selectedRowKeys.includes(id),
|
||||
);
|
||||
const exportSelectedRows = () => {
|
||||
exportToCsv(
|
||||
[
|
||||
...RESERVATION_FIELDS.map(([key, title]) => ({
|
||||
key,
|
||||
title: t(title),
|
||||
format: (row) => reservationCsvValue(row[key]),
|
||||
})),
|
||||
{
|
||||
key: 'enabled',
|
||||
title: t('状态'),
|
||||
format: (row) => t(row.enabled === false ? '禁用' : '启用'),
|
||||
},
|
||||
],
|
||||
selectedRows,
|
||||
'demo-reservations.csv',
|
||||
);
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
formRef.current?.reset();
|
||||
setQuery((previous) => ({
|
||||
changeQuery((previous) => ({
|
||||
...EMPTY_FILTERS,
|
||||
page: 1,
|
||||
pageSize: previous.pageSize,
|
||||
@@ -102,12 +220,12 @@ export default function DemoReservations() {
|
||||
};
|
||||
|
||||
const changePageSize = (pageSize) =>
|
||||
setQuery((previous) => ({ ...previous, page: 1, pageSize }));
|
||||
changeQuery((previous) => ({ ...previous, page: 1, pageSize }));
|
||||
const pagination = createCardProPagination({
|
||||
currentPage: result.page ?? query.page,
|
||||
pageSize: result.page_size ?? query.pageSize,
|
||||
total: result.total,
|
||||
onPageChange: (page) => setQuery((previous) => ({ ...previous, page })),
|
||||
onPageChange: (page) => changeQuery((previous) => ({ ...previous, page })),
|
||||
onPageSizeChange: changePageSize,
|
||||
preventPageChangeOnPageSizeChange: true,
|
||||
isMobile,
|
||||
@@ -127,11 +245,12 @@ export default function DemoReservations() {
|
||||
type='type1'
|
||||
t={t}
|
||||
tableActions={
|
||||
<CompactModeToggle
|
||||
compactMode={compactMode}
|
||||
setCompactMode={setCompactMode}
|
||||
t={t}
|
||||
/>
|
||||
<AntButton
|
||||
disabled={busy || selectedRows.length === 0}
|
||||
onClick={exportSelectedRows}
|
||||
>
|
||||
{t('导出 CSV')}
|
||||
</AntButton>
|
||||
}
|
||||
searchArea={
|
||||
<div className='flex w-full justify-start'>
|
||||
@@ -139,7 +258,7 @@ export default function DemoReservations() {
|
||||
initValues={EMPTY_FILTERS}
|
||||
getFormApi={(api) => (formRef.current = api)}
|
||||
onSubmit={(values) =>
|
||||
setQuery((previous) => ({
|
||||
changeQuery((previous) => ({
|
||||
name: (values.name || '').trim(),
|
||||
contact: (values.contact || '').trim(),
|
||||
companyName: (values.companyName || '').trim(),
|
||||
@@ -191,7 +310,15 @@ export default function DemoReservations() {
|
||||
rowKey='id'
|
||||
columns={columns}
|
||||
dataSource={result.items}
|
||||
scroll={compactMode ? undefined : { x: 'max-content' }}
|
||||
rowSelection={{
|
||||
columnWidth: 44,
|
||||
fixed: true,
|
||||
selectedRowKeys,
|
||||
onChange: setSelectedRowKeys,
|
||||
getCheckboxProps: () => ({ disabled: busy }),
|
||||
}}
|
||||
tableLayout='fixed'
|
||||
scroll={{ x: RESERVATION_TABLE_MIN_WIDTH }}
|
||||
hidePagination
|
||||
className='overflow-hidden'
|
||||
size='middle'
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
import { requestWebsite } from '../../helpers/websiteApi';
|
||||
|
||||
export async function fetchDemoReservations({
|
||||
name = '',
|
||||
contact = '',
|
||||
companyName = '',
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
} = {}) {
|
||||
const params = new URLSearchParams({
|
||||
export async function fetchDemoReservations(
|
||||
{ name = '', contact = '', companyName = '', page = 1, pageSize = 10 } = {},
|
||||
{ signal } = {},
|
||||
) {
|
||||
const params = {
|
||||
name: name.trim(),
|
||||
contact: contact.trim(),
|
||||
companyName: companyName.trim(),
|
||||
p: String(page),
|
||||
page_size: String(pageSize),
|
||||
});
|
||||
p: page,
|
||||
page_size: pageSize,
|
||||
};
|
||||
const data = await requestWebsite(
|
||||
'get',
|
||||
`/api/website/demo-requests?${params}`,
|
||||
'/api/website/demo-requests',
|
||||
undefined,
|
||||
'预约信息加载失败,请重新查询',
|
||||
{ params, signal },
|
||||
);
|
||||
if (
|
||||
!data ||
|
||||
@@ -33,3 +31,13 @@ export async function fetchDemoReservations({
|
||||
throw new Error('预约列表响应格式不正确,请联系管理员检查');
|
||||
return data;
|
||||
}
|
||||
|
||||
export function setDemoReservationEnabled(id, enabled) {
|
||||
return requestWebsite('put', `/api/website/demo-requests/${id}/status`, {
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteDemoReservation(id) {
|
||||
return requestWebsite('delete', `/api/website/demo-requests/${id}`);
|
||||
}
|
||||
|
||||
@@ -47,14 +47,13 @@ test('uses backend pagination and preserves all business fields and line breaks'
|
||||
await api.fetchDemoReservations({ page: 2, pageSize: 20 }),
|
||||
data,
|
||||
);
|
||||
const [method, path] = api.requests[0];
|
||||
const [method, path, , , { params }] = api.requests[0];
|
||||
assert.equal(method, 'get');
|
||||
const url = new URL(path, 'https://example.com');
|
||||
assert.equal(url.pathname, '/api/website/demo-requests');
|
||||
assert.equal(url.searchParams.get('p'), '2');
|
||||
assert.equal(url.searchParams.get('page_size'), '20');
|
||||
assert.equal(url.searchParams.has('pageNum'), false);
|
||||
assert.equal(url.searchParams.has('pageSize'), false);
|
||||
assert.equal(path, '/api/website/demo-requests');
|
||||
assert.equal(params.p, 2);
|
||||
assert.equal(params.page_size, 20);
|
||||
assert.equal('pageNum' in params, false);
|
||||
assert.equal('pageSize' in params, false);
|
||||
});
|
||||
|
||||
test('encodes three trimmed fuzzy AND filters without losing literal plus and wildcard characters', async () => {
|
||||
@@ -64,13 +63,14 @@ test('encodes three trimmed fuzzy AND filters without losing literal plus and wi
|
||||
contact: ' +86 138%_!& ',
|
||||
companyName: ' 测试科技 ',
|
||||
});
|
||||
const params = new URL(api.requests[0][1], 'https://example.com')
|
||||
.searchParams;
|
||||
assert.equal(params.get('name'), '张');
|
||||
assert.equal(params.get('contact'), '+86 138%_!&');
|
||||
assert.equal(params.get('companyName'), '测试科技');
|
||||
assert.equal(params.get('p'), '1');
|
||||
assert.equal(params.get('page_size'), '10');
|
||||
const { params } = api.requests[0][4];
|
||||
assert.deepEqual(params, {
|
||||
name: '张',
|
||||
contact: '+86 138%_!&',
|
||||
companyName: '测试科技',
|
||||
p: 1,
|
||||
page_size: 10,
|
||||
});
|
||||
});
|
||||
|
||||
test('returns empty matches and out-of-range pages with the actual backend total', async () => {
|
||||
@@ -95,3 +95,27 @@ test('fails visibly on malformed responses or backend errors', async () => {
|
||||
const api = await harness(new Error('没有平台管理员权限'));
|
||||
await assert.rejects(api.fetchDemoReservations(), /没有平台管理员权限/);
|
||||
});
|
||||
|
||||
test('sends status and delete mutations through the website API', async () => {
|
||||
const api = await harness(null);
|
||||
await api.setDemoReservationEnabled(4, false);
|
||||
await api.deleteDemoReservation(4);
|
||||
assert.deepEqual(api.requests[0].slice(0, 3), [
|
||||
'put',
|
||||
'/api/website/demo-requests/4/status',
|
||||
{ enabled: false },
|
||||
]);
|
||||
assert.deepEqual(api.requests[1].slice(0, 2), [
|
||||
'delete',
|
||||
'/api/website/demo-requests/4',
|
||||
]);
|
||||
});
|
||||
|
||||
test('passes an abort signal to the list request so refreshes bypass pending GETs', async () => {
|
||||
const api = await harness(response());
|
||||
const { signal } = new AbortController();
|
||||
await api.fetchDemoReservations({ page: 2 }, { signal });
|
||||
const options = api.requests[0][4];
|
||||
assert.equal(options.signal, signal);
|
||||
assert.equal(options.params.p, 2);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
|
||||
const source = readFileSync(
|
||||
new URL('../../src/hooks/video/useVideoGeneration.js', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
test('a refresh uses a new list request when the same page GET is pending', async () => {
|
||||
const start = source.indexOf(' const loadTasks = useCallback(');
|
||||
const end = source.indexOf(' const pollOnce =', start);
|
||||
assert.ok(start >= 0 && end > start);
|
||||
const loadTasksSource = source.slice(start, end);
|
||||
const ref = (current) => ({ current });
|
||||
const noop = () => {};
|
||||
const issued = [];
|
||||
let pending;
|
||||
let visible;
|
||||
const api = {
|
||||
get(url, options) {
|
||||
assert.equal(url, '/api/video/tasks');
|
||||
if (pending && !options.disableDuplicate) return pending;
|
||||
let resolve;
|
||||
const promise = new Promise((finish) => {
|
||||
resolve = finish;
|
||||
});
|
||||
pending = promise;
|
||||
issued.push({ options, resolve });
|
||||
return promise;
|
||||
},
|
||||
};
|
||||
const createLoader = new Function(
|
||||
'API',
|
||||
'useCallback',
|
||||
'taskQueryRef',
|
||||
'taskRequestRef',
|
||||
'mountedRef',
|
||||
'setTaskPage',
|
||||
'setTaskPageSize',
|
||||
'setTasksLoading',
|
||||
'setTasks',
|
||||
'setTaskTotal',
|
||||
'trackTasks',
|
||||
'ACTIVE_STATUSES',
|
||||
'normalizeVideoTaskStatus',
|
||||
loadTasksSource + '\nreturn loadTasks;',
|
||||
);
|
||||
const load = createLoader(
|
||||
api,
|
||||
(fn) => fn,
|
||||
ref({ page: 2, pageSize: 10 }),
|
||||
ref(0),
|
||||
ref(true),
|
||||
noop,
|
||||
noop,
|
||||
noop,
|
||||
(value) => {
|
||||
visible = value;
|
||||
},
|
||||
noop,
|
||||
noop,
|
||||
new Set(),
|
||||
(status) => status,
|
||||
);
|
||||
|
||||
const earlier = load();
|
||||
const afterWrite = load();
|
||||
assert.equal(issued.length, 2);
|
||||
assert.deepEqual(issued[1].options.params, { p: 2, page_size: 10 });
|
||||
|
||||
const response = (id) => ({
|
||||
data: { success: true, data: { items: [{ task_id: id }], total: 12 } },
|
||||
});
|
||||
issued[1].resolve(response('remaining'));
|
||||
await afterWrite;
|
||||
issued[0].resolve(response('deleted'));
|
||||
await earlier;
|
||||
assert.deepEqual(visible, [{ task_id: 'remaining' }]);
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import React from 'react';
|
||||
import * as Ant from 'antd';
|
||||
import { loadFrontendModule } from './helpers/loadFrontendModule.js';
|
||||
import { loadFrontendModule } from '../test/unit/helpers/frontendModule.js';
|
||||
import { toConsoleTableChange } from '../src/components/console/consoleTableAdapter.js';
|
||||
import {
|
||||
consoleMenuPaths,
|
||||
|
||||
+1
-2
@@ -41,9 +41,8 @@ function jsxInJsPlugin() {
|
||||
function disableDevImportGlob() {
|
||||
return {
|
||||
name: 'disable-dev-import-glob',
|
||||
apply: 'serve',
|
||||
apply: (_, { command, isPreview }) => command === 'serve' && !isPreview,
|
||||
configResolved(config) {
|
||||
if (config.isPreview) return;
|
||||
const plugin = config.plugins.find(
|
||||
({ name }) => name === 'vite:import-glob',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user