-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
75 deletions.
There are no files selected for viewing
49 changes: 13 additions & 36 deletions
49
src/core_plugins/input_control_vis/public/control/control_factory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,17 @@ | ||
import { rangeControlFactory } from './range_control_factory'; | ||
import { listControlFactory } from './list_control_factory'; | ||
|
||
export function controlFactory(controlParamsArray, kbnApi, callback) { | ||
const createRequestPromises = controlParamsArray.filter((control) => { | ||
// ignore controls that do not have indexPattern or field | ||
return control.indexPattern && control.fieldName; | ||
}) | ||
.map(async (controlParams, index) => { | ||
let factory = null; | ||
switch (controlParams.type) { | ||
case 'range': | ||
factory = rangeControlFactory; | ||
break; | ||
case 'list': | ||
factory = listControlFactory; | ||
break; | ||
} | ||
|
||
if (factory) { | ||
return factory( | ||
controlParams, | ||
kbnApi, | ||
callback.bind(null, index)); | ||
} | ||
}); | ||
Promise.all(createRequestPromises).then(searchRequests => { | ||
// control factory may return nothing if Control does not require a SearchRequest for initialization | ||
// remove empty elements from array before fetch | ||
const validSearchRequests = searchRequests.filter((request) => { | ||
if (request) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
if (validSearchRequests.length > 0) { | ||
kbnApi.fetch.these(validSearchRequests); | ||
} | ||
}); | ||
export function controlFactory(controlParams) { | ||
let factory = null; | ||
switch (controlParams.type) { | ||
case 'range': | ||
factory = rangeControlFactory; | ||
break; | ||
case 'list': | ||
factory = listControlFactory; | ||
break; | ||
default: | ||
throw new Error(`Unhandled control type ${controlParams.type}`); | ||
} | ||
return factory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters