From 04b64aaa7d61bcaf00b2ac5720b03d2bb3bb00e9 Mon Sep 17 00:00:00 2001 From: Samuel Greene Date: Fri, 17 Nov 2023 02:39:19 -0500 Subject: [PATCH 1/4] add anyLeaves and allLeaves --- packages/client/src/util/tree.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/client/src/util/tree.js b/packages/client/src/util/tree.js index d00207669..b88319dea 100644 --- a/packages/client/src/util/tree.js +++ b/packages/client/src/util/tree.js @@ -28,3 +28,6 @@ export let postWalkBranches = (fn) => if (Tree.traverse(node)) fn(node, ...args) } ) + +export let anyLeaves = _.curry((fn, node) => _.some(fn, Tree.leaves(node))) +export let allLeaves = _.curry((fn, node) => _.every(fn, Tree.leaves(node))) \ No newline at end of file From e53f80ce59f7f13648f0a6da6986738b08ff4b9b Mon Sep 17 00:00:00 2001 From: Samuel Greene Date: Fri, 17 Nov 2023 02:39:39 -0500 Subject: [PATCH 2/4] expose anyLeaves and allLeaves actions --- packages/client/src/actions/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/client/src/actions/index.js b/packages/client/src/actions/index.js index 08e74c7cb..7e41c57a9 100644 --- a/packages/client/src/actions/index.js +++ b/packages/client/src/actions/index.js @@ -1,6 +1,6 @@ import _ from 'lodash/fp.js' import F from 'futil' -import { encode, Tree } from '../util/tree.js' +import { encode, Tree, anyLeaves, allLeaves } from '../util/tree.js' import { getTypeProp } from '../types.js' import wrap from './wrap.js' import { dedupeWalk } from '../node.js' @@ -129,8 +129,9 @@ export default (config) => { let pauseNested = (path) => mutateNested(path, { paused: true }) let unpauseNested = (path) => mutateNested(path, { paused: false }) - let nodeLeaves = _.flow(getNode, Tree.leaves) - let isPausedNested = _.flow(nodeLeaves, _.every('paused')) + let anyPathLeaves = (path, fn) => anyLeaves(fn, getNode(path)) + let allPathLeaves = (path, fn) => allLeaves(fn, getNode(path)) + let isPausedNested = path => allPathLeaves(path, 'paused') return { add, @@ -145,5 +146,7 @@ export default (config) => { isPausedNested, pauseNested, unpauseNested, + allLeaves: allPathLeaves, + anyLeaves: anyPathLeaves, } } From b1bce0618414885124d26789979d8deef488c504 Mon Sep 17 00:00:00 2001 From: Samuel Greene Date: Fri, 17 Nov 2023 02:39:53 -0500 Subject: [PATCH 3/4] add someError and everyPaused to groups using new utils --- packages/client/src/node.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/client/src/node.js b/packages/client/src/node.js index 5f22b2015..2ce3040c9 100644 --- a/packages/client/src/node.js +++ b/packages/client/src/node.js @@ -1,6 +1,6 @@ import _ from 'lodash/fp.js' import F from 'futil' -import { Tree, encode } from './util/tree.js' +import { Tree, encode, anyLeaves, allLeaves } from './util/tree.js' import { runTypeFunction, runTypeFunctionOrDefault, @@ -32,6 +32,8 @@ export let internalStateKeys = [ 'forceReplaceResponse', 'expand', 'collapse', + 'someError', + 'everyPaused', ] export let autoKey = (x) => F.compactJoin('-', [x.field, x.type]) || 'node' @@ -50,6 +52,10 @@ export let initNode = _.curry((actionProps, dedupe, parentPath, node) => { ..._.omit(_.keys(node), snapshot(getTypeProp(types, 'defaults', node))), key, path: [...parentPath, key], + ...node.children && { + someError: () => anyLeaves('error', node), + everyPaused: () => allLeaves('paused', node), + } }) }) From b429afababaeb26a530851fdc68adba0352111d2 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Fri, 17 Nov 2023 07:40:54 +0000 Subject: [PATCH 4/4] Fix code style issues with Prettier --- packages/client/src/actions/index.js | 2 +- packages/client/src/node.js | 4 ++-- packages/client/src/util/tree.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client/src/actions/index.js b/packages/client/src/actions/index.js index 7e41c57a9..04febe8a6 100644 --- a/packages/client/src/actions/index.js +++ b/packages/client/src/actions/index.js @@ -131,7 +131,7 @@ export default (config) => { let anyPathLeaves = (path, fn) => anyLeaves(fn, getNode(path)) let allPathLeaves = (path, fn) => allLeaves(fn, getNode(path)) - let isPausedNested = path => allPathLeaves(path, 'paused') + let isPausedNested = (path) => allPathLeaves(path, 'paused') return { add, diff --git a/packages/client/src/node.js b/packages/client/src/node.js index 2ce3040c9..731b7c7e1 100644 --- a/packages/client/src/node.js +++ b/packages/client/src/node.js @@ -52,10 +52,10 @@ export let initNode = _.curry((actionProps, dedupe, parentPath, node) => { ..._.omit(_.keys(node), snapshot(getTypeProp(types, 'defaults', node))), key, path: [...parentPath, key], - ...node.children && { + ...(node.children && { someError: () => anyLeaves('error', node), everyPaused: () => allLeaves('paused', node), - } + }), }) }) diff --git a/packages/client/src/util/tree.js b/packages/client/src/util/tree.js index b88319dea..bd1bc19a4 100644 --- a/packages/client/src/util/tree.js +++ b/packages/client/src/util/tree.js @@ -30,4 +30,4 @@ export let postWalkBranches = (fn) => ) export let anyLeaves = _.curry((fn, node) => _.some(fn, Tree.leaves(node))) -export let allLeaves = _.curry((fn, node) => _.every(fn, Tree.leaves(node))) \ No newline at end of file +export let allLeaves = _.curry((fn, node) => _.every(fn, Tree.leaves(node)))