mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat: error message will be appear when tag edit empty, resolved #13
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
import React, { CSSProperties, useState, useEffect } from 'react';
|
import React, { CSSProperties, useState, useEffect } from 'react';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { Input, Option, Select, Tooltip } from '@toeverything/components/ui';
|
import {
|
||||||
|
Input,
|
||||||
|
Option,
|
||||||
|
Select,
|
||||||
|
Tooltip,
|
||||||
|
message,
|
||||||
|
} from '@toeverything/components/ui';
|
||||||
import { HelpCenterIcon } from '@toeverything/components/icons';
|
import { HelpCenterIcon } from '@toeverything/components/icons';
|
||||||
import { AsyncBlock } from '../../editor';
|
import { AsyncBlock } from '../../editor';
|
||||||
|
|
||||||
@@ -23,6 +29,7 @@ import {
|
|||||||
useSelectProperty,
|
useSelectProperty,
|
||||||
} from '../../recast-block';
|
} from '../../recast-block';
|
||||||
import {
|
import {
|
||||||
|
checkPendantForm,
|
||||||
genInitialOptions,
|
genInitialOptions,
|
||||||
getOfficialSelected,
|
getOfficialSelected,
|
||||||
getPendantConfigByType,
|
getPendantConfigByType,
|
||||||
@@ -112,7 +119,15 @@ export const CreatePendantPanel = ({
|
|||||||
iconConfig={getPendantConfigByType(selectedOption.type)}
|
iconConfig={getPendantConfigByType(selectedOption.type)}
|
||||||
// isStatusSelect={selectedOption.name === 'Status'}
|
// isStatusSelect={selectedOption.name === 'Status'}
|
||||||
onSure={async (type, newPropertyItem, newValue) => {
|
onSure={async (type, newPropertyItem, newValue) => {
|
||||||
if (!fieldName) {
|
const checkResult = checkPendantForm(
|
||||||
|
type,
|
||||||
|
fieldName,
|
||||||
|
newPropertyItem,
|
||||||
|
newValue
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!checkResult.passed) {
|
||||||
|
await message.error(checkResult.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,11 @@ import { OptionType, PendantTypes, TempInformationType } from '../types';
|
|||||||
import {
|
import {
|
||||||
getOfficialSelected,
|
getOfficialSelected,
|
||||||
getPendantConfigByType,
|
getPendantConfigByType,
|
||||||
// getPendantIconsConfigByNameOrType,
|
checkPendantForm,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
import { usePendant } from '../use-pendant';
|
import { usePendant } from '../use-pendant';
|
||||||
import {
|
import {
|
||||||
StyledPopoverWrapper,
|
StyledPopoverWrapper,
|
||||||
StyledOperationTitle,
|
|
||||||
StyledOperationLabel,
|
StyledOperationLabel,
|
||||||
StyledInputEndAdornment,
|
StyledInputEndAdornment,
|
||||||
StyledDivider,
|
StyledDivider,
|
||||||
@@ -29,7 +28,7 @@ import {
|
|||||||
StyledPopoverSubTitle,
|
StyledPopoverSubTitle,
|
||||||
} from '../StyledComponent';
|
} from '../StyledComponent';
|
||||||
import { IconMap, pendantOptions } from '../config';
|
import { IconMap, pendantOptions } from '../config';
|
||||||
import { Input, Tooltip } from '@toeverything/components/ui';
|
import { Input, message, Tooltip } from '@toeverything/components/ui';
|
||||||
import { HelpCenterIcon } from '@toeverything/components/icons';
|
import { HelpCenterIcon } from '@toeverything/components/icons';
|
||||||
|
|
||||||
type SelectPropertyType = MultiSelectProperty | SelectProperty;
|
type SelectPropertyType = MultiSelectProperty | SelectProperty;
|
||||||
@@ -111,6 +110,18 @@ export const UpdatePendantPanel = ({
|
|||||||
property={property}
|
property={property}
|
||||||
type={property.type}
|
type={property.type}
|
||||||
onSure={async (type, newPropertyItem, newValue) => {
|
onSure={async (type, newPropertyItem, newValue) => {
|
||||||
|
const checkResult = checkPendantForm(
|
||||||
|
type,
|
||||||
|
fieldTitle,
|
||||||
|
newPropertyItem,
|
||||||
|
newValue
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!checkResult.passed) {
|
||||||
|
await message.error(checkResult.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
type === PendantTypes.MultiSelect ||
|
type === PendantTypes.MultiSelect ||
|
||||||
type === PendantTypes.Select ||
|
type === PendantTypes.Select ||
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
PropertyType,
|
||||||
RecastBlockValue,
|
RecastBlockValue,
|
||||||
RecastPropertyId,
|
RecastPropertyId,
|
||||||
SelectOption,
|
SelectOption,
|
||||||
@@ -175,3 +176,49 @@ export const genInitialOptions = (
|
|||||||
}
|
}
|
||||||
return [genBasicOption({ index: 0, iconConfig })];
|
return [genBasicOption({ index: 0, iconConfig })];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const checkPendantForm = (
|
||||||
|
type: PropertyType,
|
||||||
|
fieldTitle: string,
|
||||||
|
newProperty: any,
|
||||||
|
newValue: any
|
||||||
|
): { passed: boolean; message: string } => {
|
||||||
|
if (!fieldTitle) {
|
||||||
|
return { passed: false, message: 'Please input field title !' };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
type === PendantTypes.MultiSelect ||
|
||||||
|
type === PendantTypes.Select ||
|
||||||
|
type === PendantTypes.Status
|
||||||
|
) {
|
||||||
|
if (!newProperty) {
|
||||||
|
return {
|
||||||
|
passed: false,
|
||||||
|
message: 'Ensure at least on non-empty option !',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type === PendantTypes.Information) {
|
||||||
|
if (!newProperty) {
|
||||||
|
return {
|
||||||
|
passed: false,
|
||||||
|
message: 'Ensure at least on non-empty option !',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
type === PendantTypes.Text ||
|
||||||
|
type === PendantTypes.Date ||
|
||||||
|
type === PendantTypes.Mention
|
||||||
|
) {
|
||||||
|
if (!newValue) {
|
||||||
|
return {
|
||||||
|
passed: false,
|
||||||
|
message: `Please input content !`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { passed: true, message: 'Check passed !' };
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user