Skip to content

Commit

Permalink
fix: 修复替换数据集筛选器丢失 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei authored Sep 18, 2023
1 parent 78470d6 commit 2cd8984
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
31 changes: 22 additions & 9 deletions packages/li-editor/src/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDatasetColumns } from '@antv/li-sdk';
import { useAsyncEffect } from 'ahooks';
import { ConfigProvider, Spin } from 'antd';
import { ConfigProvider, notification, Spin } from 'antd';
import classNames from 'classnames';
import React, { useState } from 'react';
import { useEditorService, useEditorState } from '../hooks';
Expand All @@ -22,6 +22,7 @@ export const DefaultTheme = {

const Layout: React.FC<LayoutProps> = (props) => {
const { className, style, defaultApplication, App } = props;
const [notificationApi, contextHolder] = notification.useNotification();
const { state, updateState } = useEditorState();
const { appService } = useEditorService();
const { datasets, serviceCache } = state;
Expand All @@ -30,16 +31,20 @@ const Layout: React.FC<LayoutProps> = (props) => {

useAsyncEffect(async () => {
const newServiceCache: EditorServiceCache = {};
const requestList: { datasetId: string; promise: Promise<Record<string, any>[]> }[] = [];
const requestList: { datasetId: string; datasetName: string; promise: Promise<Record<string, any>[]> }[] = [];
datasets.forEach((dataset) => {
const datasetId = dataset.id;
const {
id: datasetId,
metadata: { name: datasetName },
} = dataset;
if (dataset.type === 'remote') {
if (serviceCache[datasetId]) {
newServiceCache[datasetId] = serviceCache[datasetId];
} else {
const service = appService.getImplementService(dataset.serviceType);
if (service) {
requestList.push({
datasetName,
datasetId,
promise: service.service({
properties: dataset.properties,
Expand All @@ -54,12 +59,19 @@ const Layout: React.FC<LayoutProps> = (props) => {
setDataLoading(true);

await Promise.all(
requestList.map(async ({ datasetId, promise }) => {
const data = await promise;
newServiceCache[datasetId] = {
data: data ?? [],
columns: data?.length ? getDatasetColumns(data[0]) : [],
};
requestList.map(async ({ datasetId, datasetName, promise }) => {
try {
const data = await promise;
newServiceCache[datasetId] = {
data: data ?? [],
columns: data?.length ? getDatasetColumns(data[0]) : [],
};
} catch (error: any) {
notificationApi.error({
message: `数据集"${datasetName}"请求失败`,
description: error?.message || error,
});
}
}),
).finally(() => {
setDataLoading(false);
Expand All @@ -76,6 +88,7 @@ const Layout: React.FC<LayoutProps> = (props) => {
return (
<div className={classNames('li-editor', 'li-editor-layout', className)} style={style}>
<ConfigProvider theme={DefaultTheme}>
{contextHolder}
{dataLoading && (
<div className="li-editor-layout__loading">
<Spin />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const ReplaceDataset = ({ datasetId, visible, onClose }: ReplaceDatasetProps) =>
const index = draft.datasets.findIndex((item) => item.id === datasetId);
if (index !== -1) {
const replaceDataset = getAddDatasetSchema(dataset, datasetId);
draft.datasets[index] = replaceDataset;
// 复写 filter 情况
draft.datasets[index] = { ...draft.datasets[index], ...replaceDataset };
}
});
};
Expand Down
7 changes: 2 additions & 5 deletions packages/li-p2/src/components/Filter/FilterList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export const FilterList = ({

const onFilterFieldChange = (val: FilterNode, id: string) => {
setFilterFields((pre) => {
const index = pre.findIndex((item) => item.id === id);
if (index !== -1) {
pre[index] = val;
}
return pre.slice();
const list = pre.map((item) => (item.id === id ? val : item));
return list;
});
if (isEmpty(val.field)) return;

Expand Down

0 comments on commit 2cd8984

Please sign in to comment.