GeezerVison is showing github.com — fix(custom-blocks): escape LIKE wildcards in usage scan + fresh count… · simstudioai/sim@df17670
File treeExpand file treeCollapse file tree Open diff view settings ee/custom-blocks/components lib/workflows/custom-blocks
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/sim/ee/custom-blocks/components/custom-block-detail.tsx +17-11Lines changed: 17 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -432,7 +432,12 @@ export function CustomBlockDetail({ blockId, workspaceId, onBack }: CustomBlockD | 432 | 432 | { | 433 | 433 | text: remove.isPending ? 'Deleting...' : 'Delete', | 434 | 434 | variant: 'destructive' as const, | 435 | | - onSelect: () => setShowDelete(true), | | 435 | + onSelect: () => { | | 436 | + setShowDelete(true) | | 437 | + // The warning must reflect the org's CURRENT usage, not a | | 438 | + // ≤30s-stale cache entry. | | 439 | + usageCountsQuery.refetch() | | 440 | + }, | 436 | 441 | disabled: remove.isPending, | 437 | 442 | }, | 438 | 443 | ] | @@ -733,16 +738,17 @@ export function CustomBlockDetail({ blockId, workspaceId, onBack }: CustomBlockD | 733 | 738 | disabled: confirmationText !== (existing?.name ?? ''), | 734 | 739 | }} | 735 | 740 | > | 736 | | - {usageCount > 0 ? ( | 737 | | - <p className='break-words px-2 text-[var(--text-error)] text-sm'> | 738 | | - {usageCount} {usageCount === 1 ? 'workflow is' : 'workflows are'} still using this block | 739 | | - and will fail at run time. | 740 | | - </p> | 741 | | - ) : ( | 742 | | - <p className='break-words px-2 text-[var(--text-muted)] text-sm'> | 743 | | - No workflows are currently using it. | 744 | | - </p> | 745 | | - )} | | 741 | + {usageCountsQuery.data && | | 742 | + (usageCount > 0 ? ( | | 743 | + <p className='break-words px-2 text-[var(--text-error)] text-sm'> | | 744 | + {usageCount} {usageCount === 1 ? 'workflow is' : 'workflows are'} still using this | | 745 | + block and will fail at run time. | | 746 | + </p> | | 747 | + ) : ( | | 748 | + <p className='break-words px-2 text-[var(--text-muted)] text-sm'> | | 749 | + No workflows are currently using it. | | 750 | + </p> | | 751 | + ))} | 746 | 752 | <ChipModalField | 747 | 753 | type='input' | 748 | 754 | title={ | |
Collapse file Copy file name to clipboardExpand all lines: apps/sim/lib/workflows/custom-blocks/operations.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -464,6 +464,9 @@ export async function getCustomBlockUsageCounts( | 464 | 464 | eq(workspace.organizationId, organizationId), | 465 | 465 | isNull(workflow.archivedAt) | 466 | 466 | ) | | 467 | + // Escape LIKE wildcards — the `_`s in `custom_block_<id>` would otherwise match | | 468 | + // any character and let unrelated states through to the jsonb parse. | | 469 | + const likePattern = `%${blockType.replace(/[\\%_]/g, '\\$&')}%` | 467 | 470 |
| 468 | 471 | const [liveRows, deployedRows] = await Promise.all([ | 469 | 472 | db | @@ -482,7 +485,7 @@ export async function getCustomBlockUsageCounts( | 482 | 485 | eq(workflowDeploymentVersion.isActive, true), | 483 | 486 | eq(workflow.isDeployed, true), | 484 | 487 | orgActiveWorkflow, | 485 | | - sql`${workflowDeploymentVersion.state}::text LIKE ${`%${blockType}%`}`, | | 488 | + sql`${workflowDeploymentVersion.state}::text LIKE ${likePattern}`, | 486 | 489 | sql`EXISTS ( | 487 | 490 | SELECT 1 FROM jsonb_each((${workflowDeploymentVersion.state})::jsonb -> 'blocks') AS b | 488 | 491 | WHERE b.value ->> 'type' = ${blockType} | |
|