@rxtx4816/cockpit-plugin-base-react 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -73,6 +73,8 @@ For full setup guidance, config sharing, and workflow integration see the [wiki]
73
73
 
74
74
  ## Documentation
75
75
 
76
+ **[API Reference](https://rxtx4816.github.io/cockpit-plugin-base-react/)** — auto-generated from source, updated on every release.
77
+
76
78
  - [Getting Started](docs/wiki/Getting-Started.md)
77
79
  - [Hooks](docs/wiki/Hooks.md)
78
80
  - [Components](docs/wiki/Components.md)
package/docs/wiki/Home.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  This wiki covers everything you need to build, test, and ship Cockpit plugins using `@rxtx4816/cockpit-plugin-base-react`.
4
4
 
5
+ **[API Reference](https://rxtx4816.github.io/cockpit-plugin-base-react/)** — auto-generated TypeDoc, updated on every release.
6
+
5
7
  ## Contents
6
8
 
7
9
  - [Getting Started](Getting-Started.md) — install, bootstrap, and first plugin setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxtx4816/cockpit-plugin-base-react",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Shared infrastructure for Cockpit plugins: i18n, dark theme, test setup, config presets, CI/CD workflows, and QEMU VM harness",
5
5
  "type": "module",
6
6
  "author": "RXTX4816",
package/src/cockpit.d.ts CHANGED
@@ -39,8 +39,16 @@ declare interface CockpitUser {
39
39
  groups: string[];
40
40
  }
41
41
 
42
+ declare interface CockpitPermission {
43
+ allowed: boolean | null;
44
+ addEventListener(event: "changed", callback: () => void): void;
45
+ removeEventListener(event: "changed", callback: () => void): void;
46
+ close(): void;
47
+ }
48
+
42
49
  declare const cockpit: {
43
50
  user(): Promise<CockpitUser>;
51
+ permission(options: { admin: boolean }): CockpitPermission;
44
52
  spawn(
45
53
  args: string[],
46
54
  options?: { superuser?: "try" | "require"; err?: string; environ?: string[] }
@@ -32,6 +32,10 @@ export interface ServiceControlLabels {
32
32
  confirmRestartBody?: string;
33
33
  confirmReloadTitle?: string;
34
34
  confirmReloadBody?: string;
35
+ successStart?: string;
36
+ successStop?: string;
37
+ successRestart?: string;
38
+ successReload?: string;
35
39
  }
36
40
 
37
41
  const DEFAULTS: Required<ServiceControlLabels> = {
@@ -49,6 +53,10 @@ const DEFAULTS: Required<ServiceControlLabels> = {
49
53
  confirmRestartBody: "The service will be restarted.",
50
54
  confirmReloadTitle: "Reload service?",
51
55
  confirmReloadBody: "The service configuration will be reloaded.",
56
+ successStart: "Service started",
57
+ successStop: "Service stopped",
58
+ successRestart: "Service restarted",
59
+ successReload: "Configuration reloaded",
52
60
  };
53
61
 
54
62
  interface Props {
@@ -88,12 +96,20 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
88
96
  reload: () => reloadService(unit),
89
97
  };
90
98
 
99
+ const successLabel: Record<PendingAction, string> = {
100
+ start: l.successStart,
101
+ stop: l.successStop,
102
+ restart: l.successRestart,
103
+ reload: l.successReload,
104
+ };
105
+
91
106
  async function runAction() {
92
107
  if (!pendingAction) return;
93
108
  setBusy(true);
94
109
  setActionError(null);
95
110
  try {
96
111
  await ACTION_FN[pendingAction]();
112
+ toast.success(successLabel[pendingAction]);
97
113
  setPendingAction(null);
98
114
  onRefresh?.();
99
115
  } catch (e) {
@@ -112,6 +128,7 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
112
128
 
113
129
  const isRunning = status === "active";
114
130
  const notInstalled = status === "not-installed";
131
+ const isDisabledBase = busy || loading || notInstalled;
115
132
 
116
133
  const confirmTitle: Record<PendingAction, string> = {
117
134
  start: l.confirmStartTitle,
@@ -141,7 +158,7 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
141
158
  <Button
142
159
  variant="primary"
143
160
  size="sm"
144
- isDisabled={busy || notInstalled || isRunning}
161
+ isDisabled={isDisabledBase || isRunning}
145
162
  onClick={() => openAction("start")}
146
163
  >
147
164
  {l.start}
@@ -151,7 +168,7 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
151
168
  <Button
152
169
  variant="secondary"
153
170
  size="sm"
154
- isDisabled={busy || notInstalled || !isRunning}
171
+ isDisabled={isDisabledBase || !isRunning}
155
172
  onClick={() => openAction("stop")}
156
173
  >
157
174
  {l.stop}
@@ -161,7 +178,7 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
161
178
  <Button
162
179
  variant="secondary"
163
180
  size="sm"
164
- isDisabled={busy || notInstalled || !isRunning}
181
+ isDisabled={isDisabledBase || !isRunning}
165
182
  onClick={() => openAction("restart")}
166
183
  >
167
184
  {l.restart}
@@ -171,7 +188,7 @@ export function ServiceControl({ unit, status, loading = false, onRefresh, statu
171
188
  <Button
172
189
  variant="plain"
173
190
  size="sm"
174
- isDisabled={busy || notInstalled || !isRunning}
191
+ isDisabled={isDisabledBase || !isRunning}
175
192
  onClick={() => openAction("reload")}
176
193
  >
177
194
  {l.reload}