|
| 1 | +import { useBlockId } from '@core/block'; |
1 | 2 | import { useChannelsContext } from '@core/component/ChannelsProvider'; |
2 | 3 | import { EntityIcon } from '@core/component/EntityIcon'; |
3 | 4 | import { UserIcon } from '@core/component/UserIcon'; |
@@ -31,6 +32,7 @@ import { |
31 | 32 | on, |
32 | 33 | Show, |
33 | 34 | } from 'solid-js'; |
| 35 | +import { usePropertiesContext } from '../../../context/PropertiesContext'; |
34 | 36 | import { PROPERTY_STYLES } from '../../../styles/styles'; |
35 | 37 | import type { Property } from '../../../types'; |
36 | 38 | import { useSearchInputFocus } from '../../../utils'; |
@@ -205,6 +207,10 @@ export function PropertyEntitySelector(props: EntityInputProps) { |
205 | 207 |
|
206 | 208 | let searchInputRef!: HTMLInputElement; |
207 | 209 |
|
| 210 | + // Get current entity context for self-filtering |
| 211 | + const blockId = useBlockId(); |
| 212 | + const { entityType: currentEntityType } = usePropertiesContext(); |
| 213 | + |
208 | 214 | const history = useHistory(); |
209 | 215 | const contacts = useContacts(); |
210 | 216 | const channelsContext = useChannelsContext(); |
@@ -315,17 +321,26 @@ export function PropertyEntitySelector(props: EntityInputProps) { |
315 | 321 | const MAX_VISIBLE_ENTITIES_NO_SEARCH = 50; |
316 | 322 | const MAX_SEARCH_RESULTS = 20; |
317 | 323 |
|
| 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 | + |
318 | 328 | // Get visible entities based on search |
319 | 329 | const localResults = term |
320 | 330 | ? entitySearch(allEntities, term) |
321 | 331 | .slice(0, MAX_SEARCH_RESULTS) |
322 | 332 | .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); |
324 | 337 |
|
325 | 338 | // For THREAD: merge local + server results (local first, server appended, deduped) |
326 | 339 | if (props.property.specificEntityType === 'THREAD' && term) { |
327 | 340 | 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); |
329 | 344 | return [...localResults, ...serverResults].slice(0, MAX_SEARCH_RESULTS); |
330 | 345 | } |
331 | 346 |
|
|
0 commit comments