@@ -49,6 +49,8 @@ class JiraImport extends Page implements HasForms
4949 public $ selected_tickets ;
5050 public $ data = [];
5151 public $ ticketsDataApi ;
52+ public $ epicKeys = [];
53+ public $ taskKeys = [];
5254
5355 public function mount (): void
5456 {
@@ -199,6 +201,18 @@ public function getFormSchema(): array
199201 ->visible (fn () => $ this ->loadingTickets )
200202 ->content (__ ('Loading tickets, please wait... ' ));
201203
204+ if (!$ this ->loadingTickets && $ this ->tickets ) {
205+ $ fields [] = Placeholder::make ('selection_buttons ' )
206+ ->hiddenLabel ()
207+ ->content (new HtmlString (
208+ "<div class='flex items-center gap-2'> "
209+ . "<button type='button' wire:click='selectAllEpics' class='px-3 py-1.5 rounded-md text-xs font-bold bg-purple-600 text-white shadow-sm hover:bg-purple-700'> " . __ ('Select All Epics ' ) . "</button> "
210+ . "<button type='button' wire:click='selectAllTasks' class='px-3 py-1.5 rounded-md text-xs font-bold bg-primary-600 text-white shadow-sm hover:bg-primary-700'> " . __ ('Select All Tasks ' ) . "</button> "
211+ . "<button type='button' wire:click='deselectAll' class='px-3 py-1.5 rounded-md text-xs font-bold bg-gray-400 text-white shadow-sm hover:bg-gray-500'> " . __ ('Deselect All ' ) . "</button> "
212+ . "</div> "
213+ ));
214+ }
215+
202216 if (!$ this ->loadingTickets ) {
203217 if ($ this ->tickets ) {
204218 foreach ($ this ->tickets as $ projectKey => $ ticket ) {
@@ -213,9 +227,13 @@ public function getFormSchema(): array
213227 foreach ($ ticket ['issues ' ] as $ issue ) {
214228 $ fields [] = Checkbox::make ('data. ' . Str::slug ($ projectKey ) . '_ ' . Str::slug ($ issue ['code ' ]))
215229 ->label (function () use ($ issue ) {
230+ $ epicBadge = !empty ($ issue ['isEpic ' ])
231+ ? "<span class='inline-flex items-center px-2.5 py-1 rounded-md text-xs font-bold bg-purple-600 text-white shadow-sm'>EPIC</span> "
232+ : '' ;
216233 return new HtmlString (
217234 "<div class='w-full flex flex-col gap-1'> "
218235 . "<div class='w-full flex items-center gap-1'> "
236+ . $ epicBadge
219237 . "<div class='text-gray-700 text-xs font-light'><span class='font-medium uppercase'> " . $ issue ['code ' ] . "</span> " . $ issue ['name ' ] . "</div> "
220238 . "</div> "
221239 . "</div> "
@@ -251,8 +269,13 @@ public function import(): void
251269 if ($ this ->data && sizeof ($ this ->data )) {
252270 $ tickets = [];
253271 foreach (array_keys ($ this ->data ) as $ item ) {
254- $ url = $ this ->ticketsDataApi [$ item ];
255- $ tickets [] = $ this ->getJiraTicketDetails ($ this ->host , $ this ->username , $ this ->token , $ url );
272+ $ url = $ this ->ticketsDataApi [$ item ] ?? null ;
273+ if ($ url ) {
274+ $ ticket = $ this ->getJiraTicketDetails ($ this ->host , $ this ->username , $ this ->token , $ url );
275+ if ($ ticket ) {
276+ $ tickets [] = $ ticket ;
277+ }
278+ }
256279 }
257280 dispatch (new ImportJiraTicketsJob ($ tickets , auth ()->user ()));
258281 Notification::make ()
@@ -278,15 +301,42 @@ public function updateJiraProjects(): void
278301 public function updateJiraTickets (): void
279302 {
280303 $ this ->ticketsDataApi = [];
304+ $ this ->epicKeys = [];
305+ $ this ->taskKeys = [];
281306 $ client = $ this ->connectToJira ($ this ->host , $ this ->username , $ this ->token );
282307 $ this ->tickets = $ this ->getJiraTicketsByProject ($ client , $ this ->selected_projects );
283308 if ($ this ->tickets ) {
284309 foreach ($ this ->tickets as $ projectKey => $ ticket ) {
285310 foreach ($ ticket ['issues ' ] as $ issue ) {
286- $ this ->ticketsDataApi [Str::slug ($ projectKey ) . '_ ' . Str::slug ($ issue ['code ' ])] = $ issue ['data ' ]->self ;
311+ $ key = Str::slug ($ projectKey ) . '_ ' . Str::slug ($ issue ['code ' ]);
312+ $ this ->ticketsDataApi [$ key ] = $ issue ['data ' ]->self ;
313+ if (!empty ($ issue ['isEpic ' ])) {
314+ $ this ->epicKeys [] = $ key ;
315+ } else {
316+ $ this ->taskKeys [] = $ key ;
317+ }
287318 }
288319 }
289320 }
290321 $ this ->loadingTickets = false ;
291322 }
323+
324+ public function selectAllEpics (): void
325+ {
326+ foreach ($ this ->epicKeys as $ key ) {
327+ $ this ->data [$ key ] = true ;
328+ }
329+ }
330+
331+ public function selectAllTasks (): void
332+ {
333+ foreach ($ this ->taskKeys as $ key ) {
334+ $ this ->data [$ key ] = true ;
335+ }
336+ }
337+
338+ public function deselectAll (): void
339+ {
340+ $ this ->data = [];
341+ }
292342}
0 commit comments