Skip to content

Commit cb050f0

Browse files
authored
Fix enum array. (#306)
Fix unnecessary docker releases
1 parent f7f4147 commit cb050f0

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

.changeset/thick-moose-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tokens-studio/graph-editor": patch
3+
---
4+
5+
Fixed an issue on input that was throwing an error if you create both an array and enumerated value

.github/workflows/docker-release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Publish to Dockerhub
22

33
on:
4-
push:
5-
branches: [ master ]
4+
workflow_dispatch:
65

76
jobs:
87
build:
@@ -39,7 +38,7 @@ jobs:
3938
with:
4039
tags: |
4140
type=sha,format=long
42-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'major/strong-typing') }}
41+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
4342
images: |
4443
tokensstudio/graph-engine-${{matrix.type}}
4544

.github/workflows/gimlet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
with:
4343
tags: |
4444
type=sha,format=long,prefix=${{matrix.type}}-
45-
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'major/strong-typing') }}
45+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
4646
images: |
4747
ghcr.io/tokens-studio/graph-engine
4848

packages/graph-editor/src/components/flow/wrapper/nodeV2.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const NodeWrap = observer(({ node }: INodeWrap) => {
7474
subtitle={node.annotations[title] ? node.factory.title : ""}
7575
error={node.error || null}
7676
controls={''}
77-
style={{minWidth:'350px'}}
77+
style={{ minWidth: '350px' }}
7878
>
7979
<Stack direction="column" gap={2}>
8080
<Stack direction="row" gap={3} css={{ padding: '$3' }}>
@@ -159,7 +159,7 @@ const getColorPreview = (color: string, showValue = false) => {
159159

160160
return (
161161
<Stack direction="row" gap={2}>
162-
{colorSwatch}
162+
{colorSwatch}
163163
{showValue ? <Text css={{ fontSize: '$small', color: '$gray12' }}>{color.toUpperCase()}</Text> : null}
164164
</Stack>
165165
);
@@ -174,8 +174,9 @@ const getValuePreview = (value, type) => {
174174
let valuePreview = '';
175175
switch (type.type) {
176176
case 'array':
177-
const allColors = value.every(isHexColor);
178-
if (allColors) {
177+
178+
if (type.items?.$id === COLOR) {
179+
179180
return (<Stack direction="row" gap={1}>
180181
{value.length > 5 ? (
181182
<>
@@ -184,7 +185,9 @@ const getValuePreview = (value, type) => {
184185
</>
185186
) : value.map((val) => getColorPreview(val))}
186187
</Stack>)
188+
187189
}
190+
188191
valuePreview = JSON.stringify(value);
189192
break;
190193
case 'object':
@@ -198,7 +201,7 @@ const getValuePreview = (value, type) => {
198201
break
199202
default:
200203
if (isHexColor(value)) {
201-
return getColorPreview(value,true);
204+
return getColorPreview(value, true);
202205
}
203206
valuePreview = JSON.stringify(value);
204207
}

packages/graph-editor/src/components/panels/inputs/dynamicInputs.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ export const DynamicInputs = observer(({ node }: { node: Node }) => {
3333
let type = {
3434
...schema,
3535
};
36+
let innerType = type;
3637

3738
if (asArray) {
3839
type = {
3940
type: "array",
40-
items: type
41+
items: type,
42+
default: [],
4143
}
4244
}
4345

4446
if (enumerated) {
45-
type.enum = enumeratedValues.split(',').map((x) => x.trim());
46-
type.default = type.enum[0];
47+
innerType.enum = enumeratedValues.split(',').map((x) => x.trim());
48+
if (!asArray) {
49+
innerType.default = type.enum[0];
50+
}
4751
}
4852

4953
const input = node.addInput(inputName, {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { FlowGraph } from "@tokens-studio/graph-engine";
1+
import { Graph } from "@tokens-studio/graph-engine";
22

3-
export type UpgradeFunction = (graph: FlowGraph) => Promise<FlowGraph>;
3+
export type UpgradeFunction = (graph: Graph) => Promise<Graph>;

packages/migrations/src/utils.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Edge, FlowGraph, Node } from "@tokens-studio/graph-engine";
1+
import { Edge, Graph, Node } from "@tokens-studio/graph-engine";
22

33
/**
44
* Finds all nodes of a specified type in the graph
55
* @param graph
66
* @param type
77
* @returns
88
*/
9-
export const findNodesOfType = (graph: FlowGraph, type: string) =>
10-
graph.nodes.filter((node) => node.type === type);
9+
export const findNodesOfType = (graph: Graph, type: string) =>
10+
Object.values(graph.nodes).filter((node) => node.factory.type === type);
1111

12-
export const findOutEdges = (graph: FlowGraph, id: string) =>
13-
graph.edges.filter((edge) => edge.source === id);
12+
export const findOutEdges = (graph: Graph, id: string) =>
13+
Object.values(graph.edges).filter((edge) => edge.source === id);
1414

1515
/**
1616
* Converts the array of nodes in the graph to a lookup for O(1) performance
1717
* @param graph
1818
* @returns
1919
*/
20-
export const toNodeLookup = (graph: FlowGraph): Record<string, Node> =>
21-
graph.nodes.reduce((acc, node) => {
20+
export const toNodeLookup = (graph: Graph): Record<string, Node> =>
21+
Object.values(graph.nodes).reduce((acc, node) => {
2222
acc[node.id] = node;
2323
return acc;
2424
}, {});
@@ -28,8 +28,8 @@ export const toNodeLookup = (graph: FlowGraph): Record<string, Node> =>
2828
* @param graph
2929
* @returns
3030
*/
31-
export const toEdgeLookup = (graph: FlowGraph): Record<string, Edge> =>
32-
graph.edges.reduce((acc, edge) => {
31+
export const toEdgeLookup = (graph: Graph): Record<string, Edge> =>
32+
Object.values(graph.edges).reduce((acc, edge) => {
3333
acc[edge.id] = edge;
3434
return acc;
3535
}, {});
@@ -48,19 +48,19 @@ export type SourceToTarget = {
4848
* @returns
4949
*/
5050
export const findSourceToTargetOfType = (
51-
graph: FlowGraph,
51+
graph: Graph,
5252
sourceType: string,
5353
targetType: string
5454
): SourceToTarget[] => {
5555
const nodeLookup = toNodeLookup(graph);
5656

57-
return graph.nodes
58-
.filter((node) => node.type === sourceType)
57+
return Object.values(graph.nodes)
58+
.filter((node) => node.factory.type === sourceType)
5959
.reduce((acc, node) => {
6060
const edges = findOutEdges(graph, node.id);
6161

6262
const foundTargets = edges
63-
.filter((edge) => nodeLookup[edge.target].type === targetType)
63+
.filter((edge) => nodeLookup[edge.target].factory.type === targetType)
6464
.map((edge) => {
6565
return {
6666
source: node,

0 commit comments

Comments
 (0)