From 9f3273ddf1b10a55e6395ad9b858bb0a661135d5 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 10 Jan 2025 16:36:56 +0400 Subject: [PATCH] feat(lib): add isRegrouped function to validate regroup values against children --- src/if-run/lib/regroup.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/if-run/lib/regroup.ts b/src/if-run/lib/regroup.ts index 55d8f822..97816ed2 100644 --- a/src/if-run/lib/regroup.ts +++ b/src/if-run/lib/regroup.ts @@ -86,3 +86,20 @@ export const Regroup = ( return acc.children; }; + +/** + * Grabs all the values according to grouping criteria, then + * checks if regroup values are present in the children list. + */ +export const isRegrouped = ( + groups: string[], + outputStorage: PluginParams[], + childNames: Set +) => { + const validatedGroups = validateGroups(groups); + const regroupValues = validatedGroups + .map(group => [...new Set(outputStorage.map(output => output[group]))]) + .flat(); + + return regroupValues.every(one => [...childNames].includes(one)); +};