@@ -58,16 +58,32 @@ export function isEdgeProtected(
5858 * @param blocks - Record of all blocks in the workflow
5959 * @returns Result containing deletable IDs, protected IDs, and whether all are protected
6060 */
61+ export function filterProtectedBlocks (
62+ blockIds : string [ ] ,
63+ blocks : Record < string , BlockState >
64+ ) : FilterProtectedBlocksResult {
65+ const protectedIds = blockIds . filter ( ( id ) => isBlockProtected ( id , blocks ) )
66+ const deletableIds = blockIds . filter ( ( id ) => ! protectedIds . includes ( id ) )
67+
68+ return {
69+ deletableIds,
70+ protectedIds,
71+ allProtected : protectedIds . length === blockIds . length && blockIds . length > 0 ,
72+ }
73+ }
74+
6175/**
6276 * Returns block IDs ordered so that `batchToggleLocked` will target the desired state.
6377 *
6478 * `batchToggleLocked` determines its target locked state from `!firstBlock.locked`.
6579 * When `targetLocked` is true (lock all), an unlocked block must come first.
6680 * When `targetLocked` is false (unlock all), a locked block must come first.
6781 *
82+ * Returns an empty array when there are no blocks or all blocks already match `targetLocked`.
83+ *
6884 * @param blocks - Record of all blocks in the workflow
6985 * @param targetLocked - The desired locked state for all blocks
70- * @returns Sorted block IDs, or empty array if there are no blocks
86+ * @returns Sorted block IDs, or empty array if no toggle is needed
7187 */
7288export function getWorkflowLockToggleIds (
7389 blocks : Record < string , BlockState > ,
@@ -76,6 +92,10 @@ export function getWorkflowLockToggleIds(
7692 const ids = Object . keys ( blocks )
7793 if ( ids . length === 0 ) return [ ]
7894
95+ // No-op if all blocks already match the desired state
96+ const allMatch = Object . values ( blocks ) . every ( ( b ) => Boolean ( b . locked ) === targetLocked )
97+ if ( allMatch ) return [ ]
98+
7999 ids . sort ( ( a , b ) => {
80100 const aVal = blocks [ a ] . locked ? 1 : 0
81101 const bVal = blocks [ b ] . locked ? 1 : 0
@@ -86,17 +106,3 @@ export function getWorkflowLockToggleIds(
86106
87107 return ids
88108}
89-
90- export function filterProtectedBlocks (
91- blockIds : string [ ] ,
92- blocks : Record < string , BlockState >
93- ) : FilterProtectedBlocksResult {
94- const protectedIds = blockIds . filter ( ( id ) => isBlockProtected ( id , blocks ) )
95- const deletableIds = blockIds . filter ( ( id ) => ! protectedIds . includes ( id ) )
96-
97- return {
98- deletableIds,
99- protectedIds,
100- allProtected : protectedIds . length === blockIds . length && blockIds . length > 0 ,
101- }
102- }
0 commit comments