Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arthas/ui-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@flanksource/clicky-ui": "^0.2.1",
"@flanksource/plugin-ui-sdk": "file:vendor/plugin-ui-sdk",
"@tanstack/react-query": "^5.80.7",
"lucide-react": "^0.545.0",
"preact": "^10.24.0"
Expand Down
9 changes: 9 additions & 0 deletions arthas/ui-src/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions arthas/ui-src/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export const PLUGIN_NAME = "arthas";
import { invoke } from "@flanksource/plugin-ui-sdk";

function operationURL(op: string, configID: string): string {
const base = window.location.pathname.replace(/\/ui\/.*$/, "");
const url = new URL(base + "/operations/" + op, window.location.origin);
if (configID) url.searchParams.set("config_id", configID);
return url.toString();
}
export const PLUGIN_NAME = "arthas";

export class OpError extends Error {
readonly status: number;
Expand All @@ -25,13 +20,7 @@ export async function callOp<T = unknown>(
op: string,
params: Record<string, unknown> = {},
): Promise<T> {
const configID = configIDFromURL();
const res = await fetch(operationURL(op, configID), {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "same-origin",
body: JSON.stringify(params),
});
const res = await invoke(op, params);
if (!res.ok) {
const text = await res.text();
let body: unknown = text;
Expand Down
3 changes: 3 additions & 0 deletions arthas/ui-src/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render } from "preact";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ThemeProvider, DensityProvider } from "@flanksource/clicky-ui";
import { ready } from "@flanksource/plugin-ui-sdk";
import { App } from "./App";
import { logBanner } from "./version";
import "./styles.css";
Expand All @@ -24,3 +25,5 @@ render(
</ThemeProvider>,
root,
);

ready();
1 change: 1 addition & 0 deletions arthas/ui-src/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
10 changes: 10 additions & 0 deletions arthas/ui-src/vendor/plugin-ui-sdk/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type QueryValue = string | number | boolean | null | undefined;
export type QueryParams = Record<string, QueryValue | readonly QueryValue[]>;
export type InvokeOptions = Omit<RequestInit, "body"> & {
query?: QueryParams;
};
export type StreamOptions = EventSourceInit;
export declare function invoke(operation: string, body?: unknown, options?: InvokeOptions): Promise<Response>;
export declare function stream(operation: string, query?: QueryParams, options?: StreamOptions): EventSource;
export declare function ready(): void;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions arthas/ui-src/vendor/plugin-ui-sdk/lib/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions arthas/ui-src/vendor/plugin-ui-sdk/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions arthas/ui-src/vendor/plugin-ui-sdk/lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions arthas/ui-src/vendor/plugin-ui-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@flanksource/plugin-ui-sdk",
"version": "0.1.2",
"description": "Browser UI SDK for Mission Control plugin tabs",
"type": "module",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/flanksource/plugin-ui-sdk.git"
},
"files": [
"lib",
"README.md",
"LICENSE"
],
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
}
},
"types": "./lib/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.json",
"check": "tsc -p tsconfig.json --noEmit",
"test": "vitest run",
"clean": "trash lib || true"
},
"devDependencies": {
"typescript": "^5.8.3",
"vitest": "^3.1.4"
},
"engines": {
"node": ">=20"
},
"packageManager": "pnpm@10.11.0"
}
1 change: 1 addition & 0 deletions inspektor-gadget/ui-src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@flanksource/clicky-ui": "^0.2.1",
"@flanksource/plugin-ui-sdk": "file:vendor/plugin-ui-sdk",
"@flanksource/icons": "^1.0.56",
"@tanstack/react-query": "^5.90.11",
"@vitejs/plugin-react": "^5.1.0",
Expand Down
9 changes: 9 additions & 0 deletions inspektor-gadget/ui-src/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions inspektor-gadget/ui-src/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import { createRoot } from "react-dom/client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { invoke as sdkInvoke, ready } from "@flanksource/plugin-ui-sdk";
import {
Button,
DataTable,
Expand Down Expand Up @@ -169,18 +170,8 @@ function configId() {
return new URLSearchParams(window.location.search).get("config_id") || "";
}

function hostOperationUrl(op: string) {
const params = new URLSearchParams(window.location.search);
const id = params.get("config_id") || "";
return `/api/plugins/inspektor-gadget/operations/${op}${id ? `?config_id=${encodeURIComponent(id)}` : ""}`;
}

async function invoke<T>(op: string, body: unknown = {}): Promise<T> {
const res = await fetch(hostOperationUrl(op), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
});
const res = await sdkInvoke(op, body);
if (!res.ok) {
throw new Error(await res.text());
}
Expand Down Expand Up @@ -229,7 +220,7 @@ function App() {

useEffect(() => {
refresh().catch((err) => setError(String(err)));
window.parent?.postMessage({ type: "mc.tab.ready" }, "*");
ready();
}, []);

useEffect(() => {
Expand Down
10 changes: 10 additions & 0 deletions inspektor-gadget/ui-src/vendor/plugin-ui-sdk/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type QueryValue = string | number | boolean | null | undefined;
export type QueryParams = Record<string, QueryValue | readonly QueryValue[]>;
export type InvokeOptions = Omit<RequestInit, "body"> & {
query?: QueryParams;
};
export type StreamOptions = EventSourceInit;
export declare function invoke(operation: string, body?: unknown, options?: InvokeOptions): Promise<Response>;
export declare function stream(operation: string, query?: QueryParams, options?: StreamOptions): EventSource;
export declare function ready(): void;
//# sourceMappingURL=index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading