Skip to content
Snippets Groups Projects
Unverified Commit 00e00803 authored by Tom Robinson's avatar Tom Robinson
Browse files

Only show writable collections in MoveToCollection modal. Use CollectionsList in SaveQuestionModal

parent 04dd1912
Branches
Tags
No related merge requests found
import React, { Component, PropTypes } from "react";
import { connect } from "react-redux";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
......@@ -9,25 +8,13 @@ import ModalContent from "metabase/components/ModalContent.jsx";
import Radio from "metabase/components/Radio.jsx";
import Select, { Option } from "metabase/components/Select.jsx";
import Button from "metabase/components/Button";
import CollectionList from "metabase/questions/containers/CollectionList";
import Query from "metabase/lib/query";
import { cancelable } from "metabase/lib/promise";
import _ from "underscore";
import "./SaveQuestionModal.css";
import { loadCollections } from "metabase/questions/collections";
const mapStateToProps = (state, props) => ({
collections: _.filter(state.collections.collections, collection => collection.can_write)
});
const mapDispatchToProps = {
loadCollections
};
@connect(mapStateToProps, mapDispatchToProps)
export default class SaveQuestionModal extends Component {
constructor(props, context) {
......@@ -56,10 +43,6 @@ export default class SaveQuestionModal extends Component {
onClose: PropTypes.func.isRequired
}
componentWillMount() {
this.props.loadCollections();
}
componentDidMount() {
this.validateForm();
}
......@@ -131,7 +114,6 @@ export default class SaveQuestionModal extends Component {
}
render() {
const { collections } = this.props;
let { error, details } = this.state;
var formError;
if (error) {
......@@ -183,6 +165,7 @@ export default class SaveQuestionModal extends Component {
id="SaveQuestionModal"
title={title}
footer={[
formError,
<Button onClick={this.props.onClose}>
Cancel
</Button>,
......@@ -227,7 +210,8 @@ export default class SaveQuestionModal extends Component {
onChange={(e) => this.onChange("description", e.target.value)}
/>
</FormField>
{ collections && collections.length > 0 &&
<CollectionList writable>
{ (collections) => collections.length > 0 &&
<FormField
displayName="Which collection should this go in?"
fieldName="collection_id"
......@@ -262,6 +246,7 @@ export default class SaveQuestionModal extends Component {
</Select>
</FormField>
}
</CollectionList>
</div>
}
</ReactCSSTransitionGroup>
......
import React, { Component } from "react";
import { connect } from "react-redux";
import { getCollections } from "../selectors";
import { getAllCollections, getWritableCollections } from "../selectors";
import { loadCollections } from "../collections";
const mapStateToProps = (state, props) => ({
collections: getCollections(state, props)
collections: props.writable ? getWritableCollections(state, props) : getAllCollections(state, props)
})
const mapDispatchToProps = {
......
......@@ -65,7 +65,7 @@ export default class MoveToCollection extends Component {
}
onClose={onClose}
>
<CollectionList>
<CollectionList writable>
{ collections =>
<ol className="List text-brand ml-auto mr-auto" style={{ width: 520 }}>
{ [{ name: "None", id: null }].concat(collections).map((collection, index) =>
......
......@@ -18,12 +18,17 @@ export const getItemsBySection = (state) => state.questions.itemsBySection
export const getSearchText = (state) => state.questions.searchText;
export const getSelectedIds = (state) => state.questions.selectedIds;
export const getCollections = (state) => state.collections.collections;
export const getAllCollections = (state) => state.collections.collections;
export const getWritableCollections = createSelector(
[getAllCollections],
(collections) => _.filter(collections, collection => collection.can_write)
);
export const getQuery = createSelector(
[getSection],
(section) => section && JSON.parse(section)
)
);
const getSectionData = createSelector(
[getItemsBySection, getEntityType, getSection],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment