@@ -5,13 +5,14 @@ import { Command } from "cmdk";
55import { observer } from "mobx-react" ;
66import { useParams } from "next/navigation" ;
77import useSWR from "swr" ;
8- import { CommandIcon , FolderPlus , Search , Settings } from "lucide-react" ;
8+ import { CommandIcon , FolderPlus , Search , Settings , X } from "lucide-react" ;
99import { Dialog , Transition } from "@headlessui/react" ;
1010// plane imports
1111import { EUserPermissions , EUserPermissionsLevel } from "@plane/constants" ;
1212import { useTranslation } from "@plane/i18n" ;
1313import { IWorkspaceSearchResults } from "@plane/types" ;
1414import { LayersIcon , Loader , ToggleSwitch } from "@plane/ui" ;
15+ import { cn } from "@plane/utils" ;
1516// components
1617import {
1718 ChangeIssueAssignee ,
@@ -56,18 +57,11 @@ export const CommandModal: React.FC = observer(() => {
5657 const [ isSearching , setIsSearching ] = useState ( false ) ;
5758 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
5859 const [ results , setResults ] = useState < IWorkspaceSearchResults > ( {
59- results : {
60- workspace : [ ] ,
61- project : [ ] ,
62- issue : [ ] ,
63- cycle : [ ] ,
64- module : [ ] ,
65- issue_view : [ ] ,
66- page : [ ] ,
67- } ,
60+ results : { workspace : [ ] , project : [ ] , issue : [ ] , cycle : [ ] , module : [ ] , issue_view : [ ] , page : [ ] } ,
6861 } ) ;
69- const [ isWorkspaceLevel , setIsWorkspaceLevel ] = useState ( true ) ;
62+ const [ isWorkspaceLevel , setIsWorkspaceLevel ] = useState ( false ) ;
7063 const [ pages , setPages ] = useState < string [ ] > ( [ ] ) ;
64+ const [ searchInIssue , setSearchInIssue ] = useState ( false ) ;
7165 // plane hooks
7266 const { t } = useTranslation ( ) ;
7367 // hooks
@@ -96,6 +90,20 @@ export const CommandModal: React.FC = observer(() => {
9690 : null
9791 ) ;
9892
93+ useEffect ( ( ) => {
94+ if ( issueDetails && isCommandPaletteOpen ) {
95+ setSearchInIssue ( true ) ;
96+ }
97+ } , [ issueDetails , isCommandPaletteOpen ] ) ;
98+
99+ useEffect ( ( ) => {
100+ if ( ! projectId && ! isWorkspaceLevel ) {
101+ setIsWorkspaceLevel ( true ) ;
102+ } else {
103+ setIsWorkspaceLevel ( false ) ;
104+ }
105+ } , [ projectId ] ) ;
106+
99107 const closePalette = ( ) => {
100108 toggleCommandPaletteModal ( false ) ;
101109 } ;
@@ -133,15 +141,7 @@ export const CommandModal: React.FC = observer(() => {
133141 } ) ;
134142 } else {
135143 setResults ( {
136- results : {
137- workspace : [ ] ,
138- project : [ ] ,
139- issue : [ ] ,
140- cycle : [ ] ,
141- module : [ ] ,
142- issue_view : [ ] ,
143- page : [ ] ,
144- } ,
144+ results : { workspace : [ ] , project : [ ] , issue : [ ] , cycle : [ ] , module : [ ] , issue_view : [ ] , page : [ ] } ,
145145 } ) ;
146146 setIsLoading ( false ) ;
147147 setIsSearching ( false ) ;
@@ -152,7 +152,16 @@ export const CommandModal: React.FC = observer(() => {
152152
153153 return (
154154 < Transition . Root show = { isCommandPaletteOpen } afterLeave = { ( ) => setSearchTerm ( "" ) } as = { React . Fragment } >
155- < Dialog as = "div" className = "relative z-30" onClose = { ( ) => closePalette ( ) } >
155+ < Dialog
156+ as = "div"
157+ className = "relative z-30"
158+ onClose = { ( ) => {
159+ closePalette ( ) ;
160+ if ( searchInIssue ) {
161+ setSearchInIssue ( true ) ;
162+ }
163+ } }
164+ >
156165 < Transition . Child
157166 as = { React . Fragment }
158167 enter = "ease-out duration-300"
@@ -213,10 +222,7 @@ export const CommandModal: React.FC = observer(() => {
213222 nextItem . setAttribute ( "aria-selected" , "true" ) ;
214223 selectedItem ?. setAttribute ( "aria-selected" , "false" ) ;
215224 nextItem . focus ( ) ;
216- nextItem . scrollIntoView ( {
217- behavior : "smooth" ,
218- block : "nearest" ,
219- } ) ;
225+ nextItem . scrollIntoView ( { behavior : "smooth" , block : "nearest" } ) ;
220226 }
221227 }
222228
@@ -237,32 +243,40 @@ export const CommandModal: React.FC = observer(() => {
237243 }
238244 } }
239245 >
240- < div
241- className = { `flex gap-4 pb-0 sm:items-center ${
242- issueDetails ? "flex-col justify-between sm:flex-row" : "justify-end"
243- } `}
244- >
245- { issueDetails && (
246- < div className = "flex gap-2 items-center overflow-hidden truncate rounded-md bg-custom-background-80 p-2 text-xs font-medium text-custom-text-200" >
247- { issueDetails . project_id && (
248- < IssueIdentifier
249- issueId = { issueDetails . id }
250- projectId = { issueDetails . project_id }
251- textContainerClassName = "text-xs font-medium text-custom-text-200"
252- />
253- ) }
254- { issueDetails . name }
255- </ div >
256- ) }
257- </ div >
258- < div className = "relative" >
259- < Search
260- className = "pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-custom-text-200"
261- aria-hidden = "true"
262- strokeWidth = { 2 }
263- />
246+ < div className = "relative flex items-center px-4 border-0 border-b border-custom-border-200" >
247+ < div className = "flex items-center gap-2 flex-shrink-0" >
248+ < Search
249+ className = "h-4 w-4 text-custom-text-200 flex-shrink-0"
250+ aria-hidden = "true"
251+ strokeWidth = { 2 }
252+ />
253+ { searchInIssue && issueDetails && (
254+ < >
255+ < span className = "flex items-center text-sm" > Update in:</ span >
256+ < span className = "flex items-center gap-1 rounded px-1.5 py-1 text-sm bg-custom-primary-100/10 " >
257+ { issueDetails . project_id && (
258+ < IssueIdentifier
259+ issueId = { issueDetails . id }
260+ projectId = { issueDetails . project_id }
261+ textContainerClassName = "text-sm text-custom-primary-200"
262+ />
263+ ) }
264+ < X
265+ size = { 12 }
266+ strokeWidth = { 2 }
267+ className = "flex-shrink-0 cursor-pointer"
268+ onClick = { ( ) => {
269+ setSearchInIssue ( false ) ;
270+ } }
271+ />
272+ </ span >
273+ </ >
274+ ) }
275+ </ div >
264276 < Command . Input
265- className = "w-full border-0 border-b border-custom-border-200 bg-transparent p-4 pl-11 text-sm text-custom-text-100 outline-none placeholder:text-custom-text-400 focus:ring-0"
277+ className = { cn (
278+ "w-full bg-transparent p-4 text-sm text-custom-text-100 outline-none placeholder:text-custom-text-400 focus:ring-0"
279+ ) }
266280 placeholder = { placeholder }
267281 value = { searchTerm }
268282 onValueChange = { ( e ) => setSearchTerm ( e ) }
@@ -308,7 +322,7 @@ export const CommandModal: React.FC = observer(() => {
308322 { ! page && (
309323 < >
310324 { /* issue actions */ }
311- { issueId && (
325+ { issueId && issueDetails && searchInIssue && (
312326 < CommandPaletteIssueActions
313327 closePalette = { closePalette }
314328 issueDetails = { issueDetails }
0 commit comments