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

Add bulk labeling undo

parent 4cce0bf0
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ const ActionHeader = ({ selectedCount, allAreSelected, sectionIsArchive, setAllS
}
labels={labels}
/>
<span className={S.archiveButton} onClick={() => setArchived(undefined, !sectionIsArchive)}>
<span className={S.archiveButton} onClick={() => setArchived(undefined, !sectionIsArchive, true)}>
<Icon name="grid" />
{ sectionIsArchive ? "Unarchive" : "Archive" }
</span>
......
......@@ -42,7 +42,7 @@ const Item = ({ id, name, created, by, selected, favorite, archived, icon, label
</div>
<div className={S.extraIcons}>
<Tooltip tooltip={archived ? "Unarchive" : "Archive"}>
<Icon className={S.archiveIcon} name="grid" width={20} height={20} onClick={() => setArchived(id, !archived)} />
<Icon className={S.archiveIcon} name="grid" width={20} height={20} onClick={() => setArchived(id, !archived, true)} />
</Tooltip>
</div>
</div>
......
......@@ -23,7 +23,7 @@ const LabelPicker = ({ labels, count, item, setLabeled }) =>
return (
<li
key={label.id}
onClick={() => setLabeled(item && item.id, label.id, !selected)}
onClick={() => setLabeled(item && item.id, label.id, !selected, !item)}
className={cx(S.option, { [S.selected]: selected })}
style={{ color: color }}
>
......
......@@ -73,17 +73,17 @@ export const setFavorited = createThunkAction(SET_FAVORITED, (cardId, favorited)
}
});
export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, undoable = true) => {
export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, undoable = false) => {
return async (dispatch, getState) => {
if (cardId == null) {
// bulk archive
let selected = getSelectedEntities(getState()).filter(item => item.archived !== archived);
selected.map(item => dispatch(setArchived(item.id, archived, false)));
selected.map(item => dispatch(setArchived(item.id, archived)));
// TODO: errors
if (undoable) {
dispatch(addUndo(
selected.length + " question were " + (archived ? "archived" : "unarchived"),
selected.map(item => setArchived(item.id, !archived, false))
selected.map(item => setArchived(item.id, !archived))
));
}
} else {
......@@ -93,22 +93,29 @@ export const setArchived = createThunkAction(SET_ARCHIVED, (cardId, archived, un
};
let response = await CardApi.update(card);
if (undoable) {
dispatch(addUndo("Question was " + (archived ? "archived" : "unarchived"), [
setArchived(cardId, !archived, false)
]));
dispatch(addUndo(
"Question was " + (archived ? "archived" : "unarchived"),
[setArchived(cardId, !archived)]
));
}
return response;
}
}
});
export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, labeled) => {
export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, labeled, undoable = false) => {
return async (dispatch, getState) => {
if (cardId == null) {
// bulk label
let selected = getSelectedEntities(getState());
selected.map(item => dispatch(setLabeled(item.id, labelId, labeled)));
// TODO: errors
if (undoable) {
dispatch(addUndo(
"Label was " + (labeled ? "added to" : "removed from") + " " + selected.length + " questions",
selected.map(item => setLabeled(item.id, labelId, !labeled))
));
}
} else {
const state = getState();
const labelSlug = i.getIn(state.questions, ["entities", "labels", labelId, "slug"]);
......@@ -119,6 +126,12 @@ export const setLabeled = createThunkAction(SET_LABELED, (cardId, labelId, label
}
if (labels.length !== newLabels.length) {
await CardApi.updateLabels({ cardId, label_ids: newLabels });
if (undoable) {
dispatch(addUndo(
"Label was " + (labeled ? "added" : "removed"),
[setLabeled(cardId, labelId, !labeled)]
));
}
return { id: cardId, labels: newLabels, _changedLabelSlug: labelSlug, _changedLabeled: labeled };
}
}
......
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