Fix the design of the Variable chip (#9871)

- Use a React component for variable tags in tiptap
- Fix the design of the variable chip
- Always display a button to delete the chip

![CleanShot 2025-01-28 at 12 35
55@2x](https://github.com/user-attachments/assets/d78ffa52-fcc3-4bbc-b427-68edde255408)
This commit is contained in:
Baptiste Devessier
2025-01-28 14:59:45 +01:00
committed by GitHub
parent ac8c0c72cc
commit 1e9dce3fd5
12 changed files with 91 additions and 50 deletions

View File

@ -1,6 +1,6 @@
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordChip } from '@/object-record/components/RecordChip';
import { VariableChip } from '@/object-record/record-field/form-types/components/VariableChip';
import { VariableChipStandalone } from '@/object-record/record-field/form-types/components/VariableChipStandalone';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { isStandaloneVariableString } from '@/workflow/utils/isStandaloneVariableString';
import {
@ -48,7 +48,7 @@ export const WorkflowSingleRecordFieldChip = ({
isStandaloneVariableString(draftValue.value)
) {
return (
<VariableChip
<VariableChipStandalone
rawVariableName={objectMetadataItem.labelSingular}
onRemove={onRemove}
/>

View File

@ -0,0 +1,25 @@
import { VariableChip } from '@/object-record/record-field/form-types/components/VariableChip';
import styled from '@emotion/styled';
import { NodeViewProps, NodeViewWrapper } from '@tiptap/react';
const StyledWrapper = styled.span`
display: inline-block;
padding-inline: ${({ theme }) => theme.spacing(0.5)};
`;
type WorkflowTextEditorVariableChipProps = NodeViewProps;
export const WorkflowTextEditorVariableChip = ({
deleteNode,
node,
}: WorkflowTextEditorVariableChipProps) => {
const attrs = node.attrs as {
variable: string;
};
return (
<NodeViewWrapper as={StyledWrapper} style={{ whiteSpace: 'nowrap' }}>
<VariableChip rawVariableName={attrs.variable} onRemove={deleteNode} />
</NodeViewWrapper>
);
};

View File

@ -1,6 +1,7 @@
import { WorkflowTextEditorVariableChip } from '@/workflow/workflow-variables/components/WorkflowTextEditorVariableChip';
import { extractVariableLabel } from '@/workflow/workflow-variables/utils/extractVariableLabel';
import { Node } from '@tiptap/core';
import { mergeAttributes } from '@tiptap/react';
import { mergeAttributes, ReactNodeViewRenderer } from '@tiptap/react';
declare module '@tiptap/core' {
interface Commands<ReturnType> {
@ -41,6 +42,10 @@ export const VariableTag = Node.create({
];
},
addNodeView: () => {
return ReactNodeViewRenderer(WorkflowTextEditorVariableChip);
},
renderText: ({ node }) => {
return node.attrs.variable;
},