Skip to content

Commit 9f3ee6d

Browse files
committed
style(ui): run prettier on template control files
1 parent a15e385 commit 9f3ee6d

9 files changed

Lines changed: 119 additions & 72 deletions

File tree

‎ui/src/core/components/template-param-form.tsx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import type {
1414
TemplateValue,
1515
} from '@/core/api/types';
1616

17-
import {
18-
labelPropsInline,
19-
LabelWithTooltip,
20-
} from './label-with-tooltip';
17+
import { labelPropsInline, LabelWithTooltip } from './label-with-tooltip';
2118

2219
type TemplateParamFormProps = {
2320
template: TemplateDefinition;

‎ui/src/core/components/template-preview.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export function TemplatePreview({
5353
});
5454
if (result?.control) {
5555
// Strip template authoring metadata — show only what the engine sees.
56-
const { template: _t, template_values: _tv, ...rendered } = result.control as Record<string, unknown>;
56+
const {
57+
template: _t,
58+
template_values: _tv,
59+
...rendered
60+
} = result.control as Record<string, unknown>;
5761
setRenderedJson(JSON.stringify(rendered, null, 2));
5862
onErrors?.({});
5963
}

‎ui/src/core/hooks/query-hooks/use-render-template.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import type { RenderControlTemplateRequest } from '@/core/api/types';
1010
export function useRenderTemplate() {
1111
return useMutation({
1212
mutationFn: async (request: RenderControlTemplateRequest) => {
13-
const { data, error, response } = await api.controlTemplates.render(
14-
request
15-
);
13+
const { data, error, response } =
14+
await api.controlTemplates.render(request);
1615

1716
if (error) {
1817
throw parseApiError(

‎ui/src/core/page-components/agent-detail/controls/table-columns.tsx‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ export function useControlsTableColumns({
6969
onError: (error: Error) => {
7070
notifications.show({
7171
title: 'Failed to update control',
72-
message: error.message || 'An unexpected error occurred',
72+
message:
73+
error.message || 'An unexpected error occurred',
7374
color: 'red',
7475
});
7576
},
@@ -78,17 +79,24 @@ export function useControlsTableColumns({
7879
if (isTemplate) {
7980
// Template-backed controls use PATCH to avoid 409 on PUT /data
8081
updateControlMetadata.mutate(
81-
{ agentId, controlId: control.id, data: { enabled: newEnabled } },
82-
callbacks,
82+
{
83+
agentId,
84+
controlId: control.id,
85+
data: { enabled: newEnabled },
86+
},
87+
callbacks
8388
);
8489
} else {
8590
updateControl.mutate(
8691
{
8792
agentId,
8893
controlId: control.id,
89-
definition: { ...control.control, enabled: newEnabled },
94+
definition: {
95+
...control.control,
96+
enabled: newEnabled,
97+
},
9098
},
91-
callbacks,
99+
callbacks
92100
);
93101
}
94102
},
@@ -104,7 +112,9 @@ export function useControlsTableColumns({
104112
accessorKey: 'name',
105113
size: 280,
106114
cell: ({ row }: { row: { original: Control } }) => {
107-
const ctrl = row.original.control as Record<string, unknown> | undefined;
115+
const ctrl = row.original.control as
116+
| Record<string, unknown>
117+
| undefined;
108118
const isTemplate = ctrl?.template != null;
109119
return (
110120
<Group gap={6} wrap="nowrap">

‎ui/src/core/page-components/agent-detail/modals/add-new-control/index.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export function AddNewControlModal({
123123
});
124124
};
125125

126-
127126
const handleEditModalClose = () => {
128127
closeSubmodal();
129128
};
@@ -361,7 +360,6 @@ export function AddNewControlModal({
361360
) : null}
362361
</ErrorBoundary>
363362
</Modal>
364-
365363
</Modal>
366364
);
367365
}

‎ui/src/core/page-components/agent-detail/modals/create-from-template/index.tsx‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ function parseTemplateJson(text: string): TemplateDefinition | string {
5353
if (!obj.definition_template) {
5454
return 'Missing required field "definition_template".';
5555
}
56-
if (typeof obj.definition_template !== 'object' || obj.definition_template === null) {
56+
if (
57+
typeof obj.definition_template !== 'object' ||
58+
obj.definition_template === null
59+
) {
5760
return '"definition_template" must be a JSON object.';
5861
}
5962
// parameters is optional (defaults to empty dict on the server)
6063
if (obj.parameters !== undefined) {
61-
if (typeof obj.parameters !== 'object' || obj.parameters === null || Array.isArray(obj.parameters)) {
64+
if (
65+
typeof obj.parameters !== 'object' ||
66+
obj.parameters === null ||
67+
Array.isArray(obj.parameters)
68+
) {
6269
return '"parameters" must be a JSON object.';
6370
}
6471
}
@@ -125,12 +132,9 @@ export function CreateFromTemplate({
125132
setApiError(null);
126133
};
127134

128-
const handlePreviewErrors = useCallback(
129-
(errors: Record<string, string>) => {
130-
setParamErrors(errors);
131-
},
132-
[]
133-
);
135+
const handlePreviewErrors = useCallback((errors: Record<string, string>) => {
136+
setParamErrors(errors);
137+
}, []);
134138

135139
const handleSave = () => {
136140
if (!template) return;
@@ -170,10 +174,7 @@ export function CreateFromTemplate({
170174
const newParamErrors: Record<string, string> = {};
171175
for (const item of pd.errors) {
172176
if (item.field?.startsWith('template_values.')) {
173-
const paramName = item.field.replace(
174-
'template_values.',
175-
''
176-
);
177+
const paramName = item.field.replace('template_values.', '');
177178
newParamErrors[paramName] = item.message;
178179
}
179180
}
@@ -204,7 +205,11 @@ export function CreateFromTemplate({
204205
<Title order={3} fw={600}>
205206
Create from Template
206207
</Title>
207-
<Button size="sm" onClick={onClose} data-testid="close-template-modal-button">
208+
<Button
209+
size="sm"
210+
onClick={onClose}
211+
data-testid="close-template-modal-button"
212+
>
208213
<IconX size={16} />
209214
</Button>
210215
</Group>
@@ -256,10 +261,18 @@ export function CreateFromTemplate({
256261
/>
257262

258263
<Group justify="flex-end">
259-
<Button variant="outline" onClick={onClose} data-testid="cancel-template-paste">
264+
<Button
265+
variant="outline"
266+
onClick={onClose}
267+
data-testid="cancel-template-paste"
268+
>
260269
Cancel
261270
</Button>
262-
<Button variant="filled" onClick={handleContinue} data-testid="continue-template">
271+
<Button
272+
variant="filled"
273+
onClick={handleContinue}
274+
data-testid="continue-template"
275+
>
263276
Continue
264277
</Button>
265278
</Group>
@@ -332,7 +345,11 @@ export function CreateFromTemplate({
332345
<Divider />
333346

334347
<Group justify="flex-end">
335-
<Button variant="outline" onClick={onClose} data-testid="cancel-template-create">
348+
<Button
349+
variant="outline"
350+
onClick={onClose}
351+
data-testid="cancel-template-create"
352+
>
336353
Cancel
337354
</Button>
338355
<Button

‎ui/src/core/page-components/agent-detail/modals/edit-control/template-edit-content.tsx‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ export function TemplateEditContent({
5454
// generated API types yet. Will be cleaned up after type regeneration.
5555
const definitionRaw = control.control as Record<string, unknown>;
5656
const template = definitionRaw.template as TemplateControlInput['template'];
57-
const storedValues = definitionRaw.template_values as Record<
58-
string,
59-
TemplateValue
60-
> | undefined;
57+
const storedValues = definitionRaw.template_values as
58+
| Record<string, TemplateValue>
59+
| undefined;
6160

6261
const [editorMode, setEditorMode] = useState<EditorMode>('params');
6362
const [controlName, setControlName] = useState(control.name);
@@ -76,12 +75,9 @@ export function TemplateEditContent({
7675
const updateControlMetadata = useUpdateControlMetadata();
7776
const isPending = updateControl.isPending || updateControlMetadata.isPending;
7877

79-
const handlePreviewErrors = useCallback(
80-
(errors: Record<string, string>) => {
81-
setParamErrors(errors);
82-
},
83-
[]
84-
);
78+
const handlePreviewErrors = useCallback((errors: Record<string, string>) => {
79+
setParamErrors(errors);
80+
}, []);
8581

8682
const buildTemplateInput = useCallback((): TemplateControlInput => {
8783
return {
@@ -107,14 +103,18 @@ export function TemplateEditContent({
107103
try {
108104
const parsed = JSON.parse(jsonText) as TemplateControlInput;
109105
if (!parsed.template?.definition_template) {
110-
setJsonError('JSON must contain a "template" object with "definition_template".');
106+
setJsonError(
107+
'JSON must contain a "template" object with "definition_template".'
108+
);
111109
return;
112110
}
113111
setTemplateValues(parsed.template_values ?? {});
114112
setJsonError(null);
115113
setEditorMode('params');
116114
} catch {
117-
setJsonError('Invalid JSON. Fix syntax errors before switching to Parameters.');
115+
setJsonError(
116+
'Invalid JSON. Fix syntax errors before switching to Parameters.'
117+
);
118118
}
119119
};
120120

@@ -131,7 +131,9 @@ export function TemplateEditContent({
131131
try {
132132
templateInput = JSON.parse(jsonText) as TemplateControlInput;
133133
if (!templateInput.template?.definition_template) {
134-
setJsonError('JSON must contain a "template" object with "definition_template".');
134+
setJsonError(
135+
'JSON must contain a "template" object with "definition_template".'
136+
);
135137
return;
136138
}
137139
} catch {
@@ -212,10 +214,7 @@ export function TemplateEditContent({
212214
const newParamErrors: Record<string, string> = {};
213215
for (const item of pd.errors) {
214216
if (item.field?.startsWith('template_values.')) {
215-
const paramName = item.field.replace(
216-
'template_values.',
217-
''
218-
);
217+
const paramName = item.field.replace('template_values.', '');
219218
newParamErrors[paramName] = item.message;
220219
}
221220
}
@@ -239,7 +238,8 @@ export function TemplateEditContent({
239238
};
240239

241240
// Extract read-only summary from the rendered control
242-
const action = (definitionRaw.action as { decision?: string })?.decision ?? 'unknown';
241+
const action =
242+
(definitionRaw.action as { decision?: string })?.decision ?? 'unknown';
243243
const execution = (definitionRaw.execution as string) ?? 'server';
244244
const description = definitionRaw.description as string | undefined;
245245

@@ -281,7 +281,8 @@ export function TemplateEditContent({
281281
{editorMode === 'json' ? (
282282
<Stack gap="md">
283283
<Text size="sm" c="dimmed">
284-
Edit the full template input JSON below. Control name stays separate.
284+
Edit the full template input JSON below. Control name stays
285+
separate.
285286
</Text>
286287
<Textarea
287288
value={jsonText}
@@ -336,8 +337,8 @@ export function TemplateEditContent({
336337
) : null}
337338
<Alert variant="light" color="blue" p="xs">
338339
<Text size="xs">
339-
Scope, condition, and action are managed by the template.
340-
Edit the parameters on the right to change control behavior.
340+
Scope, condition, and action are managed by the template. Edit
341+
the parameters on the right to change control behavior.
341342
</Text>
342343
</Alert>
343344
</Stack>

‎ui/tests/control-templates.spec.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ test.describe('Control Templates', () => {
4747
await mockedPage.goto(controlsUrl);
4848

4949
// Then: the template-backed control row shows a "Template" badge
50-
const badge = mockedPage.locator('table').getByText('Template', { exact: true });
50+
const badge = mockedPage
51+
.locator('table')
52+
.getByText('Template', { exact: true });
5153
await expect(badge).toBeVisible();
5254
});
5355

@@ -60,7 +62,9 @@ test.describe('Control Templates', () => {
6062
await mockedPage.goto(controlsUrl);
6163

6264
// Then: no "Template" badge appears anywhere in the table
63-
const badges = mockedPage.locator('table').getByText('Template', { exact: true });
65+
const badges = mockedPage
66+
.locator('table')
67+
.getByText('Template', { exact: true });
6468
await expect(badges).toHaveCount(0);
6569
});
6670
});
@@ -99,7 +103,9 @@ test.describe('Control Templates', () => {
99103

100104
// Then: the Template badge is visible in the dialog header
101105
const dialog = mockedPage.getByRole('dialog');
102-
await expect(dialog.getByText('Template', { exact: true }).first()).toBeVisible();
106+
await expect(
107+
dialog.getByText('Template', { exact: true }).first()
108+
).toBeVisible();
103109
});
104110

105111
test('shows Parameters and Full JSON mode switcher', async ({
@@ -113,8 +119,12 @@ test.describe('Control Templates', () => {
113119

114120
// Then: both mode options are visible in the segmented control
115121
const dialog = mockedPage.getByRole('dialog');
116-
await expect(dialog.getByText('Parameters', { exact: true })).toBeVisible();
117-
await expect(dialog.locator('label').getByText('Full JSON')).toBeVisible();
122+
await expect(
123+
dialog.getByText('Parameters', { exact: true })
124+
).toBeVisible();
125+
await expect(
126+
dialog.locator('label').getByText('Full JSON')
127+
).toBeVisible();
118128
});
119129

120130
test('can toggle to Full JSON mode and see template JSON', async ({
@@ -166,9 +176,13 @@ test.describe('Control Templates', () => {
166176

167177
// Then: the left panel shows rendered control metadata as read-only
168178
const dialog = mockedPage.getByRole('dialog');
169-
await expect(dialog.getByText('Deny when input matches pattern')).toBeVisible();
179+
await expect(
180+
dialog.getByText('Deny when input matches pattern')
181+
).toBeVisible();
170182
await expect(dialog.getByText('Regex denial template')).toBeVisible();
171-
await expect(dialog.locator('.mantine-Badge-root').getByText('deny')).toBeVisible();
183+
await expect(
184+
dialog.locator('.mantine-Badge-root').getByText('deny')
185+
).toBeVisible();
172186
});
173187

174188
test('control name field is pre-filled and editable', async ({
@@ -240,7 +254,9 @@ test.describe('Control Templates', () => {
240254

241255
// And: template-specific elements are NOT shown
242256
await expect(dialog.getByText('Template Parameters')).not.toBeVisible();
243-
await expect(dialog.getByText(/managed by the template/)).not.toBeVisible();
257+
await expect(
258+
dialog.getByText(/managed by the template/)
259+
).not.toBeVisible();
244260
});
245261

246262
test('raw control edit does not show Parameters toggle', async ({
@@ -253,7 +269,9 @@ test.describe('Control Templates', () => {
253269

254270
// Then: the "Parameters" toggle (template-only) is not visible
255271
const dialog = mockedPage.getByRole('dialog');
256-
await expect(dialog.getByText('Parameters', { exact: true })).not.toBeVisible();
272+
await expect(
273+
dialog.getByText('Parameters', { exact: true })
274+
).not.toBeVisible();
257275
});
258276
});
259277

0 commit comments

Comments
 (0)