Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ export const createWatchlistEntitiesService = ({

acc.entityIdsByType[entityType].push(euid);

const watchlists = get(record, 'entity.attributes.watchlists') as string[] | undefined;
const rawWatchlists = get(record, 'entity.attributes.watchlists');
const watchlists = Array.isArray(rawWatchlists)
? rawWatchlists
: typeof rawWatchlists === 'string'
? [rawWatchlists]
: undefined;

if (watchlists) {
acc.watchlistsByEuid.set(euid, watchlists);
acc.watchlistsByEuid.set(euid, watchlists as string[]);
}

if (!isIndexSync) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export const addWatchlistAttributeToStore = async ({
if (entityRefs.length === 0) return;

const objects = entityRefs.map(({ euid, type, currentWatchlists }) => {
const watchlists = currentWatchlists ?? [];
const watchlists = Array.isArray(currentWatchlists)
? currentWatchlists
: typeof currentWatchlists === 'string'
? [currentWatchlists]
: [];
const updated = watchlists.includes(watchlistId) ? watchlists : [...watchlists, watchlistId];

return {
Expand Down Expand Up @@ -72,8 +76,9 @@ export const removeWatchlistAttributeFromStore = async ({
watchlistId: string;
}): Promise<void> => {
// Only update entities whose current watchlists are known — if we don't have the current value we'd blindly write an empty array to the store.
const knownRefs = entityRefs.filter((ref): ref is EntityRef & { currentWatchlists: string[] } =>
Boolean(ref.currentWatchlists)
const knownRefs = entityRefs.filter(
(ref): ref is EntityRef & { currentWatchlists: string[] } =>
Boolean(ref.currentWatchlists) && Array.isArray(ref.currentWatchlists)
);
if (knownRefs.length === 0) return;

Expand Down
Loading