Skip to content

Commit b4d2d72

Browse files
authored
feat/COMPASS-9792: Add renderName for custom field name rendering (#129)
1 parent 3b6f215 commit b4d2d72

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/components/field/field.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const Field = ({
145145
selectedGroupHeight = 0,
146146
previewGroupArea,
147147
glyphSize = LGSpacing[300],
148+
renderName,
148149
spacing = 0,
149150
selectable = false,
150151
selected = false,
@@ -168,6 +169,7 @@ export const Field = ({
168169
const fieldSelectionProps = useMemo(() => {
169170
return selectable && fieldProps
170171
? {
172+
'data-testid': `selectable-field-${nodeId}-${typeof id === 'string' ? id : id.join('.')}`,
171173
selectable: true,
172174
onClick: (event: ReactMouseEvent) => fieldProps.onClick(event, { id, nodeId }),
173175
}
@@ -213,7 +215,7 @@ export const Field = ({
213215
<>
214216
<FieldName>
215217
<FieldDepth depth={depth} />
216-
<InnerFieldName>{name}</InnerFieldName>
218+
<InnerFieldName>{renderName || name}</InnerFieldName>
217219
</FieldName>
218220
<FieldType color={getSecondaryTextColor()}>{type}</FieldType>
219221
</>

src/components/node/node.stories.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,33 @@ export const NodeWithCustomTypeField: Story = {
246246
},
247247
};
248248

249+
export const NodeWithCustomFieldNameRender: Story = {
250+
args: {
251+
...INTERNAL_NODE,
252+
data: {
253+
title: 'orders',
254+
fields: [
255+
{
256+
name: 'customerId',
257+
renderName: (
258+
<div style={{ background: 'orange', width: '100%' }}>
259+
<input
260+
type="text"
261+
onSubmit={e => e.preventDefault()}
262+
defaultValue="Custom name"
263+
style={{ marginLeft: 5, marginRight: 5, width: '90px' }}
264+
/>
265+
</div>
266+
),
267+
type: 'string',
268+
variant: 'default',
269+
glyphs: ['key'],
270+
},
271+
],
272+
},
273+
},
274+
};
275+
249276
export const NodeWithPrimaryField: Story = {
250277
args: {
251278
...INTERNAL_NODE,

src/components/node/node.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const NodeHeader = styled.div<{ background?: string }>`
6666
line-height: 20px;
6767
font-weight: bold;
6868
min-height: ${DEFAULT_NODE_HEADER_HEIGHT}px;
69-
padding: 0px ${spacing[400]}px 0px ${spacing[200]}px;
69+
padding: 0px;
70+
padding-left: ${spacing[200]}px;
7071
background: ${props => props.background};
7172
`;
7273

@@ -79,6 +80,7 @@ const NodeHeaderIcon = styled.div`
7980
export const NodeHeaderTitle = styled.div`
8081
overflow-wrap: break-word;
8182
min-width: 0;
83+
margin-right: ${spacing[200]}px;
8284
`;
8385

8486
const NodeHandle = styled(Handle)<{ ['z-index']?: number }>`

src/types/node.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ export interface NodeField {
143143
*/
144144
name: string;
145145

146+
/**
147+
* Optional custom rendering for the field name. If not provided, `name` will be used.
148+
*/
149+
renderName?: React.ReactNode;
150+
146151
/**
147152
* Unique identifier for the field. Passed in field click events.
148153
* Defaults to `name` when not supplied.

0 commit comments

Comments
 (0)