Skip to content

Commit 3288564

Browse files
authored
feat/COMPASS-9696 Add actions prop to node, shown in the header (#118)
1 parent 052e024 commit 3288564

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/components/node/node.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ export const NodeWithDeeplyNestedPreviewFieldsEverywhere: Story = {
483483
},
484484
};
485485

486+
export const NodeWithAction: Story = {
487+
args: {
488+
...INTERNAL_NODE,
489+
data: {
490+
title: 'orders',
491+
fields: [
492+
{
493+
name: 'orderId',
494+
type: 'string',
495+
glyphs: ['key'],
496+
},
497+
],
498+
actions: <button style={{ marginLeft: 'auto' }}>Action</button>,
499+
},
500+
},
501+
};
502+
486503
export const NodeWithSelectedFields: Story = {
487504
args: {
488505
...INTERNAL_NODE,

src/components/node/node.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const Node = ({
102102
type,
103103
selected,
104104
isConnectable,
105-
data: { title, fields, borderVariant, disabled },
105+
data: { actions, title, fields, borderVariant, disabled },
106106
}: NodeProps<InternalNode>) => {
107107
const theme = useTheme();
108108
const { zoom } = useViewport();
@@ -183,6 +183,7 @@ export const Node = ({
183183
<Icon fill={theme.node.headerIcon} glyph="Drag" />
184184
</NodeHeaderIcon>
185185
<NodeHeaderTitle>{title}</NodeHeaderTitle>
186+
{actions}
186187
</NodeHeader>
187188
<FieldList nodeId={id} nodeType={type as NodeType} isHovering={isHovering} fields={fields} />
188189
</NodeWithFields>

src/types/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { NodeBorderVariant, NodeField } from '@/types/node';
44
import { EdgeProps } from '@/types/edge';
55

66
export type NodeData = {
7+
actions?: React.ReactNode;
78
title: string;
89
disabled?: boolean;
910
fields: NodeField[];

src/types/node.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export interface NodeProps {
6565
* The title of the node, usually a collection or table name.
6666
*/
6767
title: string;
68+
69+
/**
70+
* Actions to display in the node header, optional.
71+
*/
72+
actions?: React.ReactNode;
73+
6874
/**
6975
* Whether the node is disabled.
7076
*/

0 commit comments

Comments
 (0)