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

Move Undo out of /questions. Show collection name/link when unarchiving

parent de1af51a
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@ import React, { Component, PropTypes } from "react";
import Navbar from "metabase/nav/containers/Navbar.jsx";
import UndoListing from "metabase/containers/UndoListing";
export default class App extends Component {
render() {
const { children, location } = this.props;
......@@ -9,8 +11,8 @@ export default class App extends Component {
<div className="spread flex flex-column">
<Navbar location={location} className="flex-no-shrink" />
{children}
<UndoListing />
</div>
)
}
}
@import '../Questions.css';
:local(.listing) {
composes: m2 from "style";
composes: fixed left bottom from "style";
......@@ -8,23 +6,21 @@
:local(.undo) {
composes: mt2 p2 from "style";
composes: bordered from "style";
composes: rounded from "style";
composes: shadowed from "style";
composes: relative from "style";
composes: bordered rounded shadowed from "style";
composes: bg-white from "style";
composes: relative from "style";
composes: flex align-center from "style";
width: 320px;
}
:local(.actions) {
composes: flex align-center from "style";
composes: float-right from "style";
composes: flex align-center flex-align-right from "style";
}
:local(.undoButton) {
composes: mx2 from "style";
composes: text-uppercase text-bold from "style";
color: var(--blue-color);
color: var(--brand-color);
}
:local(.dismissButton) {
composes: cursor-pointer from "style";
......
/* eslint "react/prop-types": "warn" */
import React, { Component, PropTypes } from "react";
import { Link } from "react-router";
import { connect } from "react-redux";
import S from "./UndoListing.css";
import { dismissUndo, performUndo } from "../undo";
import { getUndos } from "../selectors";
import { dismissUndo, performUndo } from "metabase/redux/undo";
import { getUndos } from "metabase/selectors/undo";
import Icon from "metabase/components/Icon";
import BodyComponent from "metabase/components/BodyComponent";
......@@ -43,11 +44,14 @@ export default class UndoListing extends Component {
>
{ undos.map(undo =>
<li key={undo._domId} className={S.undo}>
<span className={S.message}>{typeof undo.message === "function" ? undo.message(undo) : undo.message}</span>
<span className={S.actions}>
<div className={S.message}>
{typeof undo.message === "function" ? undo.message(undo) : undo.message}
</div>
<div className={S.actions}>
<a className={S.undoButton} onClick={() => performUndo(undo.id)}>Undo</a>
<Icon className={S.dismissButton} name="close" onClick={() => dismissUndo(undo.id)} />
</span>
</div>
</li>
)}
</ReactCSSTransitionGroup>
......
......@@ -40,7 +40,7 @@
align-items: flex-end;
}
.align-self-end {
.align-self-end, :local(.align-self-end) {
align-self: flex-end;
}
......
......@@ -58,7 +58,7 @@ export default class Archive extends Component {
}} />
: item.type === "card" ?
<ArchivedItem name={item.name} type="card" icon={visualizations.get(item.display).iconName} isAdmin={isAdmin} onUnarchive={async () => {
await this.props.setArchived(item.id, false);
await this.props.setArchived(item.id, false, true);
this.loadEntities();
}} />
:
......
......@@ -13,7 +13,6 @@ import S from "../components/List.css";
import List from "../components/List";
import SearchHeader from "../components/SearchHeader";
import ActionHeader from "../components/ActionHeader";
import UndoListing from "./UndoListing";
import _ from "underscore";
......@@ -225,7 +224,6 @@ export default class EntityList extends Component {
}
</LoadingAndErrorWrapper>
</div>
<UndoListing />
</div>
);
}
......
......@@ -7,11 +7,13 @@ import _ from "underscore";
import { inflect } from "metabase/lib/formatting";
import MetabaseAnalytics from "metabase/lib/analytics";
import Urls from "metabase/lib/urls";
import { push, replace } from "react-router-redux";
import { setRequestState } from "metabase/redux/requests";
import { addUndo } from "metabase/redux/undo";
import { getVisibleEntities, getSelectedEntities } from "./selectors";
import { addUndo } from "./undo";
import { push, replace } from "react-router-redux";
import { SET_COLLECTION_ARCHIVED } from "./collections";
......@@ -69,11 +71,22 @@ export const setFavorited = createThunkAction(SET_FAVORITED, (cardId, favorited)
}
});
function createUndo(type, actions) {
import React from "react";
import { Link } from "react-router";
function createUndo(type, actions, collection) {
return {
type: type,
count: actions.length,
message: (undo) => undo.count + " " + inflect(null, undo.count, "question was", "questions were") + " " + type,
message: (undo) =>
<div className="flex flex-column">
<div>
{ undo.count + " " + inflect(null, undo.count, "question was", "questions were") + " " + type }
{ undo.count === 1 && collection &&
<span> to the <Link className="link" to={Urls.collection(collection)}>{collection.name}</Link> collection.</span>
}
</div>
</div>,
actions: actions
};
}
......@@ -101,7 +114,8 @@ export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, un
if (undoable) {
dispatch(addUndo(createUndo(
archived ? "archived" : "unarchived",
[setArchived(cardId, !archived)]
[setArchived(cardId, !archived)],
!archived && card.collection
)));
MetabaseAnalytics.trackEvent("Questions", archived ? "Archive" : "Unarchive");
}
......
......@@ -202,5 +202,3 @@ export const getSectionName = createSelector(
return "";
}
);
export const getUndos = (state, props) => state.undo;
......@@ -6,6 +6,7 @@ import auth from "metabase/auth/auth";
/* ducks */
import metadata from "metabase/redux/metadata";
import requests from "metabase/redux/requests";
import undo from "metabase/redux/undo";
/* admin */
import settings from "metabase/admin/settings/settings";
......@@ -22,7 +23,6 @@ import * as home from "metabase/home/reducers";
import questions from "metabase/questions/questions";
import labels from "metabase/questions/labels";
import collections from "metabase/questions/collections";
import undo from "metabase/questions/undo";
import * as qb from "metabase/query_builder/reducers";
/* data reference */
......@@ -44,6 +44,7 @@ const reducers = {
currentUser,
metadata,
requests,
undo,
// main app reducers
dashboard,
......@@ -53,7 +54,6 @@ const reducers = {
questions,
collections,
labels,
undo,
reference,
setup: combineReducers(setup),
user: combineReducers(user),
......
......@@ -14,7 +14,7 @@ let nextUndoId = 0;
export const addUndo = createThunkAction(ADD_UNDO, (undo) => {
return (dispatch, getState) => {
let id = nextUndoId++;
setTimeout(() => dispatch(dismissUndo(id, false)), 5000);
// setTimeout(() => dispatch(dismissUndo(id, false)), 5000);
return { ...undo, id, _domId: id };
};
});
......
export const getUndos = (state, props) => state.undo;
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