From 9cbd667eb7af96cb2cafaf05778906110cf50520 Mon Sep 17 00:00:00 2001 From: Alanna Scott Date: Mon, 23 Jan 2017 10:08:00 -0800 Subject: [PATCH] [explore-v2] Fix edit datasource link for druid datasources (#1982) * only add imgSrc key if choices contain an imgSrc * handle table and druid edit links for datasource drop down * fix linting --- .../javascripts/explorev2/components/SelectField.jsx | 10 ++++------ superset/assets/javascripts/explorev2/stores/fields.js | 7 ++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/superset/assets/javascripts/explorev2/components/SelectField.jsx b/superset/assets/javascripts/explorev2/components/SelectField.jsx index dded10228..bbf812432 100644 --- a/superset/assets/javascripts/explorev2/components/SelectField.jsx +++ b/superset/assets/javascripts/explorev2/components/SelectField.jsx @@ -43,15 +43,13 @@ export default class SelectField extends React.Component { } getOptions() { const options = this.props.choices.map((c) => { - let label = c[0]; - if (c.length > 1) { - label = c[1]; - } - return { + const label = c.length > 1 ? c[1] : c[0]; + const newOptions = { value: c[0], label, - imgSrc: c[2], }; + if (c[2]) newOptions.imgSrc = c[2]; + return newOptions; }); if (this.props.freeForm) { // For FreeFormSelect, insert value into options if not exist diff --git a/superset/assets/javascripts/explorev2/stores/fields.js b/superset/assets/javascripts/explorev2/stores/fields.js index b447a98b6..621f6105d 100644 --- a/superset/assets/javascripts/explorev2/stores/fields.js +++ b/superset/assets/javascripts/explorev2/stores/fields.js @@ -26,15 +26,20 @@ const TIME_STAMP_OPTIONS = [ ['%H:%M:%S', '%H:%M:%S | 01:32:10'], ]; +const MAP_DATASOURCE_TYPE_TO_EDIT_URL = { + table: '/tablemodelview/edit', + druid: '/druiddatasourcemodelview/edit', +}; + export const fields = { datasource: { type: 'SelectField', label: 'Datasource', clearable: false, default: null, - editUrl: '/tablemodelview/edit', mapStateToProps: (state) => ({ choices: state.datasources || [], + editUrl: MAP_DATASOURCE_TYPE_TO_EDIT_URL[state.datasource_type], }), description: '', },