Skip to content

Commit

Permalink
switch to org.id
Browse files Browse the repository at this point in the history
  • Loading branch information
SuaYoo committed Jul 31, 2024
1 parent 73dd232 commit a28dcfb
Show file tree
Hide file tree
Showing 32 changed files with 164 additions and 319 deletions.
16 changes: 7 additions & 9 deletions frontend/src/components/screencast.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { localized } from "@lit/localize";
import { css, html, LitElement, type PropertyValues } from "lit";
import { css, html, type PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators.js";

import { BtrixElement } from "@/classes/BtrixElement";

type Message = {
id: number; // page ID
};
Expand Down Expand Up @@ -29,14 +31,13 @@ type CloseMessage = Message & {
* Usage example:
* ```ts
* <btrix-screencast
* orgId=${orgId}
* crawlId=${crawlId}
* ></btrix-screencast>
* ```
*/
@customElement("btrix-screencast")
@localized()
export class Screencast extends LitElement {
export class Screencast extends BtrixElement {
static baseUrl = `${window.location.protocol === "https:" ? "wss" : "ws"}:${
process.env.WEBSOCKET_HOST || window.location.host
}/watch`;
Expand Down Expand Up @@ -124,9 +125,6 @@ export class Screencast extends LitElement {
@property({ type: String })
authToken?: string;

@property({ type: String })
orgId?: string;

@property({ type: String })
crawlId?: string;

Expand Down Expand Up @@ -158,7 +156,7 @@ export class Screencast extends LitElement {
changedProperties: PropertyValues<this> & Map<string, unknown>,
) {
if (
changedProperties.get("orgId") ||
changedProperties.get("appState.org") ||
changedProperties.get("crawlId") ||
changedProperties.get("authToken")
) {
Expand Down Expand Up @@ -270,7 +268,7 @@ export class Screencast extends LitElement {
* Connect to all crawler instances
*/
private connectAll() {
if (!this.orgId || !this.crawlId) {
if (!this.org || !this.crawlId) {
return;
}

Expand Down Expand Up @@ -342,7 +340,7 @@ export class Screencast extends LitElement {
*/
private connectWs(index: number): WebSocket {
const ws = new WebSocket(
`${Screencast.baseUrl}/${this.orgId}/${
`${Screencast.baseUrl}/${this.org?.id}/${
this.crawlId
}/${index}/ws?auth_bearer=${this.authToken || ""}`,
);
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/components/ui/select-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ type CrawlerChannelsAPIResponse = {
* Usage example:
* ```ts
* <btrix-select-crawler
* authState=${authState}
* orgId=${orgId}
* on-change=${({value}) => selectedCrawler = value}
* ></btrix-select-crawler>
* ```
Expand All @@ -40,9 +38,6 @@ type CrawlerChannelsAPIResponse = {
@customElement("btrix-select-crawler")
@localized()
export class SelectCrawler extends LiteElement {
@property({ type: String })
orgId!: string;

@property({ type: String })
crawlerChannel?: string;

Expand Down Expand Up @@ -159,7 +154,7 @@ export class SelectCrawler extends LiteElement {
private async getCrawlerChannels(): Promise<CrawlerChannel[]> {
const data: CrawlerChannelsAPIResponse =
await this.apiFetch<CrawlerChannelsAPIResponse>(
`/orgs/${this.orgId}/crawlconfigs/crawler-channels`,
`/orgs/${this.org?.id}/crawlconfigs/crawler-channels`,
);

return data.channels;
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/features/archived-items/crawl-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const POLL_INTERVAL_SECONDS = 5;
* Usage example:
* ```ts
* <btrix-crawl-queue
* orgId=${this.crawl.oid}
* crawlId=${this.crawl.id}
* regex="skip-me"
* ></btrix-crawl-queue>
Expand All @@ -35,9 +34,6 @@ const POLL_INTERVAL_SECONDS = 5;
@localized()
@customElement("btrix-crawl-queue")
export class CrawlQueue extends LiteElement {
@property({ type: String })
orgId?: string;

@property({ type: String })
crawlId?: string;

Expand Down Expand Up @@ -81,7 +77,7 @@ export class CrawlQueue extends LiteElement {

willUpdate(changedProperties: PropertyValues<this> & Map<string, unknown>) {
if (
changedProperties.has("orgId") ||
changedProperties.has("appState.org") ||
changedProperties.has("crawlId") ||
changedProperties.has("pageSize") ||
changedProperties.has("regex") ||
Expand Down Expand Up @@ -288,7 +284,7 @@ export class CrawlQueue extends LiteElement {
regex,
});
const data: ResponseData = await this.apiFetch(
`/orgs/${this.orgId}/crawls/${this.crawlId}/queue?${params.toString()}`,
`/orgs/${this.org?.id}/crawls/${this.crawlId}/queue?${params.toString()}`,
);

return data;
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/features/archived-items/file-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ enum AbortReason {
@localized()
@customElement("btrix-file-uploader")
export class FileUploader extends BtrixElement {
@property({ type: String })
orgId!: string;

@property({ type: Boolean })
open = false;

Expand Down Expand Up @@ -233,6 +230,8 @@ export class FileUploader extends BtrixElement {
}

private renderMetadata() {
if (!this.org) return;

const { helpText, validate } = this.validateDescriptionMax;
return html`
<div class="mb-3">
Expand Down Expand Up @@ -262,7 +261,6 @@ export class FileUploader extends BtrixElement {
<div class="mt-4">
<btrix-collections-add
.initialCollections=${this.collectionIds}
.orgId=${this.orgId}
.configId=${"temp"}
label=${msg("Add to Collection")}
@collections-change=${(e: CollectionsChangeEvent) =>
Expand Down Expand Up @@ -389,7 +387,7 @@ export class FileUploader extends BtrixElement {
private async fetchTags() {
try {
const tags = await this.api.fetch<never>(
`/orgs/${this.orgId}/crawlconfigs/tags`,
`/orgs/${this.org?.id}/crawlconfigs/tags`,
);

// Update search/filter collection
Expand Down Expand Up @@ -430,7 +428,7 @@ export class FileUploader extends BtrixElement {
});

const data = await this.upload(
`orgs/${this.orgId}/uploads/stream?${query}`,
`orgs/${this.org?.id}/uploads/stream?${query}`,
file,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class CrawlMetadataEditor extends LiteElement {
<div class="mt-4">
<btrix-collections-add
.initialCollections=${this.crawl.collectionIds}
.orgId=${this.crawl.oid}
.configId=${"temp"}
label=${msg("Add to Collection")}
@collections-change=${(e: CollectionsChangeEvent) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import LiteElement, { html } from "@/utils/LiteElement";
@localized()
@customElement("btrix-new-browser-profile-dialog")
export class NewBrowserProfileDialog extends LiteElement {
@property({ type: String })
orgId!: string;

@property({ type: Boolean })
open = false;

Expand All @@ -35,6 +32,8 @@ export class NewBrowserProfileDialog extends LiteElement {
private readonly form!: Promise<HTMLFormElement>;

render() {
if (!this.org) return;

return html` <btrix-dialog
.label=${msg(str`Create a New Browser Profile`)}
.open=${this.open}
Expand Down Expand Up @@ -77,7 +76,6 @@ export class NewBrowserProfileDialog extends LiteElement {
</div>
<div class="mt-1">
<btrix-select-crawler
orgId=${this.orgId}
.crawlerChannel=${this.crawlerChannel}
@on-change=${(e: SelectCrawlerChangeEvent) =>
(this.crawlerChannel = e.detail.value!)}
Expand Down Expand Up @@ -170,7 +168,7 @@ export class NewBrowserProfileDialog extends LiteElement {
};

return this.apiFetch<{ browserid: string }>(
`/orgs/${this.orgId}/profiles/browser`,
`/orgs/${this.org?.id}/profiles/browser`,
{
method: "POST",
body: JSON.stringify(params),
Expand Down
14 changes: 5 additions & 9 deletions frontend/src/features/browser-profiles/profile-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html, type PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators.js";
import { when } from "lit/directives/when.js";

import { TailwindElement } from "@/classes/TailwindElement";
import { BtrixElement } from "@/classes/BtrixElement";
import { APIController } from "@/controllers/api";
import { NotifyController } from "@/controllers/notify";
import { isApiError, type APIError } from "@/utils/api";
Expand All @@ -30,7 +30,6 @@ export type BrowserConnectionChange = {
* ```ts
* <btrix-profile-browser
* authState=${authState}
* orgId=${orgId}
* browserId=${browserId}
* initialNavigateUrl=${initialNavigateUrl}
* origins=${origins}
Expand All @@ -44,10 +43,7 @@ export type BrowserConnectionChange = {
*/
@localized()
@customElement("btrix-profile-browser")
export class ProfileBrowser extends TailwindElement {
@property({ type: String })
orgId!: string;

export class ProfileBrowser extends BtrixElement {
@property({ type: String })
browserId?: string;

Expand Down Expand Up @@ -441,7 +437,7 @@ export class ProfileBrowser extends TailwindElement {

private async getBrowser() {
const data = await this.api.fetch<BrowserResponseData>(
`/orgs/${this.orgId}/profiles/browser/${this.browserId}`,
`/orgs/${this.org?.id}/profiles/browser/${this.browserId}`,
);

return data;
Expand All @@ -454,7 +450,7 @@ export class ProfileBrowser extends TailwindElement {
if (!this.iframeSrc) return;

const data = this.api.fetch(
`/orgs/${this.orgId}/profiles/browser/${this.browserId}/navigate`,
`/orgs/${this.org?.id}/profiles/browser/${this.browserId}/navigate`,
{
method: "POST",
body: JSON.stringify({ url }),
Expand All @@ -472,7 +468,7 @@ export class ProfileBrowser extends TailwindElement {

try {
const data = await this.api.fetch<{ origins?: string[] }>(
`/orgs/${this.orgId}/profiles/browser/${this.browserId}/ping`,
`/orgs/${this.org?.id}/profiles/browser/${this.browserId}/ping`,
{
method: "POST",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ export type SelectBrowserProfileChangeEvent =
* Usage example:
* ```ts
* <btrix-select-browser-profile
* authState=${authState}
* orgId=${orgId}
* on-change=${({value}) => selectedProfile = value}
* ></btrix-select-browser-profile>
* ```
Expand All @@ -33,9 +31,6 @@ export type SelectBrowserProfileChangeEvent =
@customElement("btrix-select-browser-profile")
@localized()
export class SelectBrowserProfile extends LiteElement {
@property({ type: String })
orgId!: string;

@property({ type: String })
profileId?: string;

Expand Down Expand Up @@ -212,7 +207,7 @@ export class SelectBrowserProfile extends LiteElement {

private async getProfiles() {
const data = await this.apiFetch<APIPaginatedList<Profile>>(
`/orgs/${this.orgId}/profiles`,
`/orgs/${this.org?.id}/profiles`,
);

return data.items;
Expand Down
Loading

0 comments on commit a28dcfb

Please sign in to comment.