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

fix: onOK关闭逻辑优化.issue #578 #587

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion frontend/src/app/hooks/useStateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import { Form, Modal } from 'antd';
import { useRef } from 'react';
import { isPromise } from 'utils/object';

export interface IStateModalContentProps {
onChange: (o: any) => void;
Expand Down Expand Up @@ -57,7 +58,11 @@ function useStateModal({ initState }: { initState?: any }) {
Object.keys(stateRef.current || {}).length > 0
? stateRef.current
: [];
okCallbackRef.current?.call(Object.create(null), ...spreadParmas);
const okCBResult = okCallbackRef.current?.call(
Object.create(null),
...spreadParmas,
);
if (isPromise(okCBResult)) return okCBResult;
} catch (e) {
console.error('useStateModal | exception message ---> ', e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const ChartDataViewPanel: FC<{
originId?: string,
) => {
if (!field) {
return;
return Promise.reject('field is empty');
}

let validComputedField = true;
Expand All @@ -85,7 +85,7 @@ const ChartDataViewPanel: FC<{

if (!validComputedField) {
message.error('validate function computed field failed');
return;
return Promise.reject('validate function computed field failed');
}
const otherComputedFields = dataView?.computedFields?.filter(
f => f.id !== originId,
Expand All @@ -95,7 +95,9 @@ const ChartDataViewPanel: FC<{
message.error(
'The computed field has already been exist, please choose anohter one!',
);
return;
return Promise.reject(
'The computed field has already been exist, please choose anohter one!',
);
}

const currentFieldIndex = (dataView?.computedFields || []).findIndex(
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/utils/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,14 @@ export function isEmptyArray(value?) {

return Array.isArray(value) && !value?.length;
}

export function isPromise(obj?) {
if (isEmpty(obj)) {
return false;
}

return (
(typeof obj === 'object' || typeof obj === 'function') &&
typeof obj.then === 'function'
);
}