|
1 | 1 | <script module lang="ts"> |
2 | | - import { IndexType, OrderBy } from '@appwrite.io/console'; |
| 2 | + import { DatabasesIndexType, OrderBy } from '@appwrite.io/console'; |
3 | 3 | export type CreateIndexesCallbackType = { |
4 | 4 | key: string; |
5 | | - type: IndexType; |
| 5 | + type: DatabasesIndexType; |
6 | 6 | fields: string[]; |
7 | 7 | lengths: (number | null)[]; |
8 | 8 | orders: OrderBy[]; |
|
40 | 40 |
|
41 | 41 | let key = $state(''); |
42 | 42 | let initializedForOpen = $state(false); |
43 | | - let selectedType = $state<IndexType>(IndexType.Key); |
| 43 | + let selectedType = $state<DatabasesIndexType>(DatabasesIndexType.Key); |
44 | 44 |
|
45 | 45 | const { dependencies, terminology } = getTerminologies(); |
46 | 46 |
|
47 | 47 | const fieldOptions = $derived( |
48 | 48 | entity.fields |
49 | 49 | .filter((field) => { |
50 | | - if (selectedType === IndexType.Spatial) { |
| 50 | + if (selectedType === DatabasesIndexType.Spatial) { |
51 | 51 | // keep only spatial |
52 | 52 | return isSpatialType(field); |
53 | 53 | } |
|
69 | 69 |
|
70 | 70 | const types = $derived( |
71 | 71 | [ |
72 | | - { value: IndexType.Key, label: 'Key' }, |
73 | | - { value: IndexType.Unique, label: 'Unique' }, |
74 | | - { value: IndexType.Fulltext, label: 'Fulltext' }, |
75 | | - { value: IndexType.Spatial, label: 'Spatial' } |
| 72 | + { value: DatabasesIndexType.Key, label: 'Key' }, |
| 73 | + { value: DatabasesIndexType.Unique, label: 'Unique' }, |
| 74 | + { value: DatabasesIndexType.Fulltext, label: 'Fulltext' }, |
| 75 | + { value: DatabasesIndexType.Spatial, label: 'Spatial' } |
76 | 76 | ].filter((type) => { |
77 | | - if (type.value === IndexType.Spatial && !$regionalConsoleVariables?.supportForSpatials) |
| 77 | + if (type.value === DatabasesIndexType.Spatial && !$regionalConsoleVariables?.supportForSpatials) |
78 | 78 | return false; |
79 | 79 | return true; |
80 | 80 | }) |
81 | 81 | ); |
82 | 82 |
|
83 | 83 | // order options derived from selected type |
84 | 84 | let orderOptions = $derived.by(() => |
85 | | - selectedType === IndexType.Spatial |
| 85 | + selectedType === DatabasesIndexType.Spatial |
86 | 86 | ? [ |
87 | 87 | { value: OrderBy.Asc, label: 'ASC' }, |
88 | 88 | { value: OrderBy.Desc, label: 'DESC' }, |
|
98 | 98 | // and the field already is not spatial type |
99 | 99 | $effect(() => { |
100 | 100 | const firstField = entity.fields.find((field) => field.key === fieldList.at(0)?.value); |
101 | | - if (selectedType === IndexType.Spatial && firstField && !isSpatialType(firstField)) { |
| 101 | + if (selectedType === DatabasesIndexType.Spatial && firstField && !isSpatialType(firstField)) { |
102 | 102 | fieldList = [{ value: '', order: null, length: null }]; |
103 | 103 | } |
104 | 104 | }); |
|
119 | 119 | const isSpatial = field.length && isSpatialType(field[0]); |
120 | 120 | const order = isSpatial ? null : OrderBy.Asc; |
121 | 121 |
|
122 | | - selectedType = isSpatial ? IndexType.Spatial : IndexType.Key; |
| 122 | + selectedType = isSpatial ? DatabasesIndexType.Spatial : DatabasesIndexType.Key; |
123 | 123 |
|
124 | 124 | fieldList = externalFieldKey |
125 | 125 | ? [{ value: externalFieldKey, order, length: null }] |
|
129 | 129 | } |
130 | 130 |
|
131 | 131 | const addFieldDisabled = $derived( |
132 | | - selectedType === IndexType.Spatial || |
| 132 | + selectedType === DatabasesIndexType.Spatial || |
133 | 133 | !fieldList.at(-1)?.value || |
134 | 134 | (!fieldList.at(-1)?.order && fieldList.at(-1)?.order !== null) |
135 | 135 | ); |
|
160 | 160 | export async function create() { |
161 | 161 | const fieldType = terminology.field.lower.singular; |
162 | 162 |
|
163 | | - if (!key || !selectedType || (selectedType !== IndexType.Spatial && addFieldDisabled)) { |
| 163 | + if (!key || !selectedType || (selectedType !== DatabasesIndexType.Spatial && addFieldDisabled)) { |
164 | 164 | addNotification({ |
165 | 165 | type: 'error', |
166 | 166 | message: `Selected ${fieldType} key or type invalid` |
|
239 | 239 | required |
240 | 240 | options={[ |
241 | 241 | // allow system fields only for non-spatial index types |
242 | | - ...(selectedType === IndexType.Spatial |
| 242 | + ...(selectedType === DatabasesIndexType.Spatial |
243 | 243 | ? [] |
244 | 244 | : [ |
245 | 245 | { value: '$id', label: '$id', leadingIcon: IconFingerPrint }, |
|
269 | 269 | bind:value={field.order} |
270 | 270 | placeholder="Select order" /> |
271 | 271 |
|
272 | | - {#if selectedType === IndexType.Key} |
| 272 | + {#if selectedType === DatabasesIndexType.Key} |
273 | 273 | <InputNumber |
274 | 274 | id={`length-${index}`} |
275 | 275 | label={index === 0 ? 'Length' : undefined} |
|
0 commit comments