Skip to content
Snippets Groups Projects
Commit a575080f authored by Atte Keinänen's avatar Atte Keinänen
Browse files

Return null in question.mode() if no mode available

parent 8c9bcb5e
No related branches found
No related tags found
No related merge requests found
......@@ -19,12 +19,16 @@ export default class Mode {
}
static forQuestion(question: Question): ?Mode {
// TODO: Move getMode here and refactor it after writing tests
// TODO Atte Keinänen 6/22/17: Move getMode here and refactor it after writing tests
const card = question.card();
const tableMetadata = question.tableMetadata();
const queryMode = getMode(card, tableMetadata)
return new Mode(question, queryMode);
if (queryMode) {
return new Mode(question, queryMode);
} else {
return null;
}
}
queryMode() {
......
......@@ -92,23 +92,29 @@ export default class ActionsWidget extends Component {
handleActionClick = (index: number) => {
const { question } = this.props;
const action = question.mode().actions()[index];
if (action && action.popover) {
this.setState({ selectedActionIndex: index });
} else if (action && action.question) {
const nextQuestion = action.question();
if (nextQuestion) {
MetabaseAnalytics.trackEvent("Actions", "Executed Action", `${action.section||""}:${action.name||""}`);
this.handleOnChangeCardAndRun({ nextCard: nextQuestion.card() });
const mode = question.mode()
if (mode) {
const action = mode.actions()[index];
if (action && action.popover) {
this.setState({ selectedActionIndex: index });
} else if (action && action.question) {
const nextQuestion = action.question();
if (nextQuestion) {
MetabaseAnalytics.trackEvent("Actions", "Executed Action", `${action.section||""}:${action.name||""}`);
this.handleOnChangeCardAndRun({ nextCard: nextQuestion.card() });
}
this.close();
}
this.close();
} else {
console.warn("handleActionClick: Question mode is missing")
}
};
render() {
const { className, question } = this.props;
const { isOpen, isVisible, selectedActionIndex } = this.state;
const actions = question.mode().actions();
const mode = question.mode();
const actions = mode ? mode.actions() : [];
if (actions.length === 0) {
return null;
}
......
......@@ -193,7 +193,8 @@ export default class Visualization extends Component {
const seriesIndex = clicked.seriesIndex || 0;
const card = series[seriesIndex].card;
const question = new Question(metadata, card);
return question.mode().actionsForClick(clicked);
const mode = question.mode();
return mode ? mode.actionsForClick(clicked) : [];
}
visualizationIsClickable = (clicked: ClickObject) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment