-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[explore v2] populate dynamic select field options #1543
Changes from 15 commits
ff43d16
c1bc8f5
4baf560
dce5440
6c1a0a9
e7e1db0
1a82e5c
b8f5057
7547c95
9d841e1
a4a58e1
42c7e0e
2677bf1
e5b20db
2d9da33
1cbd6e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
const $ = window.$ = require('jquery'); | ||
export const SET_DATASOURCE = 'SET_DATASOURCE'; | ||
export const SET_TIME_COLUMN_OPTS = 'SET_TIME_COLUMN_OPTS'; | ||
export const SET_TIME_GRAIN_OPTS = 'SET_TIME_GRAIN_OPTS'; | ||
export const SET_GROUPBY_COLUMN_OPTS = 'SET_GROUPBY_COLUMN_OPTS'; | ||
export const SET_METRICS_OPTS = 'SET_METRICS_OPTS'; | ||
export const SET_COLUMN_OPTS = 'SET_COLUMN_OPTS'; | ||
export const SET_ORDERING_OPTS = 'SET_ORDERING_OPTS'; | ||
export const SET_FIELD_OPTIONS = 'SET_FIELD_OPTIONS'; | ||
export const TOGGLE_SEARCHBOX = 'TOGGLE_SEARCHBOX'; | ||
export const SET_FILTER_COLUMN_OPTS = 'SET_FILTER_COLUMN_OPTS'; | ||
export const ADD_FILTER = 'ADD_FILTER'; | ||
|
@@ -19,89 +14,52 @@ export const CLEAR_ALL_OPTS = 'CLEAR_ALL_OPTS'; | |
export const SET_DATASOURCE_TYPE = 'SET_DATASOURCE_TYPE'; | ||
export const SET_FIELD_VALUE = 'SET_FIELD_VALUE'; | ||
|
||
export function setTimeColumnOpts(timeColumnOpts) { | ||
return { type: SET_TIME_COLUMN_OPTS, timeColumnOpts }; | ||
export function setFieldOptions(options) { | ||
return { type: SET_FIELD_OPTIONS, options }; | ||
} | ||
|
||
export function setTimeGrainOpts(timeGrainOpts) { | ||
return { type: SET_TIME_GRAIN_OPTS, timeGrainOpts }; | ||
} | ||
|
||
export function setGroupByColumnOpts(groupByColumnOpts) { | ||
return { type: SET_GROUPBY_COLUMN_OPTS, groupByColumnOpts }; | ||
} | ||
|
||
export function setMetricsOpts(metricsOpts) { | ||
return { type: SET_METRICS_OPTS, metricsOpts }; | ||
export function clearAllOpts() { | ||
return { type: CLEAR_ALL_OPTS }; | ||
} | ||
|
||
export function setColumnOpts(columnOpts) { | ||
return { type: SET_COLUMN_OPTS, columnOpts }; | ||
export function setDatasourceType(datasourceType) { | ||
return { type: SET_DATASOURCE_TYPE, datasourceType }; | ||
} | ||
|
||
export function setOrderingOpts(orderingOpts) { | ||
return { type: SET_ORDERING_OPTS, orderingOpts }; | ||
export const FETCH_STARTED = 'FETCH_STARTED'; | ||
export function fetchStarted() { | ||
return { type: FETCH_STARTED }; | ||
} | ||
|
||
export function setFilterColumnOpts(filterColumnOpts) { | ||
return { type: SET_FILTER_COLUMN_OPTS, filterColumnOpts }; | ||
export const FETCH_SUCCEEDED = 'FETCH_SUCCEEDED'; | ||
export function fetchSucceeded() { | ||
return { type: FETCH_SUCCEEDED }; | ||
} | ||
|
||
export function clearAllOpts() { | ||
return { type: CLEAR_ALL_OPTS }; | ||
export const FETCH_FAILED = 'FETCH_FAILED'; | ||
export function fetchFailed() { | ||
return { type: FETCH_FAILED }; | ||
} | ||
|
||
export function setFormOpts(datasourceId, datasourceType) { | ||
export function fetchFieldOptions(datasourceId, datasourceType) { | ||
return function (dispatch) { | ||
const timeColumnOpts = []; | ||
const groupByColumnOpts = []; | ||
const metricsOpts = []; | ||
const filterColumnOpts = []; | ||
const timeGrainOpts = []; | ||
const columnOpts = []; | ||
const orderingOpts = []; | ||
dispatch(fetchStarted()); | ||
|
||
if (datasourceId) { | ||
const params = [`datasource_id=${datasourceId}`, `datasource_type=${datasourceType}`]; | ||
const url = '/caravel/fetch_datasource_metadata?' + params.join('&'); | ||
|
||
$.get(url, (data, status) => { | ||
if (status === 'success') { | ||
data.time_columns.forEach((d) => { | ||
if (d) timeColumnOpts.push({ value: d, label: d }); | ||
}); | ||
data.groupby_cols.forEach((d) => { | ||
if (d) groupByColumnOpts.push({ value: d, label: d }); | ||
}); | ||
data.metrics.forEach((d) => { | ||
if (d) metricsOpts.push({ value: d[1], label: d[0] }); | ||
}); | ||
data.filter_cols.forEach((d) => { | ||
if (d) filterColumnOpts.push({ value: d, label: d }); | ||
}); | ||
data.time_grains.forEach((d) => { | ||
if (d) timeGrainOpts.push({ value: d, label: d }); | ||
}); | ||
data.columns.forEach((d) => { | ||
if (d) columnOpts.push({ value: d, label: d }); | ||
}); | ||
data.ordering_cols.forEach((d) => { | ||
if (d) orderingOpts.push({ value: d, label: d }); | ||
}); | ||
|
||
// Repopulate options for controls | ||
dispatch(setTimeColumnOpts(timeColumnOpts)); | ||
dispatch(setTimeGrainOpts(timeGrainOpts)); | ||
dispatch(setGroupByColumnOpts(groupByColumnOpts)); | ||
dispatch(setMetricsOpts(metricsOpts)); | ||
dispatch(setFilterColumnOpts(filterColumnOpts)); | ||
dispatch(setColumnOpts(columnOpts)); | ||
dispatch(setOrderingOpts(orderingOpts)); | ||
// populate options for select type fields | ||
dispatch(setFieldOptions(data.field_options)); | ||
dispatch(fetchSucceeded()); | ||
} else if (status === 'error') { | ||
dispatch(fetchFailed()); | ||
} | ||
}); | ||
} else { | ||
// Clear all Select options | ||
dispatch(clearAllOpts()); | ||
// in what case don't we have a datasource id? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in react-select there's an option to empty the select field, namely datasource could be null, not sure if this is needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure it's needed either. in the explore view we should always have a datasource. we can remove in a follow up PR. |
||
} | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to think this would be used for setting Druid/Table for datasource, but it seems that we don't have the option to switch datasource type in explore view? @mistercrunch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we actually need this. we can change a datasource but there is not a concept of changing the datasource type only. datasource type is tied to the datasource. i think this shows up like this because of some white space diffing. we can remove in a follow up pr.