GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(custom-blocks): escape LIKE wildcards in usage scan + fresh count… · simstudioai/sim@df17670

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/sim
    • ee/custom-blocks/components
      • custom-block-detail.tsx
    • lib/workflows/custom-blocks
      • operations.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

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 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={
Collapse file

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

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 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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.