Skip to content

Commit 870a09f

Browse files
author
Jicheng Lu
committed
add topology
1 parent b176710 commit 870a09f

3 files changed

Lines changed: 77 additions & 33 deletions

File tree

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
* @property {string} trigger_name
232232
* @property {string?} [displayName]
233233
* @property {boolean} disabled
234+
* @property {any?} [config]
234235
* @property {any?} [output_args]
235236
* @property {string?} [json_args]
236237
* @property {string?} [statement]

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import { slide } from 'svelte/transition';
44
import { Input } from '@sveltestrap/sveltestrap';
55
import Markdown from '$lib/common/markdown/Markdown.svelte';
6-
import CodeScript from '$lib/common/shared/CodeScript.svelte';
76
import BotsharpTooltip from '$lib/common/tooltip/BotsharpTooltip.svelte';
87
import { ADMIN_ROLES } from '$lib/helpers/constants';
98
109
const svelteDispatch = createEventDispatcher();
1110
1211
const duration = 200;
13-
const textLimit = 1024;
1412
1513
/** @type {import('$agentTypes').AgentRule} */
1614
export let rule;
@@ -27,8 +25,8 @@
2725
/** @type {any[]} */
2826
export let ruleOptions = [];
2927
30-
/** @type {any} */
31-
export let configOptions = {};
28+
/** @type {any[]} */
29+
export let configOptions = [];
3230
3331
/** @type {number} */
3432
export let windowWidth;
@@ -75,11 +73,11 @@
7573
});
7674
}
7775
78-
function compileCodeScript() {
79-
svelteDispatch('compile', {
80-
rule: rule
81-
});
82-
}
76+
// function compileCodeScript() {
77+
// svelteDispatch('compile', {
78+
// rule: rule
79+
// });
80+
// }
8381
8482
function toggleConfig() {
8583
svelteDispatch('config', {
@@ -140,7 +138,7 @@
140138
</div>
141139
{/if}
142140
143-
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && Object.keys(configOptions || {}).length > 0}
141+
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && rule.config?.topology_provider}
144142
<!-- svelte-ignore a11y-no-static-element-interactions -->
145143
<div class="line-align-center">
146144
<!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -186,6 +184,31 @@
186184
{#if !collapsed}
187185
<div class="utility-row utility-row-secondary" transition:slide={{ duration: duration }}>
188186
<div class="utility-content">
187+
<div class="utility-list-item">
188+
<div class="utility-label line-align-center">
189+
<div class="d-flex gap-1">
190+
<div class="line-align-center">
191+
{'Topology'}
192+
</div>
193+
<div class="line-align-center"></div>
194+
</div>
195+
</div>
196+
<div class="utility-value">
197+
<div class="utility-input line-align-center">
198+
<Input
199+
type="select"
200+
on:change={e => changeRule(e, 'topology')}
201+
>
202+
{#each [...configOptions] as option}
203+
<option value={`${option.name}`} selected={option.name == rule.config?.topology_provider}>
204+
{option.name}
205+
</option>
206+
{/each}
207+
</Input>
208+
</div>
209+
<div class="utility-delete line-align-center"></div>
210+
</div>
211+
</div>
189212
<!-- <div class="utility-list-item">
190213
<div class="utility-label line-align-center">
191214
<div class="d-flex gap-1">

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
let errorText = '';
3232
3333
/** @type {any} */
34-
let ruleConfig = {};
34+
let selectedRuleConfig = {};
35+
/** @type {any} */
36+
let ruleConfigs = {};
3537
3638
/** @type {import('$agentTypes').AgentModel} */
3739
export let agent;
@@ -47,6 +49,7 @@
4749
return {
4850
trigger_name: x.trigger_name,
4951
disabled: x.disabled,
52+
config: x.config,
5053
expanded: x.expanded
5154
};
5255
});
@@ -69,7 +72,7 @@
6972
let ruleOptions = [];
7073
7174
/** @type {any} */
72-
let configOptions = {};
75+
let configOptions = [];
7376
7477
/** @type {import('$agentTypes').AgentRule[]} */
7578
let innerRules = [];
@@ -120,7 +123,13 @@
120123
function loadAgentRuleConfigOptions() {
121124
return new Promise((resolve) => {
122125
getAgentRuleConfigOptions().then(data => {
123-
configOptions = data || {};
126+
ruleConfigs = data || {};
127+
const keys = Object.keys(data || {});
128+
const list = keys?.map(x => ({ name: x })) || [];
129+
configOptions = [
130+
{ name: '' },
131+
...list
132+
];
124133
resolve('done');
125134
});
126135
});
@@ -139,7 +148,13 @@
139148
if (field === 'rule') {
140149
found.trigger_name = value;
141150
innerRefresh(innerRules);
142-
}
151+
} else if (field === 'topology') {
152+
found.config = {
153+
...found.config || {},
154+
topology_provider: value
155+
};
156+
innerRefresh(innerRules);
157+
}
143158
144159
// else if (field === 'criteria') {
145160
// const name = value.split('#')[0];
@@ -362,25 +377,30 @@
362377
*/
363378
function openRuleConfigModal(e, uid) {
364379
const found = innerRules.find((_, index) => index === uid);
365-
if (!found) return;
366-
367-
const graph = configOptions['membase'];
368-
const params = JSON.stringify({
369-
agent: agent.name,
370-
agent_id: agent.id,
371-
trigger: found.trigger_name || ""
372-
});
373-
const url = new URL(graph.url, window.location.origin);
374-
url.searchParams.set('parameters', params);
375-
console.log(url.toString());
380+
if (!found || !found.config?.topology_provider) {
381+
return;
382+
}
376383
377-
ruleConfig = {
378-
url: url.toString(),
379-
rule: found,
380-
title: `${found.trigger_name} config`
381-
};
384+
const config = ruleConfigs[found.config.topology_provider];
385+
const customParam = config.customParameters || {};
382386
383-
isOpenConfigModal = true;
387+
if (customParam.htmlTag === 'iframe') {
388+
const params = JSON.stringify({
389+
agent: agent.name,
390+
agentId: agent.id,
391+
trigger: found.trigger_name || ""
392+
});
393+
const url = new URL(customParam.url, window.location.origin);
394+
url.searchParams.set(customParam.appendParameterName || 'parameters', encodeURIComponent(params));
395+
396+
selectedRuleConfig = {
397+
agent: agent.name,
398+
url: url.toString(),
399+
rule: found,
400+
title: `${found.trigger_name} config`
401+
};
402+
isOpenConfigModal = true;
403+
}
384404
}
385405
386406
function resizeWindow() {
@@ -402,12 +422,12 @@
402422
{#if isOpenConfigModal}
403423
<PlainModal
404424
containerClasses={'rule-config-modal'}
405-
title={ruleConfig?.rule?.trigger_name || ''}
425+
title={selectedRuleConfig?.rule?.trigger_name || ''}
406426
size={'xl'}
407427
isOpen={isOpenConfigModal}
408428
toggleModal={() => isOpenConfigModal = !isOpenConfigModal}
409429
>
410-
<iframe src={ruleConfig.url} title={ruleConfig.title} width="100%" height="100%" />
430+
<iframe src={selectedRuleConfig.url} title={selectedRuleConfig.title} width="100%" height="100%" />
411431
</PlainModal>
412432
{/if}
413433

0 commit comments

Comments
 (0)