-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandtypes.ts
More file actions
69 lines (62 loc) · 1.81 KB
/
commandtypes.ts
File metadata and controls
69 lines (62 loc) · 1.81 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { StructuredErrorResponse } from 'f61ui/types';
export enum CrudNature {
update = 'update',
delete = 'delete',
create = 'create',
}
// static (except for customFields) definition generated from commands.json
export interface CommandDefinition {
title: string;
key: string;
additional_confirmation?: string;
crudNature: CrudNature;
fields: CommandField[];
settings: CommandSettings;
info: string[];
customFields?: { [key: string]: CustomFieldInputFactory<any> };
}
// dynamic settings controlled by the calling code
export interface CommandSettings {
// so there's no hesitation of "did I pick the right row for this action?"
disambiguation?: string;
helpUrl?: string;
// if returns empty string, considered as error and form is not closed
redirect?: (id: string) => string;
error?: (err: StructuredErrorResponse, values: CommandValueCollection) => boolean;
}
export enum CommandFieldKind {
Text,
Password,
Multiline,
Checkbox,
Integer,
Date,
Any, // for custom datatypes (not same as custom components - don't have autogenerated UI component)
CustomString, // custom UI component (maybe autocomplete), yielding a string
CustomInteger, // custom UI component (maybe autocomplete), yielding a number
}
// T is type of the output value from the component
export type CustomFieldInputFactory<T> = (
field: CommandField,
value: T,
update: (val: T | undefined) => void,
autoFocus: boolean,
) => JSX.Element;
export interface CommandField {
Key: string;
Title: string;
Required: boolean;
HideIfDefaultValue: boolean;
Kind: CommandFieldKind;
Unit: string | null;
DefaultValueString?: string;
DefaultValueBoolean?: boolean;
DefaultValueNumber?: number;
DefaultValueAny?: any;
Help?: string;
Placeholder?: string;
ValidationRegex: string;
}
export interface CommandValueCollection {
[key: string]: any;
}