1- import { consume } from "@lit/context" ;
21import { localized , msg , str } from "@lit/localize" ;
32import { type SlInput } from "@shoelace-style/shoelace" ;
4- import { nothing } from "lit" ;
3+ import { html , nothing , type PropertyValues } from "lit" ;
54import {
65 customElement ,
76 property ,
@@ -12,17 +11,23 @@ import {
1211import { ifDefined } from "lit/directives/if-defined.js" ;
1312import queryString from "query-string" ;
1413
14+ import { BtrixElement } from "@/classes/BtrixElement" ;
1515import type { Dialog } from "@/components/ui/dialog" ;
1616import { type SelectCrawlerChangeEvent } from "@/components/ui/select-crawler" ;
1717import { type SelectCrawlerProxyChangeEvent } from "@/components/ui/select-crawler-proxy" ;
18- import { proxiesContext , type ProxiesContext } from "@/context/org" ;
19- import LiteElement , { html } from "@/utils/LiteElement" ;
18+ import { CrawlerChannelImage , type Proxy } from "@/types/crawler" ;
2019
2120@customElement ( "btrix-new-browser-profile-dialog" )
2221@localized ( )
23- export class NewBrowserProfileDialog extends LiteElement {
24- @consume ( { context : proxiesContext , subscribe : true } )
25- private readonly proxies ?: ProxiesContext ;
22+ export class NewBrowserProfileDialog extends BtrixElement {
23+ @property ( { type : String } )
24+ defaultProxyId ?: string ;
25+
26+ @property ( { type : String } )
27+ defaultCrawlerChannel ?: string ;
28+
29+ @property ( { type : Array } )
30+ proxyServers ?: Proxy [ ] ;
2631
2732 @property ( { type : Boolean } )
2833 open = false ;
@@ -31,7 +36,7 @@ export class NewBrowserProfileDialog extends LiteElement {
3136 private isSubmitting = false ;
3237
3338 @state ( )
34- private crawlerChannel = "default" ;
39+ private crawlerChannel : string = CrawlerChannelImage . Default ;
3540
3641 @state ( )
3742 private proxyId : string | null = null ;
@@ -42,6 +47,22 @@ export class NewBrowserProfileDialog extends LiteElement {
4247 @queryAsync ( "#browserProfileForm" )
4348 private readonly form ! : Promise < HTMLFormElement > ;
4449
50+ protected willUpdate ( changedProperties : PropertyValues ) : void {
51+ if ( changedProperties . has ( "defaultProxyId" ) && this . defaultProxyId ) {
52+ this . proxyId = this . proxyId || this . defaultProxyId ;
53+ }
54+
55+ if (
56+ changedProperties . has ( "defaultCrawlerChannel" ) &&
57+ this . defaultCrawlerChannel
58+ ) {
59+ this . crawlerChannel =
60+ ( this . crawlerChannel !== ( CrawlerChannelImage . Default as string ) &&
61+ this . crawlerChannel ) ||
62+ this . defaultCrawlerChannel ;
63+ }
64+ }
65+
4566 render ( ) {
4667 return html ` < btrix-dialog
4768 .label =${ msg ( str `Create a New Browser Profile ` ) }
@@ -61,43 +82,28 @@ export class NewBrowserProfileDialog extends LiteElement {
6182 @reset =${ this . onReset }
6283 @submit =${ this . onSubmit }
6384 >
64- < div class ="grid ">
65- < div >
66- < label
67- id ="startingUrlLabel "
68- class ="text-sm leading-normal "
69- style ="margin-bottom: var(--sl-spacing-3x-small) "
70- > ${ msg ( "Starting URL" ) }
71- </ label >
72-
73- < div class ="flex ">
74- < sl-input
75- class ="grow "
76- name ="url "
77- placeholder =${ msg ( "https://example.com" ) }
78- autocomplete ="off"
79- aria-labelledby="startingUrlLabel"
80- required
81- >
82- </ sl-input >
83- </ div >
84- </ div >
85- </ div >
86- < div class ="mt-1 ">
85+ < btrix-url-input
86+ label =${ msg ( "Starting URL" ) }
87+ name ="url"
88+ placeholder=${ msg ( "https://example.com" ) }
89+ autocomplete="off"
90+ required
91+ >
92+ </ btrix-url-input >
93+
94+ < div class ="mt-4 ">
8795 < btrix-select-crawler
8896 .crawlerChannel =${ this . crawlerChannel }
8997 @on-change =${ ( e : SelectCrawlerChangeEvent ) =>
9098 ( this . crawlerChannel = e . detail . value ! ) }
9199 > </ btrix-select-crawler >
92100 </ div >
93- ${ this . proxies ?. servers . length
101+ ${ this . proxyServers ? .length
94102 ? html `
95103 < div class ="mt-4 ">
96104 < btrix-select-crawler-proxy
97- defaultProxyId =${ ifDefined (
98- this . proxies . default_proxy_id ?? undefined ,
99- ) }
100- .proxyServers =${ this . proxies . servers }
105+ defaultProxyId =${ ifDefined ( this . defaultProxyId || undefined ) }
106+ .proxyServers =${ this . proxyServers }
101107 .proxyId="${ this . proxyId || "" } "
102108 @btrix-change=${ ( e : SelectCrawlerProxyChangeEvent ) =>
103109 ( this . proxyId = e . detail . value ) }
@@ -156,15 +162,15 @@ export class NewBrowserProfileDialog extends LiteElement {
156162 proxyId : this . proxyId ,
157163 } ) ;
158164
159- this . notify ( {
165+ this . notify . toast ( {
160166 message : msg ( "Starting up browser for new profile..." ) ,
161167 variant : "success" ,
162168 icon : "check2-circle" ,
163169 id : "browser-profile-update-status" ,
164170 } ) ;
165171 await this . hideDialog ( ) ;
166- this . navTo (
167- `${ this . orgBasePath } /browser-profiles/profile/browser/${
172+ this . navigate . to (
173+ `${ this . navigate . orgBasePath } /browser-profiles/profile/browser/${
168174 data . browserid
169175 } ?${ queryString . stringify ( {
170176 url,
@@ -174,7 +180,7 @@ export class NewBrowserProfileDialog extends LiteElement {
174180 } ) } `,
175181 ) ;
176182 } catch ( e ) {
177- this . notify ( {
183+ this . notify . toast ( {
178184 message : msg ( "Sorry, couldn't create browser profile at this time." ) ,
179185 variant : "danger" ,
180186 icon : "exclamation-octagon" ,
@@ -199,7 +205,7 @@ export class NewBrowserProfileDialog extends LiteElement {
199205 proxyId,
200206 } ;
201207
202- return this . apiFetch < { browserid : string } > (
208+ return this . api . fetch < { browserid : string } > (
203209 `/orgs/${ this . orgId } /profiles/browser` ,
204210 {
205211 method : "POST" ,
0 commit comments