fix(lock): address code review feedback

- Fix toggle enabled using first toggleable block, not first block
- Delete button now checks isParentLocked
- Lock button now has disabled state
- Editor lock icon distinguishes block vs parent lock state

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
waleed
2026-01-31 18:56:57 -08:00
parent 3f908d6121
commit 73856af86d
3 changed files with 20 additions and 9 deletions

View File

@@ -225,9 +225,12 @@ export const ActionBar = memo(
variant='ghost'
onClick={(e) => {
e.stopPropagation()
collaborativeBatchToggleLocked([blockId])
if (!disabled) {
collaborativeBatchToggleLocked([blockId])
}
}}
className={ACTION_BUTTON_STYLES}
disabled={disabled}
>
{isLocked ? <Unlock className={ICON_SIZE} /> : <Lock className={ICON_SIZE} />}
</Button>
@@ -319,18 +322,18 @@ export const ActionBar = memo(
variant='ghost'
onClick={(e) => {
e.stopPropagation()
if (!disabled && !isLocked) {
if (!disabled && !isLocked && !isParentLocked) {
collaborativeBatchRemoveBlocks([blockId])
}
}}
className={ACTION_BUTTON_STYLES}
disabled={disabled || isLocked}
disabled={disabled || isLocked || isParentLocked}
>
<Trash2 className={ICON_SIZE} />
</Button>
</Tooltip.Trigger>
<Tooltip.Content side='top'>
{isLocked ? 'Block is locked' : getTooltipMessage('Delete Block')}
{isLocked || isParentLocked ? 'Block is locked' : getTooltipMessage('Delete Block')}
</Tooltip.Content>
</Tooltip.Root>
</div>

View File

@@ -368,11 +368,11 @@ export function Editor() {
)}
</div>
<div className='flex shrink-0 items-center gap-[8px]'>
{/* Locked indicator - clickable to unlock if user has admin permissions */}
{/* Locked indicator - clickable to unlock if user has admin permissions and block itself is locked */}
{isLocked && currentBlock && (
<Tooltip.Root>
<Tooltip.Trigger asChild>
{userPermissions.canAdmin ? (
{userPermissions.canAdmin && currentBlock.locked ? (
<Button
variant='ghost'
className='p-0'
@@ -388,7 +388,13 @@ export function Editor() {
)}
</Tooltip.Trigger>
<Tooltip.Content side='top'>
<p>{userPermissions.canAdmin ? 'Unlock block' : 'Block is locked'}</p>
<p>
{userPermissions.canAdmin && currentBlock.locked
? 'Unlock block'
: isParentLocked
? 'Parent container is locked'
: 'Block is locked'}
</p>
</Tooltip.Content>
</Tooltip.Root>
)}

View File

@@ -778,8 +778,10 @@ async function handleBlocksOperationTx(
}
}
// Determine target enabled state based on first block
const firstBlock = blocksById[blockIds[0]]
// Determine target enabled state based on first toggleable block
if (blocksToToggle.size === 0) break
const firstToggleableId = Array.from(blocksToToggle)[0]
const firstBlock = blocksById[firstToggleableId]
if (!firstBlock) break
const targetEnabled = !firstBlock.enabled