@@ -18,8 +18,6 @@ import {
1818 // IAdvLinkDescription,
1919 ILink ,
2020 ILinkEditorModel ,
21- IDatasets ,
22- IDatasetsKeys ,
2321 // IdentityLinkFunction,
2422 IdentityLinkUsing
2523} from '../types' ;
@@ -63,11 +61,6 @@ export class Linking extends LinkEditorWidget {
6361 ) ;
6462 }
6563
66- this . _identityAttributes = {
67- first : undefined ,
68- second : undefined
69- } ;
70-
7164 this . updateDatasets ( ) ;
7265 }
7366
@@ -84,7 +77,10 @@ export class Linking extends LinkEditorWidget {
8477 * @param _sender - the link editor model.
8578 * @param selection - the selected datasets.
8679 */
87- onDatasetChange = ( _sender : ILinkEditorModel , selection : IDatasets ) : void => {
80+ onDatasetChange = (
81+ _sender : ILinkEditorModel ,
82+ selection : [ string , string ]
83+ ) : void => {
8884 // this.updateAttributes();
8985 // this.updateAdvancedLink();
9086 } ;
@@ -104,7 +100,7 @@ export class Linking extends LinkEditorWidget {
104100 updateDatasets ( ) : void {
105101 const currentDatasets = this . _linkEditorModel . currentDatasets ;
106102
107- IDatasetsKeys . forEach ( ( position , index ) => {
103+ [ 0 , 1 ] . forEach ( index => {
108104 const datasetsList = Object . keys ( this . _sharedModel . dataset ) ;
109105
110106 // Remove all the existing datasets.
@@ -121,22 +117,22 @@ export class Linking extends LinkEditorWidget {
121117 dataset . classList . add ( 'glue-LinkEditor-linkingItem' ) ;
122118 dataset . innerText = value ;
123119 dataset . onclick = ( ) => {
124- this . onDatasetSelected ( position , dataset ) ;
120+ this . onDatasetSelected ( index , dataset ) ;
125121 } ;
126122 this . _datasetsPanels [ index ] . append ( dataset ) ;
127123
128124 // Select the current dataset if exists.
129- if ( currentDatasets [ position ] === value ) {
125+ if ( currentDatasets [ index ] === value ) {
130126 selectedDataset = dataset ;
131127 }
132128 } ) ;
133129
134130 // Select a default dataset.
135131 if ( selectedDataset ) {
136- this . onDatasetSelected ( position , selectedDataset ) ;
132+ this . onDatasetSelected ( index , selectedDataset ) ;
137133 } else if ( this . _datasetsPanels [ index ] . childNodes [ index ] ) {
138134 this . onDatasetSelected (
139- position ,
135+ index ,
140136 this . _datasetsPanels [ index ] . childNodes [ index ] as HTMLDivElement
141137 ) ;
142138 }
@@ -149,7 +145,7 @@ export class Linking extends LinkEditorWidget {
149145 * @param position - 'first' or 'second', the column where the widget belongs.
150146 * @param dataset - Element clicked.
151147 */
152- onDatasetSelected ( position : keyof IDatasets , dataset : HTMLDivElement ) : void {
148+ onDatasetSelected ( index : number , dataset : HTMLDivElement ) : void {
153149 // no-op if the dataset is already selected.
154150 if ( dataset . classList . contains ( 'selected' ) ) {
155151 return ;
@@ -162,8 +158,8 @@ export class Linking extends LinkEditorWidget {
162158
163159 // Select the dataset.
164160 dataset . classList . add ( 'selected' ) ;
165- this . updateAttributes ( IDatasetsKeys . indexOf ( position ) , dataset . title ) ;
166- this . _linkEditorModel . setCurrentDataset ( position , dataset . title ) ;
161+ this . updateAttributes ( index , dataset . title ) ;
162+ this . _linkEditorModel . setCurrentDataset ( index , dataset . title ) ;
167163 }
168164
169165 /**
@@ -202,7 +198,7 @@ export class Linking extends LinkEditorWidget {
202198 this . _attributesPanels [ index ] . append ( attribute ) ;
203199 } ) ;
204200
205- this . _identityAttributes [ IDatasetsKeys [ index ] ] = undefined ;
201+ this . _identityAttributes [ index ] = undefined ;
206202
207203 // Enable/disable the Glue button if datasets are different and attributes selected.
208204 this . _updateGlueButtonStatus ( ) ;
@@ -225,12 +221,12 @@ export class Linking extends LinkEditorWidget {
225221 // Select the attribute.
226222 if ( ! isSelected ) {
227223 attribute . classList . add ( 'selected' ) ;
228- this . _identityAttributes [ IDatasetsKeys [ index ] ] = {
224+ this . _identityAttributes [ index ] = {
229225 name : attribute . title ,
230226 label : attribute . innerText
231227 } ;
232228 } else {
233- this . _identityAttributes [ IDatasetsKeys [ index ] ] = undefined ;
229+ this . _identityAttributes [ index ] = undefined ;
234230 }
235231
236232 // Enable/disable the Glue button if datasets are different and attributes selected.
@@ -243,27 +239,27 @@ export class Linking extends LinkEditorWidget {
243239 private _updateGlueButtonStatus ( ) : void {
244240 const currentDatasets = this . _linkEditorModel . currentDatasets ;
245241 const status =
246- Object . values ( this . _identityAttributes ) . every ( value => ! ! value ) &&
247- currentDatasets . first !== currentDatasets . second ;
242+ this . _identityAttributes . every ( value => ! ! value ) &&
243+ currentDatasets [ 0 ] !== currentDatasets [ 1 ] ;
248244 this . _reloadGlueButton . emit ( ! status ) ;
249245 }
250246
251247 /**
252248 * Creates identity link.
253249 */
254250 glueIdentity = ( ) : void => {
255- if ( ! ( this . _identityAttributes . first && this . _identityAttributes . second ) ) {
251+ if ( ! ( this . _identityAttributes [ 0 ] && this . _identityAttributes [ 1 ] ) ) {
256252 return ;
257253 }
258254
259255 const link : ILink = {
260256 _type : ComponentLinkType ,
261- cids1 : [ this . _identityAttributes . first . name ] ,
262- cids2 : [ this . _identityAttributes . second . name ] ,
263- cids1_labels : [ this . _identityAttributes . first . label ] ,
264- cids2_labels : [ this . _identityAttributes . second . label ] ,
265- data1 : this . _linkEditorModel . currentDatasets . first ,
266- data2 : this . _linkEditorModel . currentDatasets . second ,
257+ cids1 : [ this . _identityAttributes [ 0 ] . name ] ,
258+ cids2 : [ this . _identityAttributes [ 1 ] . name ] ,
259+ cids1_labels : [ this . _identityAttributes [ 0 ] . label ] ,
260+ cids2_labels : [ this . _identityAttributes [ 1 ] . label ] ,
261+ data1 : this . _linkEditorModel . currentDatasets [ 0 ] ,
262+ data2 : this . _linkEditorModel . currentDatasets [ 1 ] ,
267263 inverse : IdentityLinkUsing ,
268264 using : IdentityLinkUsing
269265 } ;
@@ -452,7 +448,10 @@ export class Linking extends LinkEditorWidget {
452448 return panel ;
453449 }
454450
455- private _identityAttributes : Private . ISelectedIdentityAttributes ;
451+ private _identityAttributes : [
452+ Private . IAttribute | undefined ,
453+ Private . IAttribute | undefined
454+ ] = [ undefined , undefined ] ;
456455 // private _selectedAdvLink: Private.IAdvancedLinkSelected;
457456 private _datasetsPanels : [ HTMLDivElement , HTMLDivElement ] ;
458457 private _attributesPanels : [ HTMLDivElement , HTMLDivElement ] ;
@@ -478,14 +477,6 @@ namespace Private {
478477 name : string ;
479478 }
480479
481- /**
482- * The selected identity attributes.
483- */
484- export interface ISelectedIdentityAttributes {
485- first ?: IAttribute ;
486- second ?: IAttribute ;
487- }
488-
489480 /**
490481 * The IO types names.
491482 */
0 commit comments