improvement(editor): fix React effect/state anti-patterns across the /w surface by waleedlatif1 · Pull Request #5325 · simstudioai/sim · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ const TagIcon: React.FC<{

const EMPTY_OUTPUTS: string[] = []

/**
* Gets the background color for a block output based on its type
* @param blockType - The type of the block
* @returns The hex color code for the block
*/
const getOutputColor = (blockType: string) => {
const blockConfig = getBlock(blockType)
return blockConfig?.bgColor || '#2F55FF'
}

/**
* Props for the OutputSelect component
*/
Expand Down Expand Up @@ -159,16 +169,7 @@ export function OutputSelect({
path: f.path,
}
})
}, [
workflowBlocks,
workflowId,
isShowingDiff,
isDiffReady,
baselineWorkflow,
blocks,
subBlockValues,
shouldUseBaseline,
])
}, [workflowBlocks, workflowId, baselineWorkflow, subBlockValues, shouldUseBaseline])

/**
* Gets display text for selected outputs
Expand All @@ -193,16 +194,6 @@ export function OutputSelect({
return `${validOutputs.length} outputs`
}, [selectedOutputs, workflowOutputs, placeholder])

/**
* Gets the background color for a block output based on its type
* @param blockType - The type of the block
* @returns The hex color code for the block
*/
const getOutputColor = (blockType: string) => {
const blockConfig = getBlock(blockType)
return blockConfig?.bgColor || '#2F55FF'
}

/**
* Groups outputs by block and sorts by distance from starter block.
* Returns ComboboxOptionGroup[] for use with Combobox.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ const CursorsComponent = () => {
return []
}

return presenceUsers
.filter((user): user is typeof user & { cursor: CursorPoint } => Boolean(user.cursor))
.filter((user) => user.socketId !== currentSocketId)
.map((user) => ({
const rendered: CursorRenderData[] = []
for (const user of presenceUsers) {
if (!user.cursor || user.socketId === currentSocketId) continue
rendered.push({
id: user.socketId,
name: user.userName?.trim() || 'Collaborator',
cursor: user.cursor,
color: getUserColor(user.userId),
}))
})
}
return rendered
}, [activeWorkflowId, currentSocketId, currentWorkflowId, presenceUsers])

if (!cursors.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const DiffControls = memo(function DiffControls() {
>
{/* Reject side */}
<button
type='button'
onClick={handleReject}
title='Reject changes'
className='relative flex h-full items-center border border-[var(--border)] bg-[var(--surface-4)] pr-5 pl-3 font-medium text-[var(--text-secondary)] text-small transition-colors hover-hover:border-[var(--border-1)] hover-hover:bg-[var(--surface-6)] hover-hover:text-[var(--text-primary)] dark:hover-hover:bg-[var(--surface-5)]'
Expand All @@ -86,6 +87,7 @@ export const DiffControls = memo(function DiffControls() {
/>
{/* Accept side */}
<button
type='button'
onClick={handleAccept}
title='Accept changes (⇧⌘⏎)'
className='-ml-2.5 relative flex h-full items-center border border-[rgba(0,0,0,0.15)] bg-[var(--brand-accent)] pr-3 pl-5 font-medium text-[var(--text-inverse)] text-small transition-[background-color,border-color,fill,stroke] hover-hover:brightness-110 dark:border-[rgba(255,255,255,0.1)]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const NoteBlock = memo(function NoteBlock({
const userPermissions = useUserPermissionsContext()
const canEditWorkflow = userPermissions.canEdit && !data.isWorkflowLocked

const actionBar = useMemo(
() => <ActionBar blockId={id} blockType={type} disabled={!canEditWorkflow} />,
[id, type, canEditWorkflow]
)

/**
* Calculate deterministic dimensions based on content structure. Uses fixed
* width and computed height to avoid ResizeObserver jitter.
Expand All @@ -90,7 +95,7 @@ export const NoteBlock = memo(function NoteBlock({
hasRing={hasRing}
ringStyles={ringStyles}
onSelect={handleClick}
actionBar={<ActionBar blockId={id} blockType={type} disabled={!canEditWorkflow} />}
actionBar={actionBar}
/>
)
})
Loading
Loading