Skip to content

Commit 402732a

Browse files
authored
fix [properties-fe] - filter current entity from entity selection list (#615)
1 parent ebe46ba commit 402732a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

js/app/packages/core/component/Properties/component/modal/shared/PropertyEntitySelector.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useBlockId } from '@core/block';
12
import { useChannelsContext } from '@core/component/ChannelsProvider';
23
import { EntityIcon } from '@core/component/EntityIcon';
34
import { UserIcon } from '@core/component/UserIcon';
@@ -31,6 +32,7 @@ import {
3132
on,
3233
Show,
3334
} from 'solid-js';
35+
import { usePropertiesContext } from '../../../context/PropertiesContext';
3436
import { PROPERTY_STYLES } from '../../../styles/styles';
3537
import type { Property } from '../../../types';
3638
import { useSearchInputFocus } from '../../../utils';
@@ -205,6 +207,10 @@ export function PropertyEntitySelector(props: EntityInputProps) {
205207

206208
let searchInputRef!: HTMLInputElement;
207209

210+
// Get current entity context for self-filtering
211+
const blockId = useBlockId();
212+
const { entityType: currentEntityType } = usePropertiesContext();
213+
208214
const history = useHistory();
209215
const contacts = useContacts();
210216
const channelsContext = useChannelsContext();
@@ -315,17 +321,26 @@ export function PropertyEntitySelector(props: EntityInputProps) {
315321
const MAX_VISIBLE_ENTITIES_NO_SEARCH = 50;
316322
const MAX_SEARCH_RESULTS = 20;
317323

324+
// Filter out the current entity when selecting same entity type (e.g., parent task on a task)
325+
const excludeFilter = (e: CombinedEntity) =>
326+
!(getEntityType(e) === currentEntityType && e.id === blockId);
327+
318328
// Get visible entities based on search
319329
const localResults = term
320330
? entitySearch(allEntities, term)
321331
.slice(0, MAX_SEARCH_RESULTS)
322332
.map((result) => result.item)
323-
: allEntities.slice(0, MAX_VISIBLE_ENTITIES_NO_SEARCH);
333+
.filter(excludeFilter)
334+
: allEntities
335+
.filter(excludeFilter)
336+
.slice(0, MAX_VISIBLE_ENTITIES_NO_SEARCH);
324337

325338
// For THREAD: merge local + server results (local first, server appended, deduped)
326339
if (props.property.specificEntityType === 'THREAD' && term) {
327340
const localIds = new Set(localResults.map((e) => e.id));
328-
const serverResults = serverEmails().filter((e) => !localIds.has(e.id));
341+
const serverResults = serverEmails()
342+
.filter((e) => !localIds.has(e.id))
343+
.filter(excludeFilter);
329344
return [...localResults, ...serverResults].slice(0, MAX_SEARCH_RESULTS);
330345
}
331346

0 commit comments

Comments
 (0)