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

setCollection instrumentation and undo

parent fd81c5f9
Branches
Tags
No related merge requests found
......@@ -179,7 +179,7 @@ export class InlineModal extends Component {
}
const Modal = ({ full, inline, ...props }) =>console.log(full, inline, props)||
const Modal = ({ full, inline, ...props }) =>
full ?
(props.isOpen ? <FullPageModal {...props} /> : null)
: inline ?
......
......@@ -37,7 +37,7 @@ export default class MoveToCollection extends Component {
async onMove(collectionId) {
try {
this.setState({ error: null })
await this.props.setCollection(this.props.questionId, collectionId);
await this.props.setCollection(this.props.questionId, collectionId, true);
this.props.onClose();
} catch (e) {
this.setState({ error: e })
......
......@@ -161,14 +161,31 @@ export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, label
}
});
const getCardCollectionId = (state, cardId) => getIn(state, ["questions", "entities", "cards", cardId, "collection_id"])
export const setCollection = createThunkAction(SET_COLLECTION, (cardId, collectionId, undoable = false) => {
return async (dispatch, getState) => {
const state = getState();
if (cardId == null) {
// bulk label
// bulk move
let selected = getSelectedEntities(getState());
if (undoable) {
dispatch(addUndo(createUndo(
"moved",
selected.map(item => setCollection(item.id, getCardCollectionId(state, item.id)))
)));
MetabaseAnalytics.trackEvent("Questions", "Bulk Move to Collection");
}
selected.map(item => dispatch(setCollection(item.id, collectionId)));
} else {
const collection = _.findWhere(getState().collections.collections, { id: collectionId });
const collection = _.findWhere(state.collections.collections, { id: collectionId });
if (undoable) {
dispatch(addUndo(createUndo(
"moved",
[setCollection(cardId, getCardCollectionId(state, cardId))]
)));
MetabaseAnalytics.trackEvent("Questions", "Move to Collection");
}
const card = await CardApi.update({ id: cardId, collection_id: collectionId });
return {
...card,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment