-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathAddPolicyEngineScreen.tsx
More file actions
38 lines (36 loc) · 1.23 KB
/
AddPolicyEngineScreen.tsx
File metadata and controls
38 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { PolicyEngineNameSchema } from '../../../../schema';
import { Panel, Screen, TextInput } from '../../components';
import { HELP_TEXT } from '../../constants';
import { generateUniqueName } from '../../utils';
import type { AddPolicyEngineConfig } from './types';
import React from 'react';
interface AddPolicyEngineScreenProps {
onComplete: (config: AddPolicyEngineConfig) => void;
onExit: () => void;
existingEngineNames: string[];
initialName?: string;
headerContent?: React.ReactNode;
}
export function AddPolicyEngineScreen({
onComplete,
onExit,
existingEngineNames,
initialName,
headerContent,
}: AddPolicyEngineScreenProps) {
return (
<Screen title="Add Policy Engine" onExit={onExit} helpText={HELP_TEXT.TEXT_INPUT} headerContent={headerContent}>
<Panel>
<TextInput
key="name"
prompt="Policy engine name"
initialValue={initialName ?? generateUniqueName('MyPolicyEngine', existingEngineNames)}
onSubmit={name => onComplete({ name })}
onCancel={onExit}
schema={PolicyEngineNameSchema}
customValidation={value => !existingEngineNames.includes(value) || 'Policy engine name already exists'}
/>
</Panel>
</Screen>
);
}