summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/frequent_items/store/actions.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 19:00:14 +0000
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/assets/javascripts/frequent_items/store/actions.js
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
downloadgitlab-ce-05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2.tar.gz
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/assets/javascripts/frequent_items/store/actions.js')
-rw-r--r--app/assets/javascripts/frequent_items/store/actions.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/assets/javascripts/frequent_items/store/actions.js b/app/assets/javascripts/frequent_items/store/actions.js
index babc2ef2e32..e5ef49ec402 100644
--- a/app/assets/javascripts/frequent_items/store/actions.js
+++ b/app/assets/javascripts/frequent_items/store/actions.js
@@ -12,6 +12,10 @@ export const setStorageKey = ({ commit }, key) => {
commit(types.SET_STORAGE_KEY, key);
};
+export const toggleItemsListEditablity = ({ commit }) => {
+ commit(types.TOGGLE_ITEMS_LIST_EDITABILITY);
+};
+
export const requestFrequentItems = ({ commit }) => {
commit(types.REQUEST_FREQUENT_ITEMS);
};
@@ -81,3 +85,28 @@ export const setSearchQuery = ({ commit, dispatch }, query) => {
dispatch('fetchFrequentItems');
}
};
+
+export const removeFrequentItemSuccess = ({ commit }, itemId) => {
+ commit(types.RECEIVE_REMOVE_FREQUENT_ITEM_SUCCESS, itemId);
+};
+
+export const removeFrequentItemError = ({ commit }) => {
+ commit(types.RECEIVE_REMOVE_FREQUENT_ITEM_ERROR);
+};
+
+export const removeFrequentItem = ({ state, dispatch }, itemId) => {
+ if (AccessorUtilities.canUseLocalStorage()) {
+ try {
+ const storedRawItems = JSON.parse(localStorage.getItem(state.storageKey));
+ localStorage.setItem(
+ state.storageKey,
+ JSON.stringify(storedRawItems.filter((item) => item.id !== itemId)),
+ );
+ dispatch('removeFrequentItemSuccess', itemId);
+ } catch {
+ dispatch('removeFrequentItemError');
+ }
+ } else {
+ dispatch('removeFrequentItemError');
+ }
+};