File size: 3,814 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { PropertyType } from '../../../backend/adapters/property/base-property.js'

export type PropertyPlace = 'show' | 'list' | 'edit' | 'filter';

/**
 * JSON representation of a Property.
 * @subcategory Frontend
 */
export interface PropertyJSON {
  /**
   * If given property should be treated as a title
   */
  isTitle: boolean;
  /**
   * If given property should be treated as a Id field
   */
  isId: boolean;
  /**
   * Property position on a list
   */
  position: number;
  /**
   * If property is sortable
   */
  isSortable: boolean;
  /**
   * If property has restricted number of values
   */
  availableValues: Array<{label?: string; value: string | number}> | null;
  /**
   * Property uniq name
   */
  name: string;
  /**
   * Property uniq path. For top level properties - the same as name, but for nested
   * properties it is separated with dot notation: `nested.property`
   */
  propertyPath: string;
  /**
   * Path of the actual value inside the record. It is usually the same as propertyPath, with the
   * exception of array values.
   */
  path: string;
  /**
   * Property label
   */
  label: string;
  /**
   * Description of field. Shown as hoverable hint after label.
   *
   * To use translations provide it in locale with specified options key from resource
   * @example
   * ```js
   * new AdminJS({
   *   resources: [
   *     {
   *       resource: myResource,
   *       options: {
   *         properties: {
   *           myAwesomeProperty: {
   *             description: "Plane description" || "awesomeHint", // <- message key in locale
   *           },
   *         },
   *       },
   *     },
   *   ],
   *   locale: {
   *     translations: {
   *       resources: {
   *         myResource: {
   *           messages: {
   *             awesomeHint: "Locale description",
   *           },
   *         },
   *       },
   *     },
   *   },
   * });
   * ```
   */
  description?: string;
  /**
   * One of {@link PropertyType}s
   */
  type: PropertyType;
  /**
   * Has a name of a resource to which it is a reference.
   * For instance property `userId` will have here `Users`
   */
  reference: string | null;
  /**
   * Indicates if property is an array of properties
   */
  isArray: boolean;
  /**
   * Indicates if array elements should be draggable when editing.
   * It is only usable if the property is an array.
   */
  isDraggable: boolean;
  /**
   * Contain list of all sub properties.
   * This is the case for nested schemas in MongoDB.
   */
  subProperties: Array<BasePropertyJSON>;
  /**
   * All component names overridden by the user in PropertyOptions
   */
  components?: {
    show?: string;
    edit?: string;
    filter?: string;
    list?: string;
  };

  /**
   * Custom parameters passed from the {@link PropertyOptions.custom}.
   */
  custom: {
    [key: string]: any;
  };

  /**
   * Additional props passed to the actual react component
   */
  props: {
    [key: string]: any;
  };

  /**
   * Whether the field should be disabled in edition
   */
  isDisabled: boolean;

  /**
   * Whether the field should be marked as required (with a star)
   */
  isRequired: boolean;

  /**
   * if label above the input should be hidden
   */
  hideLabel: boolean;

  /**
   * Resource to which given property belongs
   */
  resourceId: string;

  /**
   * Indicates if given property has been created in AdminJS {@link PropertyOptions} and hasn't
   * been returned by the database adapter.
   */
  isVirtual: boolean;
}

export type BasePropertyJSON = Omit<PropertyJSON, 'path'>

/**
 * Property without the path. Defined as `Omit<PropertyJSON, 'path'>`
 *
 * @typedef {Object} BasePropertyJSON
 * @property {any} ...   properties from {@link PropertyJSON} except `path`
 * @alias BasePropertyJSON
 * @memberof PropertyJSON
 */