11import { localized , msg } from "@lit/localize" ;
2- import { Task } from "@lit/task" ;
32import { html , nothing , unsafeCSS } from "lit" ;
43import { customElement , property } from "lit/decorators.js" ;
54import { repeat } from "lit/directives/repeat.js" ;
6- import queryString from "query-string" ;
75
86import { collectionStatusIcon } from "../templates/collection-status-icon" ;
97
@@ -14,17 +12,12 @@ import { dedupeIcon } from "@/features/collections/templates/dedupe-icon";
1412import { dedupeStatusText } from "@/features/collections/templates/dedupe-status-text" ;
1513import type { ArchivedItemSectionName } from "@/pages/org/archived-item-detail/archived-item-detail" ;
1614import { OrgTab , WorkflowTab } from "@/routes" ;
17- import type { APIPaginatedList } from "@/types/api" ;
1815import type { ArchivedItem } from "@/types/crawler" ;
1916import { isCrawl , renderName } from "@/utils/crawler" ;
2017import { pluralOf } from "@/utils/pluralize" ;
2118
2219const styles = unsafeCSS ( stylesheet ) ;
2320
24- // FIXME Sometimes the API returns circular dependencies
25- const dependenciesWithoutSelf = ( item : ArchivedItem ) =>
26- item . requiresCrawls . filter ( ( id ) => id !== item . id ) ;
27-
2821@customElement ( "btrix-item-dependency-list" )
2922@localized ( )
3023export class ItemDependencyList extends BtrixElement {
@@ -43,51 +36,6 @@ export class ItemDependencyList extends BtrixElement {
4336 ArchivedItem | undefined
4437 > ( ) ;
4538
46- private readonly dependenciesTask = new Task ( this , {
47- task : async ( [ items ] , { signal } ) => {
48- if ( ! items ?. length ) return ;
49-
50- const itemsMap = new Map ( items . map ( ( item ) => [ item . id , item ] ) ) ;
51- const newIds : string [ ] = [ ] ;
52-
53- items . forEach ( ( item ) => {
54- dependenciesWithoutSelf ( item ) . forEach ( ( id ) => {
55- if ( ! this . dependenciesMap . get ( id ) ) {
56- const cachedItem = itemsMap . get ( id ) ;
57- if ( cachedItem ) {
58- this . dependenciesMap . set ( id , cachedItem ) ;
59- } else {
60- newIds . push ( id ) ;
61- }
62- }
63- } ) ;
64- } ) ;
65-
66- if ( ! newIds . length ) return ;
67-
68- const query = queryString . stringify (
69- {
70- ids : newIds ,
71- } ,
72- {
73- arrayFormat : "none" ,
74- } ,
75- ) ;
76-
77- const { items : dependencies } = await this . api . fetch <
78- APIPaginatedList < ArchivedItem >
79- > ( `/orgs/${ this . orgId } /all-crawls?${ query } ` , { signal } ) ;
80-
81- newIds . forEach ( ( id ) => {
82- this . dependenciesMap . set (
83- id ,
84- dependencies . find ( ( item ) => item . id === id ) ,
85- ) ;
86- } ) ;
87- } ,
88- args : ( ) => [ this . items ] as const ,
89- } ) ;
90-
9139 disconnectedCallback ( ) : void {
9240 this . timerIds . forEach ( window . clearTimeout ) ;
9341 super . disconnectedCallback ( ) ;
@@ -143,7 +91,7 @@ export class ItemDependencyList extends BtrixElement {
14391 } ;
14492
14593 private readonly renderContent = ( item : ArchivedItem ) => {
146- const dependencies = dependenciesWithoutSelf ( item ) ;
94+ const numDependencies = item . requiresCrawls . length ;
14795 const crawled = isCrawl ( item ) ;
14896 const collectionId = this . collectionId ;
14997
@@ -177,20 +125,20 @@ export class ItemDependencyList extends BtrixElement {
177125 < sl-tooltip
178126 content =${ dedupeStatusText (
179127 item . requiredByCrawls . length ,
180- dependencies . length ,
128+ numDependencies ,
181129 ) }
182130 placement ="left"
183131 hoist
184132 >
185133 ${
186- dependencies . length
134+ numDependencies
187135 ? html `
188136 ${ dedupeIcon ( {
189137 hasDependencies : true ,
190138 hasDependents : ! ! item . requiredByCrawls . length ,
191139 } ) }
192- ${ this . localize . number ( dependencies . length ) }
193- ${ pluralOf ( "dependencies" , dependencies . length ) }
140+ ${ this . localize . number ( numDependencies ) }
141+ ${ pluralOf ( "dependencies" , numDependencies ) }
194142 `
195143 : nothing
196144 }
0 commit comments