Skip to content

Commit df17670

Browse files
fix(custom-blocks): escape LIKE wildcards in usage scan + fresh count on delete modal
1 parent 416a640 commit df17670

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

apps/sim/ee/custom-blocks/components/custom-block-detail.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,12 @@ export function CustomBlockDetail({ blockId, workspaceId, onBack }: CustomBlockD
432432
{
433433
text: remove.isPending ? 'Deleting...' : 'Delete',
434434
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+
},
436441
disabled: remove.isPending,
437442
},
438443
]
@@ -733,16 +738,17 @@ export function CustomBlockDetail({ blockId, workspaceId, onBack }: CustomBlockD
733738
disabled: confirmationText !== (existing?.name ?? ''),
734739
}}
735740
>
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+
))}
746752
<ChipModalField
747753
type='input'
748754
title={

apps/sim/lib/workflows/custom-blocks/operations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ export async function getCustomBlockUsageCounts(
464464
eq(workspace.organizationId, organizationId),
465465
isNull(workflow.archivedAt)
466466
)
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, '\\$&')}%`
467470

468471
const [liveRows, deployedRows] = await Promise.all([
469472
db
@@ -482,7 +485,7 @@ export async function getCustomBlockUsageCounts(
482485
eq(workflowDeploymentVersion.isActive, true),
483486
eq(workflow.isDeployed, true),
484487
orgActiveWorkflow,
485-
sql`${workflowDeploymentVersion.state}::text LIKE ${`%${blockType}%`}`,
488+
sql`${workflowDeploymentVersion.state}::text LIKE ${likePattern}`,
486489
sql`EXISTS (
487490
SELECT 1 FROM jsonb_each((${workflowDeploymentVersion.state})::jsonb -> 'blocks') AS b
488491
WHERE b.value ->> 'type' = ${blockType}

0 commit comments

Comments
 (0)