@industream/flowmaker-flowbox-ui-components 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -22,129 +22,85 @@ npm install @industream/flowmaker-flowbox-ui-components
|
|
|
22
22
|
|
|
23
23
|
A dropdown component that fetches and displays source connections from the DataCatalog API, allowing users to select a data source for their FlowBox configuration.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { DCSourceConnection, type SourceConnection } from '@industream/flowmaker-flowbox-ui-components';
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
##### Props
|
|
32
|
-
|
|
33
|
-
| Prop | Type | Default | Description |
|
|
34
|
-
|------|------|---------|-------------|
|
|
35
|
-
| `dcapiurl` | `string` | `''` | Base URL of the DataCatalog API |
|
|
36
|
-
| `sourcetypefilter` | `string \| string[] \| null` | `null` | Filter connections by source type(s) |
|
|
37
|
-
| `onsourceselect` | `(connection: SourceConnection) => void` | `null` | Callback when a connection is selected |
|
|
38
|
-
| `onitemsloaded` | `(connections: SourceConnection[]) => void` | `null` | Callback when connections are loaded |
|
|
39
|
-
|
|
40
|
-
##### Exported Methods
|
|
41
|
-
|
|
42
|
-
| Method | Signature | Description |
|
|
43
|
-
|--------|-----------|-------------|
|
|
44
|
-
| `select` | `(idOrConnection: string \| SourceConnection) => void` | Programmatically select a connection |
|
|
45
|
-
| `getSelection` | `() => SourceConnection \| null` | Get the currently selected connection |
|
|
46
|
-
| `getConnections` | `() => SourceConnection[]` | Get all loaded connections |
|
|
25
|
+
### Quick Start
|
|
47
26
|
|
|
48
|
-
|
|
27
|
+
```svelte
|
|
28
|
+
<script>
|
|
29
|
+
let conn = $state('');
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
Selection: {{ conn }}
|
|
49
33
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
[key: string]: any;
|
|
56
|
-
}
|
|
34
|
+
<DCSourceConnection
|
|
35
|
+
dcapiurl="http://localhost:8002"
|
|
36
|
+
sourcetypefilter="DataBridge"
|
|
37
|
+
onsourceselect={(newValue) => conn = newvalue}
|
|
38
|
+
/>
|
|
57
39
|
```
|
|
58
40
|
|
|
59
|
-
#####
|
|
60
|
-
|
|
61
|
-
This example shows how to integrate `DCSourceConnection` into a FlowBox configuration form using `@industream/flowmaker-flowbox-ui`.
|
|
41
|
+
##### Environment Configuration with `jsonEnv`
|
|
62
42
|
|
|
63
43
|
```svelte
|
|
64
|
-
<script
|
|
44
|
+
<script>
|
|
65
45
|
import { flowMakerBridge } from '@industream/flowmaker-flowbox-ui';
|
|
66
|
-
import { DCSourceConnection
|
|
46
|
+
import { DCSourceConnection } from '@industream/flowmaker-flowbox-ui-components';
|
|
67
47
|
|
|
68
48
|
const props = $props();
|
|
69
|
-
const {
|
|
70
|
-
|
|
71
|
-
// Get DC API URL from context (passed by FlowMaker)
|
|
72
|
-
const dcApiUrl = $derived($context?.dcApiUrl || 'http://localhost:8002');
|
|
73
|
-
|
|
74
|
-
// Optional: filter by source type
|
|
75
|
-
const sourceTypeFilter = $derived($context?.sourceTypeFilter || null);
|
|
49
|
+
const { values, jsonEnv } = flowMakerBridge(props);
|
|
76
50
|
|
|
77
|
-
//
|
|
78
|
-
|
|
51
|
+
// Get DataCatalog config from environment variables (reactive derived store)
|
|
52
|
+
const dcApiUrl = jsonEnv('datacatalog');
|
|
79
53
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
$values.sourceConnectionId = connection.id;
|
|
83
|
-
|
|
84
|
-
// Optionally store more details
|
|
85
|
-
$values.sourceConnectionName = connection.name;
|
|
86
|
-
$values.sourceType = connection.sourceType?.name;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function handleItemsLoaded(connections: SourceConnection[]) {
|
|
90
|
-
// Restore previous selection if exists
|
|
91
|
-
if ($values.sourceConnectionId) {
|
|
92
|
-
dcSourceConnection.select($values.sourceConnectionId);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
54
|
+
// Source type filter (can also come from context/values/environment)
|
|
55
|
+
const sourceTypeFilter = "MQTT";
|
|
95
56
|
</script>
|
|
96
57
|
|
|
97
|
-
<div class="
|
|
98
|
-
<
|
|
58
|
+
<div class="dc-selector-container">
|
|
59
|
+
<div>Data Catalog Source Connection</div>
|
|
99
60
|
|
|
100
61
|
<DCSourceConnection
|
|
101
|
-
dcapiurl={dcApiUrl}
|
|
62
|
+
dcapiurl={$dcApiUrl?.url}
|
|
102
63
|
sourcetypefilter={sourceTypeFilter}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
bind:this={dcSourceConnection}
|
|
64
|
+
initialselection={$values?.sourceConnectionId ?? ''}
|
|
65
|
+
onsourceselect={(conn) => $values.sourceConnectionId = conn.id}
|
|
106
66
|
/>
|
|
107
67
|
|
|
108
68
|
{#if $values.sourceConnectionId}
|
|
109
69
|
<div class="selection-info">
|
|
110
|
-
<
|
|
111
|
-
<p><strong>
|
|
70
|
+
<h5>Selected Connection</h5>
|
|
71
|
+
<p><strong>ID:</strong> {$values.sourceConnectionId}</p>
|
|
112
72
|
</div>
|
|
113
73
|
{/if}
|
|
114
74
|
</div>
|
|
115
|
-
|
|
116
|
-
<style>
|
|
117
|
-
.config-form {
|
|
118
|
-
display: flex;
|
|
119
|
-
flex-direction: column;
|
|
120
|
-
gap: 1rem;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.selection-info {
|
|
124
|
-
padding: 1rem;
|
|
125
|
-
background: var(--cds-layer-01, #393939);
|
|
126
|
-
border-radius: 4px;
|
|
127
|
-
}
|
|
128
|
-
</style>
|
|
129
75
|
```
|
|
130
76
|
|
|
131
|
-
##### Context Configuration
|
|
132
77
|
|
|
133
|
-
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
The `jsonEnv(key)` helper from `flowMakerBridge` parses JSON environment variables from `context.environmentVars["environment/{key}"]`. It returns a reactive derived store that updates when context changes.
|
|
81
|
+
|
|
82
|
+
```svelte
|
|
83
|
+
<script>
|
|
84
|
+
const { jsonEnv } = flowMakerBridge(props);
|
|
85
|
+
|
|
86
|
+
// Returns a derived store - use with $ prefix
|
|
87
|
+
const dcConfig = jsonEnv('datacatalog');
|
|
88
|
+
|
|
89
|
+
// Reactively access parsed values
|
|
90
|
+
const apiUrl = $derived($dcConfig?.url ?? null);
|
|
91
|
+
</script>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The environment variable `environment/datacatalog` should contain a JSON string:
|
|
134
95
|
|
|
135
96
|
```json
|
|
136
97
|
{
|
|
137
|
-
"
|
|
138
|
-
"dcApiUrl": "https://datacatalog.example.com/api",
|
|
139
|
-
"sourceTypeFilter": ["Mqtt", "DataBridge"]
|
|
140
|
-
}
|
|
98
|
+
"url": "https://datacatalog.example.com/api",
|
|
141
99
|
}
|
|
142
100
|
```
|
|
143
101
|
|
|
144
102
|
##### Filtering by Source Type
|
|
145
103
|
|
|
146
|
-
Filter to show only specific source types:
|
|
147
|
-
|
|
148
104
|
```svelte
|
|
149
105
|
<!-- Single type -->
|
|
150
106
|
<DCSourceConnection
|
|
@@ -177,3 +133,45 @@ const selected = dcSourceConnection.getSelection();
|
|
|
177
133
|
const all = dcSourceConnection.getConnections();
|
|
178
134
|
```
|
|
179
135
|
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## API Reference
|
|
139
|
+
|
|
140
|
+
### DCSourceConnection
|
|
141
|
+
|
|
142
|
+
##### Import
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { DCSourceConnection, type SourceConnection } from '@industream/flowmaker-flowbox-ui-components';
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
##### Props
|
|
149
|
+
|
|
150
|
+
| Prop | Type | Default | Description |
|
|
151
|
+
|------|------|---------|-------------|
|
|
152
|
+
| `dcapiurl` | `string` | `''` | Base URL of the DataCatalog API |
|
|
153
|
+
| `sourcetypefilter` | `string \| string[] \| null` | `null` | Filter connections by source type(s) |
|
|
154
|
+
| `initialselection` | `string \| null` | `null` | ID to auto-select when items load |
|
|
155
|
+
| `onsourceselect` | `(connection: SourceConnection) => void` | `null` | Callback when a connection is selected |
|
|
156
|
+
| `onitemsloaded` | `(connections: SourceConnection[]) => void` | `null` | Callback when connections are loaded |
|
|
157
|
+
|
|
158
|
+
The `initialselection` prop automatically restores the selection when items are loaded - no need for `onitemsloaded` handler.
|
|
159
|
+
|
|
160
|
+
##### Exported Methods
|
|
161
|
+
|
|
162
|
+
| Method | Signature | Description |
|
|
163
|
+
|--------|-----------|-------------|
|
|
164
|
+
| `select` | `(idOrConnection: string \| SourceConnection) => void` | Programmatically select a connection |
|
|
165
|
+
| `getSelection` | `() => SourceConnection \| null` | Get the currently selected connection |
|
|
166
|
+
| `getConnections` | `() => SourceConnection[]` | Get all loaded connections |
|
|
167
|
+
|
|
168
|
+
##### Types
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
interface SourceConnection {
|
|
172
|
+
id: string;
|
|
173
|
+
name: string;
|
|
174
|
+
sourceType?: { name: string };
|
|
175
|
+
[key: string]: any;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
interface Props {
|
|
12
12
|
dcapiurl?: string;
|
|
13
13
|
sourcetypefilter?: string | string[] | null;
|
|
14
|
+
initialselection?: string | null;
|
|
14
15
|
onsourceselect?: (connection: SourceConnection) => void;
|
|
15
16
|
onitemsloaded?: (connections: SourceConnection[]) => void;
|
|
16
17
|
}
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
let {
|
|
19
20
|
dcapiurl = '',
|
|
20
21
|
sourcetypefilter = null,
|
|
22
|
+
initialselection = null,
|
|
21
23
|
onsourceselect = null,
|
|
22
24
|
onitemsloaded = null
|
|
23
25
|
}: Props = $props();
|
|
@@ -62,6 +64,12 @@
|
|
|
62
64
|
const result = await client.sourceConnections.get(filters);
|
|
63
65
|
sourceConnections = result.items || [];
|
|
64
66
|
console.log('Loaded source connections:', sourceConnections);
|
|
67
|
+
|
|
68
|
+
// Auto-select initial selection if provided
|
|
69
|
+
if (initialselection) {
|
|
70
|
+
select(initialselection);
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
onitemsloaded?.(sourceConnections);
|
|
66
74
|
} catch (e) {
|
|
67
75
|
console.error('Failed to load source connections:', e);
|
|
@@ -9,6 +9,7 @@ export interface SourceConnection {
|
|
|
9
9
|
interface Props {
|
|
10
10
|
dcapiurl?: string;
|
|
11
11
|
sourcetypefilter?: string | string[] | null;
|
|
12
|
+
initialselection?: string | null;
|
|
12
13
|
onsourceselect?: (connection: SourceConnection) => void;
|
|
13
14
|
onitemsloaded?: (connections: SourceConnection[]) => void;
|
|
14
15
|
}
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
interface Props {
|
|
12
12
|
dcapiurl?: string;
|
|
13
13
|
sourcetypefilter?: string | string[] | null;
|
|
14
|
+
initialselection?: string | null;
|
|
14
15
|
onsourceselect?: (connection: SourceConnection) => void;
|
|
15
16
|
onitemsloaded?: (connections: SourceConnection[]) => void;
|
|
16
17
|
}
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
let {
|
|
19
20
|
dcapiurl = '',
|
|
20
21
|
sourcetypefilter = null,
|
|
22
|
+
initialselection = null,
|
|
21
23
|
onsourceselect = null,
|
|
22
24
|
onitemsloaded = null
|
|
23
25
|
}: Props = $props();
|
|
@@ -62,6 +64,12 @@
|
|
|
62
64
|
const result = await client.sourceConnections.get(filters);
|
|
63
65
|
sourceConnections = result.items || [];
|
|
64
66
|
console.log('Loaded source connections:', sourceConnections);
|
|
67
|
+
|
|
68
|
+
// Auto-select initial selection if provided
|
|
69
|
+
if (initialselection) {
|
|
70
|
+
select(initialselection);
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
onitemsloaded?.(sourceConnections);
|
|
66
74
|
} catch (e) {
|
|
67
75
|
console.error('Failed to load source connections:', e);
|