feat: support editing title when editing tag, resolved #538
This commit is contained in:
@@ -69,6 +69,7 @@ export const PendantHistoryPanel = ({
|
|||||||
item.id
|
item.id
|
||||||
].setVisible(false);
|
].setVisible(false);
|
||||||
}}
|
}}
|
||||||
|
titleEditable={false}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import { useState } from 'react';
|
||||||
import { PendantModifyPanel } from '../pendant-modify-panel';
|
import { PendantModifyPanel } from '../pendant-modify-panel';
|
||||||
import type { AsyncBlock } from '../../editor';
|
import type { AsyncBlock } from '../../editor';
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +29,8 @@ 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 { HelpCenterIcon } from '@toeverything/components/icons';
|
||||||
|
|
||||||
type SelectPropertyType = MultiSelectProperty | SelectProperty;
|
type SelectPropertyType = MultiSelectProperty | SelectProperty;
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ type Props = {
|
|||||||
hasDelete?: boolean;
|
hasDelete?: boolean;
|
||||||
onSure?: () => void;
|
onSure?: () => void;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
|
titleEditable?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UpdatePendantPanel = ({
|
export const UpdatePendantPanel = ({
|
||||||
@@ -48,6 +51,7 @@ export const UpdatePendantPanel = ({
|
|||||||
hasDelete = false,
|
hasDelete = false,
|
||||||
onSure,
|
onSure,
|
||||||
onCancel,
|
onCancel,
|
||||||
|
titleEditable = false,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { updateSelect } = useSelectProperty();
|
const { updateSelect } = useSelectProperty();
|
||||||
const { setPendant, removePendant } = usePendant(block);
|
const { setPendant, removePendant } = usePendant(block);
|
||||||
@@ -55,6 +59,7 @@ export const UpdatePendantPanel = ({
|
|||||||
const iconConfig = getPendantConfigByType(property.type);
|
const iconConfig = getPendantConfigByType(property.type);
|
||||||
const Icon = IconMap[iconConfig.iconName];
|
const Icon = IconMap[iconConfig.iconName];
|
||||||
const { updateProperty } = useRecastBlockMeta();
|
const { updateProperty } = useRecastBlockMeta();
|
||||||
|
const [fieldTitle, setFieldTitle] = useState(property.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledPopoverWrapper>
|
<StyledPopoverWrapper>
|
||||||
@@ -70,7 +75,25 @@ export const UpdatePendantPanel = ({
|
|||||||
{property.type}
|
{property.type}
|
||||||
</StyledPopoverContent>
|
</StyledPopoverContent>
|
||||||
<StyledOperationLabel>Field Title</StyledOperationLabel>
|
<StyledOperationLabel>Field Title</StyledOperationLabel>
|
||||||
<StyledPopoverContent>{property.name}</StyledPopoverContent>
|
{titleEditable ? (
|
||||||
|
<Input
|
||||||
|
value={fieldTitle}
|
||||||
|
placeholder="Input your field name here"
|
||||||
|
onChange={e => {
|
||||||
|
setFieldTitle(e.target.value);
|
||||||
|
}}
|
||||||
|
endAdornment={
|
||||||
|
<Tooltip content="Help info here">
|
||||||
|
<StyledInputEndAdornment>
|
||||||
|
<HelpCenterIcon />
|
||||||
|
</StyledInputEndAdornment>
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<StyledPopoverContent>{property.name}</StyledPopoverContent>
|
||||||
|
)}
|
||||||
|
|
||||||
<StyledDivider />
|
<StyledDivider />
|
||||||
{pendantOption.subTitle && (
|
{pendantOption.subTitle && (
|
||||||
<StyledPopoverSubTitle>
|
<StyledPopoverSubTitle>
|
||||||
@@ -190,6 +213,12 @@ export const UpdatePendantPanel = ({
|
|||||||
await setPendant(property, newValue);
|
await setPendant(property, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fieldTitle !== property.name) {
|
||||||
|
await updateProperty({
|
||||||
|
...property,
|
||||||
|
name: fieldTitle,
|
||||||
|
});
|
||||||
|
}
|
||||||
onSure?.();
|
onSure?.();
|
||||||
}}
|
}}
|
||||||
onDelete={
|
onDelete={
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, {useRef, useState} from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import {AsyncBlock} from '../../editor';
|
import { AsyncBlock } from '../../editor';
|
||||||
import {
|
import {
|
||||||
getRecastItemValue,
|
getRecastItemValue,
|
||||||
RecastBlockValue,
|
RecastBlockValue,
|
||||||
@@ -12,38 +12,22 @@ import {
|
|||||||
PopperHandler,
|
PopperHandler,
|
||||||
styled,
|
styled,
|
||||||
} from '@toeverything/components/ui';
|
} from '@toeverything/components/ui';
|
||||||
import {PendantTag} from '../PendantTag';
|
import { PendantTag } from '../PendantTag';
|
||||||
import {
|
import { UpdatePendantPanel } from '../pendant-operation-panel';
|
||||||
UpdatePendantPanel
|
import { AddPendantPopover } from '../AddPendantPopover';
|
||||||
} from '../pendant-operation-panel';
|
|
||||||
import {AddPendantPopover} from '../AddPendantPopover';
|
|
||||||
|
|
||||||
export const PendantRender = ({block}: { block: AsyncBlock }) => {
|
export const PendantRender = ({ block }: { block: AsyncBlock }) => {
|
||||||
const [propertyWithValue, setPropertyWithValue] = useState<{
|
|
||||||
value: RecastBlockValue;
|
|
||||||
property: RecastMetaProperty;
|
|
||||||
}>();
|
|
||||||
const popoverHandlerRef = useRef<{ [key: string]: PopperHandler }>({});
|
const popoverHandlerRef = useRef<{ [key: string]: PopperHandler }>({});
|
||||||
const blockRenderContainerRef = useRef<HTMLDivElement>(null);
|
const blockRenderContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const [showAddBtn, setShowAddBtn] = useState(false);
|
const [showAddBtn, setShowAddBtn] = useState(false);
|
||||||
|
|
||||||
const {getProperties} = useRecastBlockMeta();
|
const { getProperties } = useRecastBlockMeta();
|
||||||
|
|
||||||
const {
|
const { getValue, removeValue } = getRecastItemValue(block);
|
||||||
getValue,
|
|
||||||
removeValue
|
|
||||||
} = getRecastItemValue(block);
|
|
||||||
|
|
||||||
const properties = getProperties();
|
const properties = getProperties();
|
||||||
|
|
||||||
const propertyWithValues = properties
|
const hasAddBtn = properties.some(property => getValue(property.id));
|
||||||
.map(property => {
|
|
||||||
return {
|
|
||||||
value: getValue(property.id),
|
|
||||||
property,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.filter(v => v.value);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BlockPendantContainer
|
<BlockPendantContainer
|
||||||
@@ -55,13 +39,14 @@ export const PendantRender = ({block}: { block: AsyncBlock }) => {
|
|||||||
setShowAddBtn(false);
|
setShowAddBtn(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{propertyWithValues.map(pWithV => {
|
{properties.map(property => {
|
||||||
const {id, type} = pWithV.value;
|
const value = getValue(property.id);
|
||||||
|
|
||||||
/* (暂时关闭,HOOK中需要加入Scene的判断)Remove duplicate label(tag) */
|
if (!value) {
|
||||||
// if (groupBy?.id === id) {
|
return null;
|
||||||
// return null;
|
}
|
||||||
// }
|
|
||||||
|
const { id } = value;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
@@ -73,24 +58,23 @@ export const PendantRender = ({block}: { block: AsyncBlock }) => {
|
|||||||
trigger="click"
|
trigger="click"
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
content={
|
content={
|
||||||
propertyWithValue && (
|
<UpdatePendantPanel
|
||||||
<UpdatePendantPanel
|
block={block}
|
||||||
block={block}
|
value={value}
|
||||||
value={propertyWithValue.value}
|
property={property}
|
||||||
property={propertyWithValue.property}
|
hasDelete={false}
|
||||||
hasDelete={false}
|
onSure={() => {
|
||||||
onSure={() => {
|
popoverHandlerRef.current[id].setVisible(
|
||||||
popoverHandlerRef.current[
|
false
|
||||||
id
|
);
|
||||||
].setVisible(false);
|
}}
|
||||||
}}
|
onCancel={() => {
|
||||||
onCancel={() => {
|
popoverHandlerRef.current[id].setVisible(
|
||||||
popoverHandlerRef.current[
|
false
|
||||||
id
|
);
|
||||||
].setVisible(false);
|
}}
|
||||||
}}
|
titleEditable={true}
|
||||||
/>
|
/>
|
||||||
)
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<PendantTag
|
<PendantTag
|
||||||
@@ -99,25 +83,22 @@ export const PendantRender = ({block}: { block: AsyncBlock }) => {
|
|||||||
marginRight: 10,
|
marginRight: 10,
|
||||||
marginTop: 4,
|
marginTop: 4,
|
||||||
}}
|
}}
|
||||||
onClick={e => {
|
value={value}
|
||||||
setPropertyWithValue(pWithV);
|
property={property}
|
||||||
}}
|
|
||||||
value={pWithV.value}
|
|
||||||
property={pWithV.property}
|
|
||||||
closeable
|
closeable
|
||||||
onClose={async () => {
|
onClose={async () => {
|
||||||
await removeValue(pWithV.property.id);
|
await removeValue(property.id);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
{propertyWithValues.length ? (
|
{hasAddBtn ? (
|
||||||
<MuiZoom in={showAddBtn}>
|
<MuiZoom in={showAddBtn}>
|
||||||
<div>
|
<div>
|
||||||
<AddPendantPopover
|
<AddPendantPopover
|
||||||
block={block}
|
block={block}
|
||||||
iconStyle={{marginTop: 4}}
|
iconStyle={{ marginTop: 4 }}
|
||||||
container={blockRenderContainerRef.current}
|
container={blockRenderContainerRef.current}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user