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

Drop the segment search from new question flow

parent 8402584e
Branches
Tags
No related merge requests found
......@@ -105,9 +105,9 @@ export class NewQueryOptions extends Component {
}
render() {
const { query, metadataFetched, isAdmin, metricSearchUrl, segmentSearchUrl } = this.props
const { showMetricOption, showSegmentOption, showSQLOption } = this.state
const showCustomInsteadOfNewQuestionText = showMetricOption || showSegmentOption
const { query, metadataFetched, isAdmin, metricSearchUrl } = this.props
const { showMetricOption, showSQLOption } = this.state
const showCustomInsteadOfNewQuestionText = showMetricOption
if (!query || (!isAdmin && (!metadataFetched.metrics || !metadataFetched.segments))) {
return <LoadingAndErrorWrapper loading={true}/>
......@@ -128,17 +128,6 @@ export class NewQueryOptions extends Component {
/>
</li>
}
{ showSegmentOption &&
<li className="Grid-cell">
<NewQueryOption
image="/app/img/list_illustration"
title="Segments"
description="Explore tables and see what’s going on underneath your charts."
width={180}
to={segmentSearchUrl}
/>
</li>
}
<li className="Grid-cell">
{/*TODO: Move illustrations to the new location in file hierarchy. At the same time put an end to the equal-size-@2x ridicule. */}
<NewQueryOption
......
import React, { Component } from 'react'
import { connect } from 'react-redux'
import _ from 'underscore'
import { fetchDatabases, fetchSegments } from "metabase/redux/metadata";
import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper";
import EntitySearch from "metabase/containers/EntitySearch";
import { getMetadata, getMetadataFetched } from "metabase/selectors/metadata";
import Metadata from "metabase-lib/lib/metadata/Metadata";
import type { Segment } from "metabase/meta/types/Segment";
import EmptyState from "metabase/components/EmptyState";
import type { StructuredQuery } from "metabase/meta/types/Query";
import { getCurrentQuery } from "metabase/new_query/selectors";
import { resetQuery } from '../new_query'
const mapStateToProps = state => ({
query: getCurrentQuery(state),
metadata: getMetadata(state),
metadataFetched: getMetadataFetched(state)
})
const mapDispatchToProps = {
fetchSegments,
fetchDatabases,
resetQuery
}
@connect(mapStateToProps, mapDispatchToProps)
export default class SegmentSearch extends Component {
props: {
getUrlForQuery: (StructuredQuery) => void,
backButtonUrl: string,
query: StructuredQuery,
metadata: Metadata,
metadataFetched: any,
fetchSegments: () => void,
fetchDatabases: () => void,
resetQuery: () => void
}
componentDidMount() {
this.props.fetchDatabases() // load databases if not loaded yet
this.props.fetchSegments(true) // segments may change more often so always reload them
this.props.resetQuery();
}
getUrlForSegment = (segment: Segment) => {
const updatedQuery = this.props.query
.setDatabase(segment.table.database)
.setTable(segment.table)
.addFilter(segment.filterClause())
return this.props.getUrlForQuery(updatedQuery);
}
render() {
const { backButtonUrl, metadataFetched, metadata } = this.props;
const isLoading = !metadataFetched.segments || !metadataFetched.databases
return (
<LoadingAndErrorWrapper loading={isLoading}>
{() => {
// TODO Atte Keinänen 8/22/17: If you call `/api/table/:id/table_metadata` it returns
// all segments (also retired ones) and they are missing both `is_active` and `creator` props. Currently this
// filters them out but we should definitely update the endpoints in the upcoming metadata API refactoring.
const sortedActiveSegments = _.chain(metadata.segmentsList())
// Segment shouldn't be retired and it should refer to an existing table
.filter((segment) => segment.isActive() && segment.table)
.sortBy(({name}) => name.toLowerCase())
.value()
if (sortedActiveSegments.length > 0) {
return <EntitySearch
title="Which segment?"
entities={sortedActiveSegments}
getUrlForEntity={this.getUrlForSegment}
backButtonUrl={backButtonUrl}
/>
} else {
return (
<div className="mt2 flex-full flex align-center justify-center">
<EmptyState
message={<span>Defining common segments for your team makes it even easier to ask questions</span>}
image="/app/img/segments_illustration"
action="How to create segments"
link="http://www.metabase.com/docs/latest/administration-guide/07-segments-and-metrics.html"
className="mt2"
imageClassName="mln2"
/>
</div>
)
}
}}
</LoadingAndErrorWrapper>
)
}
}
......@@ -5,7 +5,6 @@ import { push } from "react-router-redux";
import { withBackground } from 'metabase/hoc/Background'
import NewQueryOptions from "./containers/NewQueryOptions";
import SegmentSearch from "./containers/SegmentSearch";
import MetricSearch from "./containers/MetricSearch";
@connect(null, { onChangeLocation: push })
......@@ -42,20 +41,3 @@ export class NewQuestionMetricSearch extends Component {
)
}
}
@connect(null, { onChangeLocation: push })
@withBackground('bg-slate-extra-light')
export class NewQuestionSegmentSearch extends Component {
getUrlForQuery = (query) => {
return query.question().getUrl()
}
render() {
return (
<SegmentSearch
getUrlForQuery={this.getUrlForQuery}
backButtonUrl="/question/new"
/>
)
}
}
......@@ -42,7 +42,7 @@ import SetupApp from "metabase/setup/containers/SetupApp.jsx";
import UserSettingsApp from "metabase/user/containers/UserSettingsApp.jsx";
// new question
import { NewQuestionStart, NewQuestionMetricSearch, NewQuestionSegmentSearch } from "metabase/new_query/router_wrappers";
import { NewQuestionStart, NewQuestionMetricSearch } from "metabase/new_query/router_wrappers";
// admin containers
import DatabaseListApp from "metabase/admin/databases/containers/DatabaseListApp.jsx";
......@@ -205,7 +205,6 @@ export const getRoutes = (store) =>
<Route path="new" title="New Question">
<IndexRoute component={NewQuestionStart} />
<Route path="metric" title="Metrics" component={NewQuestionMetricSearch} />
<Route path="segment" title="Segments" component={NewQuestionSegmentSearch} />
</Route>
</Route>
<Route path="/question/:cardId" component={QueryBuilder} />
......
......@@ -10,7 +10,6 @@ import EntitySearch, {
SearchResultsGroup
} from "metabase/containers/EntitySearch";
import FilterWidget from "metabase/query_builder/components/filters/FilterWidget";
import AggregationWidget from "metabase/query_builder/components/AggregationWidget";
import {
......@@ -86,7 +85,7 @@ describe("new question flow", async () => {
await store.waitForActions([RESET_QUERY, FETCH_METRICS, FETCH_SEGMENTS]);
await store.waitForActions([SET_REQUEST_STATE]);
expect(app.find(NewQueryOption).length).toBe(4)
expect(app.find(NewQueryOption).length).toBe(3)
});
it("lets you start a custom gui question", async () => {
const store = await createTestStore()
......@@ -156,36 +155,6 @@ describe("new question flow", async () => {
app.find(AggregationWidget).find(".View-section-aggregation").text()
).toBe("A Metric")
})
it("lets you start a question from a segment", async () => {
const store = await createTestStore()
store.pushPath(Urls.newQuestion());
const app = mount(store.getAppContainer());
await store.waitForActions([RESET_QUERY, FETCH_METRICS, FETCH_SEGMENTS]);
await store.waitForActions([SET_REQUEST_STATE]);
click(app.find(NewQueryOption).filterWhere((c) => c.prop('title') === "Segments"))
await store.waitForActions(FETCH_DATABASES);
await store.waitForActions([SET_REQUEST_STATE]);
expect(store.getPath()).toBe("/question/new/segment")
const entitySearch = app.find(EntitySearch)
const viewByTable = entitySearch.find(SearchGroupingOption).at(1)
expect(viewByTable.text()).toBe("Table");
click(viewByTable)
expect(store.getPath()).toBe("/question/new/segment?grouping=table")
const group = entitySearch.find(SearchResultsGroup)
.filterWhere((group) => group.prop('groupName') === "Orders")
const metricSearchResult = group.find(SearchResultListItem)
.filterWhere((item) => /A Segment/.test(item.text()))
click(metricSearchResult.childAt(0))
await store.waitForActions([INITIALIZE_QB, QUERY_COMPLETED]);
expect(app.find(FilterWidget).find(".Filter-section-value").text()).toBe("A Segment")
})
})
describe("a newer instance", () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment