Skip to content

Commit

Permalink
group -> inputGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
sroussey committed Feb 4, 2024
1 parent 94c3760 commit a72429f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
12 changes: 6 additions & 6 deletions lib/NodeGraphEditorEllmers.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,37 +178,37 @@ const meta = {
{
name: 'Distribution',
id: 'distribution',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'specularDistribution',
},
{
name: 'IOR Level',
id: 'iorLevel',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Tint',
id: 'tint',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'color',
},
{
name: 'Anisotropic',
id: 'anisotropic',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Anisotropic Rotation',
id: 'anisotropicRotation',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Strength',
id: 'strength',
group: 'Emission',
inputGroup: 'Emission',
valueType: 'number',
},
],
Expand Down
12 changes: 6 additions & 6 deletions lib/NodeGraphEditorInputGroups.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,37 +155,37 @@ const meta = {
{
name: 'Distribution',
id: 'distribution',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'specularDistribution',
},
{
name: 'IOR Level',
id: 'iorLevel',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Tint',
id: 'tint',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'color',
},
{
name: 'Anisotropic',
id: 'anisotropic',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Anisotropic Rotation',
id: 'anisotropicRotation',
group: 'Specular',
inputGroup: 'Specular',
valueType: 'number',
},
{
name: 'Strength',
id: 'strength',
group: 'Emission',
inputGroup: 'Emission',
valueType: 'number',
},
],
Expand Down
10 changes: 5 additions & 5 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface NodeInputConfig {
* any other inputs with this group name will be rendered under a collapsable
* accordion.
*/
group?: string
inputGroup?: string
}

export interface NodeOutputConfig {
Expand Down Expand Up @@ -231,14 +231,14 @@ export class GraphConfig {
registerCustomNode<T>(
name: string,
type: string,
group: string,
theme: string,
node: JSXElementConstructor<T>,
inputs: NodeInputConfig[],
outputs: NodeOutputConfig[],
) {
this.customNodes[type] = node
this.nodeTypes[type] = {
theme: group,
theme: theme,
name,
inputs: inputs,
outputs: outputs,
Expand Down Expand Up @@ -288,8 +288,8 @@ export class GraphConfig {
return this.nodeTypes[type]
}

nodeConfigsByGroup(group: string): NodeConfig[] {
return Object.values(this.nodeTypes).filter((n) => n.theme === group)
nodeConfigsByTheme(theme: string): NodeConfig[] {
return Object.values(this.nodeTypes).filter((n) => n.theme === theme)
}

nodeThemeConfigs(): WithType<NodeThemeConfig, string>[] {
Expand Down
8 changes: 4 additions & 4 deletions lib/hooks/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const INPUT_GROUPS_FIELD = '__inputGroupsExpanded'
* A drop-in replacement for the useState hook that stores whether an input group is expanded
* or not in the node's data object. It shares the same underlying array of expanded groups
* with other hooks that use the same node ID.
* @param group
* @param inputGroup
*/
export function useNodeInputGroupState(
group: string,
inputGroup: string,
): [boolean, (newState: boolean) => void] {
const nodeId = useNodeId()
return useToggleNodeArrayProperty(nodeId!, INPUT_GROUPS_FIELD, group)
return useToggleNodeArrayProperty(nodeId!, INPUT_GROUPS_FIELD, inputGroup)
}

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ function useToggleNodeArrayProperty(
data[INPUT_GROUPS_FIELD].includes(key),
)
const toggleProperty = useCallback(
(newState) => {
(newState: React.SetStateAction<boolean>) => {
setIsEnabled(newState)

updateNodeData(nodeId, (node) => {
Expand Down
16 changes: 8 additions & 8 deletions lib/node-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function buildNode(nodeConfig: NodeConfig): FunctionComponent<Node> {
// Construct memoized input and output components based on the node config
const inputs = useMemo(() => {
return getInputElements(
inputConfigs.filter((input) => !input.group),
inputConfigs.filter((input) => !input.inputGroup),
edges,
)
}, [inputConfigs, config, node, edgeIds])
Expand All @@ -83,18 +83,18 @@ export function buildNode(nodeConfig: NodeConfig): FunctionComponent<Node> {
// Input groups are those inputs that should be rendered under a collapsable accordion
const inputGroups = useMemo(() => {
const grouped: Record<string, NodeInputConfig[]> = inputConfigs
.filter((input) => input.group)
.filter((input) => input.inputGroup)
.reduce((acc: Record<string, NodeInputConfig[]>, input) => {
const group = input.group!
if (!acc[group]) acc[group] = []
acc[group].push(input)
const inputGroup = input.inputGroup!
if (!acc[inputGroup]) acc[inputGroup] = []
acc[inputGroup].push(input)
return acc
}, {})

return Object.entries(grouped).map(([group, inputs]) => (
return Object.entries(grouped).map(([inputGroup, inputs]) => (
<InputGroup
label={group}
key={group}
label={inputGroup}
key={inputGroup}
handles={getHandlesForInputs(inputs)}
>
{getInputElements(inputs, edges)}
Expand Down

0 comments on commit a72429f

Please sign in to comment.