@@ -6,7 +6,8 @@ import assign from 'lodash/assign';
6
6
import intersection from 'lodash/intersection' ;
7
7
8
8
import type { ServerI18n } from '../../../i18n/types' ;
9
- import { DASH_CURRENT_SCHEME_VERSION } from '../../../shared/constants' ;
9
+ import { DASH_CURRENT_SCHEME_VERSION , DASH_DATA_REQUIRED_FIELDS } from '../../../shared/constants' ;
10
+ import { DashSchemeConverter } from '../../../shared/modules' ;
10
11
import type {
11
12
CreateEntryRequest ,
12
13
DashData ,
@@ -22,7 +23,9 @@ import {
22
23
DashTabItemType ,
23
24
EntryScope ,
24
25
EntryUpdateMode ,
26
+ Feature ,
25
27
} from '../../../shared/types' ;
28
+ import { isEnabledServerFeature } from '../../../shared/utils' ;
26
29
27
30
import US from './us' ;
28
31
@@ -69,11 +72,15 @@ function gatherLinks(data: DashData) {
69
72
) ;
70
73
}
71
74
72
- function assignData ( I18n : ServerI18n , requestData : DashData ) {
75
+ function setDefaultData ( I18n : ServerI18n , requestData : DashData , initialData ? : DashData ) {
73
76
const i18n = I18n . keyset ( 'dash.tabs-dialog.edit' ) ;
77
+
78
+ if ( initialData ) {
79
+ return assign ( { } , initialData , requestData ) ;
80
+ }
81
+
74
82
const salt = Math . random ( ) . toString ( ) ;
75
83
const hashids = new Hashids ( salt ) ;
76
-
77
84
const data : DashData = {
78
85
salt,
79
86
counter : 2 ,
@@ -102,6 +109,9 @@ function assignData(I18n: ServerI18n, requestData: DashData) {
102
109
return assign ( data , requestData ) ;
103
110
}
104
111
112
+ const needSetDefaultData = ( data : DashData ) =>
113
+ DASH_DATA_REQUIRED_FIELDS . every ( ( fieldName ) => fieldName in data ) ;
114
+
105
115
function validateData ( data : DashData ) {
106
116
const allTabsIds : Set < string > = new Set ( ) ;
107
117
const allItemsIds : Set < string > = new Set ( ) ;
@@ -193,8 +203,15 @@ class Dash {
193
203
scope : EntryScope . Dash ,
194
204
type : '' ,
195
205
} ;
196
- } else {
197
- usData . data = assignData ( I18n , usData . data ) ;
206
+ } else if ( needSetDefaultData ( usData . data ) ) {
207
+ usData . data = setDefaultData ( I18n , usData . data ) ;
208
+ }
209
+
210
+ const isServerMigrationEnabled = Boolean (
211
+ isEnabledServerFeature ( ctx , Feature . DashServerMigrationEnable ) ,
212
+ ) ;
213
+ if ( isServerMigrationEnabled && DashSchemeConverter . isUpdateNeeded ( usData . data ) ) {
214
+ usData . data = await DashSchemeConverter . update ( usData . data ) ;
198
215
}
199
216
200
217
usData . links = gatherLinks ( usData . data ) ;
@@ -242,6 +259,13 @@ class Dash {
242
259
ctx ,
243
260
) ) as DashEntry ;
244
261
262
+ const isServerMigrationEnabled = Boolean (
263
+ isEnabledServerFeature ( ctx , Feature . DashServerMigrationEnable ) ,
264
+ ) ;
265
+ if ( isServerMigrationEnabled && DashSchemeConverter . isUpdateNeeded ( result . data ) ) {
266
+ result . data = await DashSchemeConverter . update ( result . data ) ;
267
+ }
268
+
245
269
ctx . log ( 'SDK_DASH_READ_SUCCESS' , US . getLoggedEntry ( result ) ) ;
246
270
247
271
return result ;
@@ -265,8 +289,13 @@ class Dash {
265
289
266
290
const needDataSend = ! ( mode === EntryUpdateMode . Publish && data . revId ) ;
267
291
if ( needDataSend ) {
268
- usData . data = assignData ( I18n , usData . data ) ;
292
+ if ( needSetDefaultData ( usData . data ) ) {
293
+ const initialData = await Dash . read ( entryId , null , headers , ctx ) ;
294
+ usData . data = setDefaultData ( I18n , usData . data , initialData . data ) ;
295
+ }
296
+
269
297
usData . links = gatherLinks ( usData . data ) ;
298
+
270
299
validateData ( usData . data ) ;
271
300
}
272
301
0 commit comments