From a881556ad320b11c799590f2b08a3909b9b01051 Mon Sep 17 00:00:00 2001 From: qishaoxuan Date: Tue, 26 Jul 2022 18:53:28 +0800 Subject: [PATCH] chore: optimisation code --- .../PendantHistoryPanel.tsx | 51 +++++++------------ .../CreatePendantPanel.tsx | 14 ++--- .../pendant-render/PandentRender.tsx | 7 +-- 3 files changed, 24 insertions(+), 48 deletions(-) diff --git a/libs/components/editor-core/src/block-pendant/pendant-history-panel/PendantHistoryPanel.tsx b/libs/components/editor-core/src/block-pendant/pendant-history-panel/PendantHistoryPanel.tsx index 3ed9a0e244..f0e188d9a3 100644 --- a/libs/components/editor-core/src/block-pendant/pendant-history-panel/PendantHistoryPanel.tsx +++ b/libs/components/editor-core/src/block-pendant/pendant-history-panel/PendantHistoryPanel.tsx @@ -1,11 +1,10 @@ -import React, { ReactNode, useRef, useState } from 'react'; +import React, { ReactNode, useRef } from 'react'; import { getLatestPropertyValue } from '../utils'; import { getRecastItemValue, RecastMetaProperty, useRecastBlock, useRecastBlockMeta, - RecastBlockValue, } from '../../recast-block'; import { AsyncBlock } from '../../editor'; import { Popover, PopperHandler, styled } from '@toeverything/components/ui'; @@ -19,10 +18,6 @@ export const PendantHistoryPanel = ({ block: AsyncBlock; endElement?: ReactNode; }) => { - const [propertyWithValue, setPropertyWithValue] = useState<{ - value: RecastBlockValue; - property: RecastMetaProperty; - }>(); const popoverHandlerRef = useRef<{ [key: string]: PopperHandler }>({}); const { getProperty } = useRecastBlockMeta(); @@ -53,25 +48,23 @@ export const PendantHistoryPanel = ({ }} placement="bottom-start" content={ - propertyWithValue && ( - { - popoverHandlerRef.current[ - item.id - ].setVisible(false); - }} - onCancel={() => { - popoverHandlerRef.current[ - item.id - ].setVisible(false); - }} - titleEditable={false} - /> - ) + { + popoverHandlerRef.current[ + item.id + ].setVisible(false); + }} + onCancel={() => { + popoverHandlerRef.current[ + item.id + ].setVisible(false); + }} + titleEditable={false} + /> } trigger="click" > @@ -84,14 +77,6 @@ export const PendantHistoryPanel = ({ }} property={property as RecastMetaProperty} value={item} - onClick={e => { - if (property) { - setPropertyWithValue({ - property, - value: item, - }); - } - }} /> ); diff --git a/libs/components/editor-core/src/block-pendant/pendant-operation-panel/CreatePendantPanel.tsx b/libs/components/editor-core/src/block-pendant/pendant-operation-panel/CreatePendantPanel.tsx index ca198b67bb..cc230b226a 100644 --- a/libs/components/editor-core/src/block-pendant/pendant-operation-panel/CreatePendantPanel.tsx +++ b/libs/components/editor-core/src/block-pendant/pendant-operation-panel/CreatePendantPanel.tsx @@ -3,7 +3,7 @@ import { Input, Option, Select, Tooltip } from '@toeverything/components/ui'; import { HelpCenterIcon } from '@toeverything/components/icons'; import { AsyncBlock } from '../../editor'; -import { pendantOptions, IconMap } from '../config'; +import { IconMap, pendantOptions } from '../config'; import { OptionType, PendantOptions, PendantTypes } from '../types'; import { PendantModifyPanel } from '../pendant-modify-panel'; import { @@ -15,12 +15,11 @@ import { StyledPopoverWrapper, } from '../StyledComponent'; import { - PropertyType, + genSelectOptionId, + InformationProperty, useRecastBlock, useRecastBlockMeta, useSelectProperty, - genSelectOptionId, - InformationProperty, } from '../../recast-block'; import { genInitialOptions, @@ -103,9 +102,7 @@ export const CreatePendantPanel = ({ selectedOption.type, getPendantConfigByType(selectedOption.type) )} - iconConfig={getPendantConfigByType( - selectedOption.type - )} + iconConfig={getPendantConfigByType(selectedOption.type)} // isStatusSelect={selectedOption.name === 'Status'} onSure={async (type, newPropertyItem, newValue) => { if (!fieldName) { @@ -177,8 +174,7 @@ export const CreatePendantPanel = ({ }); } else { // TODO: Color and background should use pendant config, but ui is not design now - const iconConfig = - getPendantConfigByType(type); + const iconConfig = getPendantConfigByType(type); // TODO: Color and background should be choose by user in the future const newProperty = await addProperty({ type: type, diff --git a/libs/components/editor-core/src/block-pendant/pendant-render/PandentRender.tsx b/libs/components/editor-core/src/block-pendant/pendant-render/PandentRender.tsx index b60b1ea872..371ea2048e 100644 --- a/libs/components/editor-core/src/block-pendant/pendant-render/PandentRender.tsx +++ b/libs/components/editor-core/src/block-pendant/pendant-render/PandentRender.tsx @@ -1,11 +1,6 @@ import React, { useRef, useState } from 'react'; import { AsyncBlock } from '../../editor'; -import { - getRecastItemValue, - RecastBlockValue, - RecastMetaProperty, - useRecastBlockMeta, -} from '../../recast-block'; +import { getRecastItemValue, useRecastBlockMeta } from '../../recast-block'; import { MuiZoom, Popover,