fix: apikey form value diff
This commit is contained in:
@@ -54,6 +54,11 @@ const AllowModelsForm: React.FC<{
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleAllowTypeChange = (e: any) => {
|
||||||
|
const value = e.target.value;
|
||||||
|
onValuesChange?.({ allowed_type: value }, form.getFieldsValue());
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getModelList();
|
getModelList();
|
||||||
}, [action, currentData]);
|
}, [action, currentData]);
|
||||||
@@ -68,6 +73,7 @@ const AllowModelsForm: React.FC<{
|
|||||||
style={{ marginBottom: 8 }}
|
style={{ marginBottom: 8 }}
|
||||||
>
|
>
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
|
onChange={handleAllowTypeChange}
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
label: intl.formatMessage({ id: 'apikeys.models.all' }),
|
label: intl.formatMessage({ id: 'apikeys.models.all' }),
|
||||||
|
|||||||
@@ -134,14 +134,24 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
setShowKey(false);
|
setShowKey(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const customEqual = (objValue: any, othValue: any) => {
|
||||||
|
if (_.isArray(objValue) && _.isArray(othValue)) {
|
||||||
|
return _.isEmpty(_.xor(objValue, othValue));
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
||||||
const initialValues = cacheFormRef.current;
|
const initialValues = cacheFormRef.current;
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
setTimeout(resolve, 100);
|
setTimeout(resolve, 100);
|
||||||
});
|
});
|
||||||
console.log('initialValues', initialValues, allValues);
|
|
||||||
if (
|
if (
|
||||||
_.isEqual(initialValues, _.pick(allValues, Object.keys(initialValues)))
|
_.isEqualWith(
|
||||||
|
initialValues,
|
||||||
|
_.pick(allValues, Object.keys(initialValues)),
|
||||||
|
customEqual
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
setIsChanged(false);
|
setIsChanged(false);
|
||||||
} else {
|
} else {
|
||||||
@@ -259,7 +269,6 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
name="addAPIKey"
|
name="addAPIKey"
|
||||||
form={form}
|
form={form}
|
||||||
onFinish={handleOnOk}
|
onFinish={handleOnOk}
|
||||||
onValuesChange={handleOnValuesChange}
|
|
||||||
preserve={false}
|
preserve={false}
|
||||||
>
|
>
|
||||||
{!showKey && (
|
{!showKey && (
|
||||||
|
|||||||
@@ -40,10 +40,18 @@ const AccessControlModal: React.FC<
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const customEqual = (objValue: any, othValue: any) => {
|
||||||
|
if (_.isArray(objValue) && _.isArray(othValue)) {
|
||||||
|
const objIds = objValue.map((item: any) => item.id).sort();
|
||||||
|
const othIds = othValue.map((item: any) => item.id).sort();
|
||||||
|
return _.isEqual(objIds, othIds);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
const handleOnValuesChange = async (changedValues: any, allValues: any) => {
|
||||||
console.log('changedValues', changedValues, allValues);
|
|
||||||
const initialValues = formCacheRef.current;
|
const initialValues = formCacheRef.current;
|
||||||
if (_.isEqual(initialValues, allValues)) {
|
if (_.isEqualWith(initialValues, allValues, customEqual)) {
|
||||||
setIsChanged(false);
|
setIsChanged(false);
|
||||||
} else {
|
} else {
|
||||||
setIsChanged(true);
|
setIsChanged(true);
|
||||||
@@ -77,6 +85,7 @@ const AccessControlModal: React.FC<
|
|||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
keyboard={false}
|
keyboard={false}
|
||||||
width={700}
|
width={700}
|
||||||
|
height={660}
|
||||||
footer={
|
footer={
|
||||||
<>
|
<>
|
||||||
{isChanged && (
|
{isChanged && (
|
||||||
|
|||||||
Reference in New Issue
Block a user