1- /**
2- * Display list of crawls
3- *
4- * Usage example:
5- * ```ts
6- * <btrix-crawl-list>
7- * <btrix-crawl-list-item .crawl=${crawl1}>
8- * </btrix-crawl-list-item>
9- * <btrix-crawl-list-item .crawl=${crawl2}>
10- * </btrix-crawl-list-item>
11- * </btrix-crawl-list>
12- * ```
13- */
141import { localized , msg } from "@lit/localize" ;
152import { css , html , nothing , type TemplateResult } from "lit" ;
16- import {
17- customElement ,
18- property ,
19- query ,
20- queryAssignedElements ,
21- } from "lit/decorators.js" ;
3+ import { customElement , property , query } from "lit/decorators.js" ;
224import { ifDefined } from "lit/directives/if-defined.js" ;
235
246import { BtrixElement } from "@/classes/BtrixElement" ;
25- import { TailwindElement } from "@/classes/TailwindElement" ;
267import type { OverflowDropdown } from "@/components/ui/overflow-dropdown" ;
278import type { Crawl } from "@/types/crawler" ;
28- import { renderName } from "@/utils/crawler" ;
9+ import { isSkipped , renderName } from "@/utils/crawler" ;
2910import { humanizeExecutionSeconds } from "@/utils/executionTimeFormatter" ;
3011
3112/**
@@ -99,7 +80,7 @@ export class CrawlListItem extends BtrixElement {
9980 ` ;
10081 } else {
10182 const label = html `
102- < btrix-table-cell class ="clickLabel " role ="generic ">
83+ < btrix-table-cell class ="clickLabel pl-0 " role ="generic ">
10384 ${ this . safeRender ( ( workflow ) => renderName ( workflow ) ) }
10485 </ btrix-table-cell >
10586 ` ;
@@ -114,6 +95,12 @@ export class CrawlListItem extends BtrixElement {
11495 ` ;
11596 }
11697
98+ const skipped = isSkipped ( this . crawl ) ;
99+ const hasExec = Boolean ( this . crawl . crawlExecSeconds ) ;
100+ const notApplicable = html `< sl-tooltip content =${ msg ( "Not applicable" ) } >
101+ < sl-icon name ="slash " class ="text-base text-neutral-400 "> </ sl-icon >
102+ </ sl-tooltip > ` ;
103+
117104 return html `
118105 < btrix-table-row
119106 class =${ this . href
@@ -171,51 +158,62 @@ export class CrawlListItem extends BtrixElement {
171158 minute="2-digit"
172159 > </ btrix-format-date >
173160 `
174- : html `< span class ="text-neutral-400 " role ="presentation "
175- > ---</ span
176- > ` ,
161+ : notApplicable ,
177162 ) }
178163 </ btrix-table-cell >
179164 < btrix-table-cell >
180165 ${ this . safeRender ( ( crawl ) =>
181- this . localize . humanizeDuration (
182- ( crawl . finished
183- ? new Date ( crawl . finished )
184- : new Date ( )
185- ) . valueOf ( ) - new Date ( crawl . started ) . valueOf ( ) ,
186- ) ,
187- ) }
188- </ btrix-table-cell >
189- < btrix-table-cell >
190- ${ this . safeRender ( ( crawl ) =>
191- humanizeExecutionSeconds ( crawl . crawlExecSeconds ) ,
166+ ! skipped
167+ ? html `< sl-tooltip >
168+ ${ humanizeExecutionSeconds ( crawl . crawlExecSeconds , {
169+ style : "short" ,
170+ } ) }
171+ < span slot ="content ">
172+ ${ humanizeExecutionSeconds ( crawl . crawlExecSeconds , {
173+ style : "long" ,
174+ } ) }
175+ </ span >
176+ </ sl-tooltip > `
177+ : notApplicable ,
192178 ) }
193179 </ btrix-table-cell >
194180 < btrix-table-cell >
195181 ${ this . safeRender ( ( crawl ) => {
196- const pagesFound = + ( crawl . stats ?. found || 0 ) ;
197- if ( crawl . finished ) {
198- const pagesComplete = crawl . pageCount ? + crawl . pageCount : 0 ;
199- return `${ this . localize . number ( pagesComplete , { notation : "compact" } ) } ` ;
182+ if ( hasExec ) {
183+ const pagesComplete = crawl . finished
184+ ? crawl . pageCount
185+ ? + crawl . pageCount
186+ : 0
187+ : + ( crawl . stats ?. done || 0 ) ;
188+
189+ return this . localize . number ( pagesComplete , {
190+ notation : "compact" ,
191+ } ) ;
200192 }
201193
202- const pagesComplete = + ( crawl . stats ?. done || 0 ) ;
203- return `${ this . localize . number ( pagesComplete , { notation : "compact" } ) } / ${ this . localize . number ( pagesFound , { notation : "compact" } ) } ` ;
194+ return notApplicable ;
204195 } ) }
205196 </ btrix-table-cell >
206197 < btrix-table-cell >
207198 ${ this . safeRender ( ( crawl ) =>
208- this . localize . bytes (
209- crawl . finished ? crawl . fileSize || 0 : + ( crawl . stats ?. size || 0 ) ,
210- {
211- unitDisplay : "narrow" ,
212- } ,
213- ) ,
199+ hasExec
200+ ? this . localize . bytes (
201+ crawl . finished
202+ ? crawl . fileSize || 0
203+ : + ( crawl . stats ?. size || 0 ) ,
204+ )
205+ : notApplicable ,
214206 ) }
215207 </ btrix-table-cell >
216208 < btrix-table-cell >
217209 < div class ="max-w-sm truncate ">
218- ${ this . safeRender ( ( crawl ) => crawl . userName ) }
210+ ${ this . safeRender (
211+ ( crawl ) =>
212+ html `< btrix-user-chip
213+ userId =${ crawl . userid }
214+ userName =${ crawl . userName }
215+ > </ btrix-user-chip > ` ,
216+ ) }
219217 </ div >
220218 </ btrix-table-cell >
221219 < btrix-table-cell class ="pl-1 pr-1 ">
@@ -248,110 +246,3 @@ export class CrawlListItem extends BtrixElement {
248246 </ div > ` ;
249247 }
250248}
251-
252- /**
253- * @slot
254- */
255- @customElement ( "btrix-crawl-list" )
256- @localized ( )
257- export class CrawlList extends TailwindElement {
258- static styles = css `
259- btrix-table {
260- --btrix-table-cell-gap: var(--sl-spacing-x-small);
261- --btrix-table-cell-padding-x: var(--sl-spacing-small);
262- }
263-
264- btrix-table-body {
265- --btrix-table-cell-padding-y: var(--sl-spacing-2x-small);
266- }
267-
268- btrix-table-body ::slotted(*:nth-of-type(n + 2)) {
269- --btrix-border-top: 1px solid var(--sl-panel-border-color);
270- }
271-
272- btrix-table-body ::slotted(*:first-of-type) {
273- --btrix-border-radius-top: var(--sl-border-radius-medium);
274- }
275-
276- btrix-table-body ::slotted(*:last-of-type) {
277- --btrix-border-radius-bottom: var(--sl-border-radius-medium);
278- }
279- ` ;
280-
281- @property ( { type : String } )
282- collectionId ?: string ;
283-
284- @property ( { type : String } )
285- workflowId ?: string ;
286-
287- @queryAssignedElements ( { selector : "btrix-crawl-list-item" } )
288- listItems ! : HTMLElement [ ] ;
289-
290- render ( ) {
291- return html ` < style >
292- btrix-table {
293- --btrix-table-grid-template-columns : min-content [clickable-start]
294- ${ this . workflowId ? "" : `30ch ` } repeat (7 , auto) [clickable-end]
295- min-content;
296- }
297- </ style >
298- < btrix-overflow-scroll class ="-mx-3 part-[content]:px-3 ">
299- < btrix-table >
300- < btrix-table-head class ="mb-2 ">
301- < btrix-table-header-cell class ="pr-0 ">
302- < span class ="sr-only "> ${ msg ( "Status" ) } </ span >
303- </ btrix-table-header-cell >
304- ${ this . workflowId
305- ? nothing
306- : html `
307- < btrix-table-header-cell >
308- ${ msg ( "Name" ) }
309- </ btrix-table-header-cell >
310- ` }
311- < btrix-table-header-cell >
312- ${ msg ( "Started" ) }
313- </ btrix-table-header-cell >
314- < btrix-table-header-cell >
315- ${ msg ( "Finished" ) }
316- </ btrix-table-header-cell >
317- < btrix-table-header-cell
318- > ${ msg ( "Run Duration" ) } </ btrix-table-header-cell
319- >
320- < btrix-table-header-cell
321- > ${ msg ( "Execution Time" ) } </ btrix-table-header-cell
322- >
323- < btrix-table-header-cell > ${ msg ( "Pages" ) } </ btrix-table-header-cell >
324- < btrix-table-header-cell > ${ msg ( "Size" ) } </ btrix-table-header-cell >
325- < btrix-table-header-cell >
326- ${ msg ( "Run By" ) }
327- </ btrix-table-header-cell >
328- < btrix-table-header-cell class ="pl-1 pr-1 ">
329- < span class ="sr-only "> ${ msg ( "Row actions" ) } </ span >
330- </ btrix-table-header-cell >
331- </ btrix-table-head >
332- < btrix-table-body class ="rounded border ">
333- < slot @slotchange =${ this . handleSlotchange } > </ slot >
334- </ btrix-table-body >
335- </ btrix-table >
336- </ btrix-overflow-scroll > ` ;
337- }
338-
339- private handleSlotchange ( ) {
340- const assignProp = (
341- el : HTMLElement ,
342- attr : { name : string ; value : string } ,
343- ) => {
344- if ( ! el . attributes . getNamedItem ( attr . name ) ) {
345- el . setAttribute ( attr . name , attr . value ) ;
346- }
347- } ;
348-
349- this . listItems . forEach ( ( item ) => {
350- assignProp ( item , {
351- name : "collectionId" ,
352- value : this . collectionId || "" ,
353- } ) ;
354- assignProp ( item , { name : "workflowId" , value : this . workflowId || "" } ) ;
355- } ) ;
356- }
357- }
0 commit comments