fix: api watch data
This commit is contained in:
@@ -11,6 +11,18 @@ export default function createProxyTable(target?: string) {
|
|||||||
secure: false,
|
secure: false,
|
||||||
ws: true,
|
ws: true,
|
||||||
pathRewrite: (pth: string) => pth.replace(`/^/${api}/`, `/${api}`),
|
pathRewrite: (pth: string) => pth.replace(`/^/${api}/`, `/${api}`),
|
||||||
|
// onProxyRes: (proxyRes: any, req: any, res: any) => {
|
||||||
|
// if (req.headers.accept === 'text/event-stream') {
|
||||||
|
// res.writeHead(res.statusCode, {
|
||||||
|
// 'Content-Type': 'text/event-stream',
|
||||||
|
// 'Cache-Control': 'no-transform',
|
||||||
|
// Connection: 'keep-alive',
|
||||||
|
// 'X-Accel-Buffering': 'no',
|
||||||
|
// 'Access-Control-Allow-Origin': '*'
|
||||||
|
// });
|
||||||
|
// proxyRes.pipe(res);
|
||||||
|
// }
|
||||||
|
// },
|
||||||
headers: {
|
headers: {
|
||||||
origin: newTarget,
|
origin: newTarget,
|
||||||
Connection: 'keep-alive'
|
Connection: 'keep-alive'
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ const SealTable: React.FC<SealTableProps> = (props) => {
|
|||||||
columnProps as SealColumnProps;
|
columnProps as SealColumnProps;
|
||||||
if (React.isValidElement(child)) {
|
if (React.isValidElement(child)) {
|
||||||
return (
|
return (
|
||||||
<Col span={span}>
|
<Col span={span} key={i}>
|
||||||
<TableHeader
|
<TableHeader
|
||||||
title={title}
|
title={title}
|
||||||
style={headerStyle}
|
style={headerStyle}
|
||||||
|
|||||||
@@ -125,11 +125,21 @@ const useSetChunkRequest = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const resetResultSchema = (result: any[]) => {
|
const resetResultSchema = (result: any[]) => {
|
||||||
|
// ============ handle list data ============
|
||||||
|
// return _.map(result, (data: any) => {
|
||||||
|
// if (data.type === WatchEventType.DELETE) {
|
||||||
|
// data.ids = _.map(data.items, (item: any) => item.id);
|
||||||
|
// }
|
||||||
|
// data.collection = data.items || [];
|
||||||
|
// return data;
|
||||||
|
// });
|
||||||
|
// ============ handle list data ============
|
||||||
|
|
||||||
return _.map(result, (data: any) => {
|
return _.map(result, (data: any) => {
|
||||||
if (data.type === WatchEventType.DELETE) {
|
if (data.type === WatchEventType.DELETE) {
|
||||||
data.ids = _.map(data.items, (item: any) => item.id);
|
data.ids = data.data?.id ? [data.data.id] : [];
|
||||||
}
|
}
|
||||||
data.collection = data.items || [];
|
data.collection = data.data ? [data.data] : [];
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ export default function useEventSource() {
|
|||||||
|
|
||||||
eventSourceRef.current.onmessage = (res: any) => {
|
eventSourceRef.current.onmessage = (res: any) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('event source message: ', { res, resData: res });
|
||||||
const data = JSON.parse(res.data);
|
const data = JSON.parse(res.data);
|
||||||
console.log('event source message: ', { data, resData: res });
|
|
||||||
onmessage(data);
|
onmessage(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// error
|
// error
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
interface ChunkedCollection {
|
interface ChunkedCollection {
|
||||||
ids: string[];
|
ids: string[];
|
||||||
|
data: any;
|
||||||
collection: any[];
|
collection: any[];
|
||||||
type: string;
|
type: string | number;
|
||||||
}
|
}
|
||||||
// Only used to update lists without nested state
|
// Only used to update lists without nested state
|
||||||
export function useUpdateChunkedList(
|
export function useUpdateChunkedList(
|
||||||
|
|||||||
@@ -372,19 +372,15 @@ const Models: React.FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData();
|
fetchData();
|
||||||
// createModelsDataByFetch();
|
setTimeout(() => {
|
||||||
createModelEvent();
|
createModelsChunkRequest();
|
||||||
createModelsChunkRequest();
|
}, 1000);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
chunkRequedtRef.current?.current?.cancel?.();
|
chunkRequedtRef.current?.current?.cancel?.();
|
||||||
};
|
};
|
||||||
}, [queryParams]);
|
}, [queryParams]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// watch models list
|
|
||||||
}, [queryParams]);
|
|
||||||
|
|
||||||
const renderChildren = (list: any) => {
|
const renderChildren = (list: any) => {
|
||||||
return (
|
return (
|
||||||
<Space size={16} direction="vertical" style={{ width: '100%' }}>
|
<Space size={16} direction="vertical" style={{ width: '100%' }}>
|
||||||
|
|||||||
@@ -75,3 +75,19 @@ export const readStreamData = async (
|
|||||||
// callback(chunk);
|
// callback(chunk);
|
||||||
await readStreamData(reader, decoder, callback);
|
await readStreamData(reader, decoder, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const readTextEventStreamData = async (
|
||||||
|
reader: any,
|
||||||
|
decoder: TextDecoder,
|
||||||
|
callback: (data: any) => void
|
||||||
|
) => {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let chunk = decoder.decode(value, { stream: true });
|
||||||
|
callback(chunk);
|
||||||
|
await readTextEventStreamData(reader, decoder, callback);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user