Skip to content

Commit

Permalink
fix: promise close modal after success
Browse files Browse the repository at this point in the history
  • Loading branch information
1pone committed Nov 7, 2024
1 parent f3a92a4 commit 085b8a0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type AddConfigModalProps<T> = {
dependency?: Rule[];
};
operationList?: OperationInterface<'Interface'>[];
onOk?: (form: FormInstance<CompareConfigForm<T>>) => void;
onOk?: (form: FormInstance<CompareConfigForm<T>>) => Promise<any>;
onClose?: () => void;
};

Expand All @@ -62,6 +62,7 @@ const AddConfigModal = forwardRef(

// reset dependency when operationId changed
useEffect(() => {
// @ts-ignore
form.setFieldValue('dependency', undefined);
}, [operationId]);

Expand Down Expand Up @@ -132,8 +133,15 @@ const AddConfigModal = forwardRef(

const [dependencyOptions, setDependencyOptions] = useState<SelectProps['options']>();

const handleOk = () =>
props.onOk?.(form).then(() => {
setOpenAddConfigModal(false);
form.resetFields();
});

const handleCloseModal = () => {
setOpenAddConfigModal(false);
form.resetFields();
props.onClose?.();
};

Expand All @@ -142,7 +150,7 @@ const AddConfigModal = forwardRef(
destroyOnClose
title={props.title}
open={openAddConfigModal}
onOk={() => props.onOk?.(form)}
onOk={handleOk}
onCancel={handleCloseModal}
>
<Form<CompareConfigForm<T>>
Expand Down Expand Up @@ -188,7 +196,9 @@ const AddConfigModal = forwardRef(
{(() =>
props.field?.(
props.appId,
// @ts-ignore
form.getFieldValue('operationId'),
// @ts-ignore
form.getFieldValue('dependency'),
))()}
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function SortPathKeyInput(props: SortPathKeyInputProps) {
{/* TODO select path from contract tree */}
<Input />
</Form.Item>

<Form.Item
name='keys'
label={t('components:appSetting.keys')}
Expand All @@ -60,16 +61,7 @@ export default function SortPathKeyInput(props: SortPathKeyInputProps) {
]}
>
{/* TODO select path from contract tree */}
<Select
allowClear
mode='multiple'
options={[
{
label: '/test/value',
value: '/test/value',
},
]}
/>
<Select allowClear mode='tags' options={[]} />
</Form.Item>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default function ListSort(props: ListSortProps) {
});
}

const handleAddListSort: AddConfigModalProps<ListSortPrivate>['onOk'] = (form) => {
const handleAddListSort: AddConfigModalProps<ListSortPrivate>['onOk'] = (form) =>
form
.validateFields()
.then((res) => {
Expand All @@ -233,7 +233,6 @@ export default function ListSort(props: ListSortProps) {
.catch((e) => {
console.error(e);
});
};

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DownOutlined } from '@ant-design/icons';
import { styled, TooltipButton, tryParseJsonString, useTranslation } from '@arextest/arex-core';
import { css, styled, TooltipButton, tryParseJsonString } from '@arextest/arex-core';
import { useRequest } from 'ahooks';
import { Button, Collapse, Form, Input, InputProps, Space, theme, Typography } from 'antd';
import { Collapse, Input, InputProps, Space, Typography } from 'antd';
import React, { useMemo, useState } from 'react';

import { ReportService } from '@/services';
Expand All @@ -25,8 +25,6 @@ export type ExclusionPathInputProps = Omit<InputProps, 'onChange'> & {
const IgnorePathInput = (props: ExclusionPathInputProps) => {
const { appId, operationId, dependency, ...inputProps } = props;

const { t } = useTranslation();

const [expand, setExpand] = useState(false);

const [selectedKeys, setSelectedKeys] = useState<React.Key[]>();
Expand All @@ -43,7 +41,7 @@ const IgnorePathInput = (props: ExclusionPathInputProps) => {
...dependency,
}),
{
ready: !!appId, // TODO && collapseExpand
ready: !!appId && expand,
refreshDeps: [appId, operationId, dependency],
onBefore() {
setContract();
Expand Down Expand Up @@ -79,11 +77,18 @@ const IgnorePathInput = (props: ExclusionPathInputProps) => {
<Collapse
ghost
activeKey={expand ? 'nodeTree' : undefined}
css={css`
.ant-collapse-header {
display: none !important;
}
.ant-collapse-content-box {
padding: 16px 0 0 !important;
}
`}
items={[
{
key: 'nodeTree',
showArrow: false,
// TODO styles no padding
children: (
<IgnoreTree
multiple={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default function NodeIgnore(props: NodeIgnoreProps) {
</div>
);

const handleAddIgnore: AddConfigModalProps<NodeIgnorePrivate>['onOk'] = (form) => {
const handleAddIgnore: AddConfigModalProps<NodeIgnorePrivate>['onOk'] = (form) =>
form
.validateFields()
.then((res) => {
Expand All @@ -222,7 +222,6 @@ export default function NodeIgnore(props: NodeIgnoreProps) {
.catch((e) => {
console.log(e);
});
};

return (
<div>
Expand Down

0 comments on commit 085b8a0

Please sign in to comment.