-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display existing validation checks in publish dialog (#3276)
- Loading branch information
1 parent
87de06d
commit 8e303fe
Showing
6 changed files
with
572 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
ComponentType, | ||
FlowGraph, | ||
Node, | ||
} from "@opensystemslab/planx-core/types"; | ||
import { Entry } from "type-fest"; | ||
|
||
export const isComponentType = ( | ||
entry: Entry<FlowGraph>, | ||
type: ComponentType, | ||
): entry is [string, Node] => { | ||
const [nodeId, node] = entry; | ||
if (nodeId === "_root") return false; | ||
return Boolean(node?.type === type); | ||
}; | ||
|
||
export const hasComponentType = ( | ||
flowGraph: FlowGraph, | ||
type: ComponentType, | ||
fn?: string, | ||
): boolean => { | ||
const nodeIds = Object.entries(flowGraph).filter( | ||
(entry): entry is [string, Node] => isComponentType(entry, type), | ||
); | ||
if (fn) { | ||
nodeIds | ||
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn) | ||
?.map(([nodeId, _nodeData]) => nodeId); | ||
} else { | ||
nodeIds?.map(([nodeId, _nodeData]) => nodeId); | ||
} | ||
return Boolean(nodeIds?.length); | ||
}; | ||
|
||
export const numberOfComponentType = ( | ||
flowGraph: FlowGraph, | ||
type: ComponentType, | ||
fn?: string, | ||
): number => { | ||
const nodeIds = Object.entries(flowGraph).filter( | ||
(entry): entry is [string, Node] => isComponentType(entry, type), | ||
); | ||
if (fn) { | ||
nodeIds | ||
?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn) | ||
?.map(([nodeId, _nodeData]) => nodeId); | ||
} else { | ||
nodeIds?.map(([nodeId, _nodeData]) => nodeId); | ||
} | ||
return nodeIds?.length; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.