Fixed adding queries to favorites

Summary: I found a bug after migration to Sandy. It is now not possible to add queries to favorites. This diff fixes the issue.

Reviewed By: mweststrate

Differential Revision: D28066435

fbshipit-source-id: 129a62dab9521160f8957abba70e5c7a6e609839
This commit is contained in:
Anton Nikolaev
2021-04-29 01:27:05 -07:00
committed by Facebook GitHub Bot
parent 05bf55419f
commit c4887e638b

View File

@@ -485,28 +485,21 @@ export function plugin(client: PluginClient<Events, Methods>) {
const updateFavorites = (event: {favorites: Array<string> | undefined}) => {
const state = pluginState.get();
let newFavorites = event.favorites || state.favorites;
if (
state.query &&
state.query !== null &&
typeof state.query !== 'undefined'
) {
const newFavorites = [...(event.favorites || state.favorites)];
if (state.query) {
const value = state.query.value;
if (newFavorites.includes(value)) {
const index = newFavorites.indexOf(value);
newFavorites.splice(index, 1);
const index = newFavorites.indexOf(value);
if (index < 0) {
newFavorites.push(value);
} else {
newFavorites = state.favorites.concat(value);
newFavorites.splice(index, 1);
}
}
pluginState.set({...state, favorites: newFavorites});
window.localStorage.setItem(
'plugin-database-favorites-sql-queries',
JSON.stringify(newFavorites),
);
return {
...state,
favorites: newFavorites,
};
};
const sortByChanged = (event: {sortOrder: TableRowSortOrder}) => {