@prorobotech/openapi-k8s-toolkit 1.1.0-alpha.4 → 1.1.0-alpha.6

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.
@@ -8356,9 +8356,9 @@
8356
8356
  }).toString()}`;
8357
8357
  const { data, isError, isLoading, error } = useDirectUnknownResource({
8358
8358
  uri,
8359
- queryKey: ["k8s-verbs", group || "", version, plural],
8359
+ queryKey: ["k8s-verbs", cluster, group || "", version, plural],
8360
8360
  refetchInterval: false,
8361
- isEnabled
8361
+ isEnabled: Boolean(isEnabled && cluster && version && plural)
8362
8362
  });
8363
8363
  const verbs = data?.verbs || [];
8364
8364
  const canList = verbs.includes("list");
@@ -8372,11 +8372,7 @@
8372
8372
  };
8373
8373
  };
8374
8374
 
8375
- const eventKey$1 = (e) => {
8376
- const n = e.metadata?.name ?? "";
8377
- const ns = e.metadata?.namespace ?? "";
8378
- return `${ns}/${n}`;
8379
- };
8375
+ const eventKey$1 = (e) => e.metadata?.uid ?? `${e.metadata?.namespace ?? ""}/${e.metadata?.name ?? ""}`;
8380
8376
  const compareRV$1 = (a, b) => {
8381
8377
  if (a.length !== b.length) return a.length > b.length ? 1 : -1;
8382
8378
  return a > b ? 1 : a < b ? -1 : 0;
@@ -8631,19 +8627,6 @@
8631
8627
  wsRef.current = null;
8632
8628
  connect();
8633
8629
  }, [closeWS, connect, setStatusSafe]);
8634
- K.useEffect(() => {
8635
- if (!mountedRef.current) return;
8636
- if (isEnabled) {
8637
- connect();
8638
- } else {
8639
- if (reconnectTimerRef.current) {
8640
- window.clearTimeout(reconnectTimerRef.current);
8641
- reconnectTimerRef.current = null;
8642
- }
8643
- closeWS();
8644
- setStatusSafe("closed");
8645
- }
8646
- }, [isEnabled, closeWS, connect, setStatusSafe]);
8647
8630
  const setUrl = K.useCallback(
8648
8631
  (next) => {
8649
8632
  const changed = next !== urlRef.current;
@@ -8697,6 +8680,12 @@
8697
8680
  return;
8698
8681
  }
8699
8682
  if (!frame) return;
8683
+ if (frame.type === "SERVER_LOG") {
8684
+ const level = frame.level || "info";
8685
+ const msg = frame.message;
8686
+ (console[level] || console.log).call(console, "[useListWatch][server]", msg);
8687
+ return;
8688
+ }
8700
8689
  if (frame.type === "INITIAL") {
8701
8690
  dispatch({ type: "RESET", items: frame.items });
8702
8691
  setContToken(frame.continue);
@@ -8767,6 +8756,19 @@
8767
8756
  K.useEffect(() => {
8768
8757
  if (wsUrl !== urlRef.current) setUrl(wsUrl);
8769
8758
  }, [wsUrl, setUrl]);
8759
+ K.useEffect(() => {
8760
+ if (!mountedRef.current) return;
8761
+ if (isEnabled) {
8762
+ connect();
8763
+ } else {
8764
+ if (reconnectTimerRef.current) {
8765
+ window.clearTimeout(reconnectTimerRef.current);
8766
+ reconnectTimerRef.current = null;
8767
+ }
8768
+ closeWS();
8769
+ setStatusSafe("closed");
8770
+ }
8771
+ }, [isEnabled, closeWS, connect, setStatusSafe]);
8770
8772
  K.useEffect(() => {
8771
8773
  if (resIdRef.current !== resId) {
8772
8774
  clearErrorSafe();
@@ -8916,7 +8918,7 @@
8916
8918
  group,
8917
8919
  version,
8918
8920
  plural,
8919
- isEnabled
8921
+ isEnabled: Boolean(isEnabled && cluster && cluster.length > 0)
8920
8922
  });
8921
8923
  const listUri = buildListUri({
8922
8924
  cluster,
@@ -8928,7 +8930,9 @@
8928
8930
  labelSelector,
8929
8931
  limit
8930
8932
  });
8931
- const restEnabled = Boolean(isEnabled && canList && !canWatch && !verbsLoading && !verbsIsError);
8933
+ const restEnabled = Boolean(
8934
+ cluster && cluster.length > 0 && isEnabled && canList && !canWatch && !verbsLoading && !verbsIsError
8935
+ );
8932
8936
  const {
8933
8937
  data: restData,
8934
8938
  isLoading: restLoading,
@@ -8949,7 +8953,9 @@
8949
8953
  refetchInterval: listRefetchInterval,
8950
8954
  isEnabled: restEnabled
8951
8955
  });
8952
- const watchEnabled = Boolean(isEnabled && canList && canWatch && !verbsLoading && !verbsIsError);
8956
+ const watchEnabled = Boolean(
8957
+ cluster && cluster.length > 0 && isEnabled && canList && canWatch && !verbsLoading && !verbsIsError
8958
+ );
8953
8959
  const { state, status, lastError } = useListWatch({
8954
8960
  wsUrl: `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`,
8955
8961
  paused: false,
@@ -34274,6 +34280,7 @@
34274
34280
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
34275
34281
  id,
34276
34282
  fetchUrl,
34283
+ k8sResourceToFetch,
34277
34284
  pathToItems,
34278
34285
  clusterNamePartOfUrl,
34279
34286
  labelSelector,
@@ -34317,7 +34324,13 @@
34317
34324
  verb: "create",
34318
34325
  refetchInterval: false
34319
34326
  });
34320
- const fetchUrlPrepared = parseAll({ text: fetchUrl, replaceValues, multiQueryData });
34327
+ const fetchUrlPrepared = fetchUrl ? parseAll({ text: fetchUrl, replaceValues, multiQueryData }) : void 0;
34328
+ const k8sResourceToFetchPrepared = k8sResourceToFetch ? {
34329
+ group: k8sResourceToFetch.group ? parseAll({ text: k8sResourceToFetch.group, replaceValues, multiQueryData }) : void 0,
34330
+ version: parseAll({ text: k8sResourceToFetch.version, replaceValues, multiQueryData }),
34331
+ plural: parseAll({ text: k8sResourceToFetch.plural, replaceValues, multiQueryData }),
34332
+ namespace: k8sResourceToFetch.namespace ? parseAll({ text: k8sResourceToFetch.namespace, replaceValues, multiQueryData }) : void 0
34333
+ } : void 0;
34321
34334
  const sParams = new URLSearchParams();
34322
34335
  if (labelSelector && Object.keys(labelSelector).length > 0) {
34323
34336
  const parsedObject = Object.fromEntries(
@@ -34354,21 +34367,48 @@
34354
34367
  } = useDirectUnknownResource({
34355
34368
  uri: `${fetchUrlPrepared}${searchParams ? `?${searchParams}` : ""}`,
34356
34369
  queryKey: [`${fetchUrlPrepared}${searchParams ? `?${searchParams}` : ""}`],
34357
- isEnabled: !isMultiqueryLoading
34370
+ isEnabled: Boolean(!isMultiqueryLoading && fetchUrlPrepared)
34358
34371
  });
34359
- if (isMultiqueryLoading) {
34372
+ const {
34373
+ data: fetchedDataSocket,
34374
+ isLoading: isFetchedDataSocketLoading,
34375
+ error: fetchedDataSocketError
34376
+ } = useK8sSmartResource({
34377
+ cluster: clusterName || "",
34378
+ namespace: k8sResourceToFetchPrepared?.namespace,
34379
+ group: k8sResourceToFetchPrepared?.group,
34380
+ version: k8sResourceToFetchPrepared?.version || "",
34381
+ plural: k8sResourceToFetchPrepared?.plural || "",
34382
+ fieldSelector: sParams.get("fieldSelector") || void 0,
34383
+ labelSelector: sParams.get("labelSelector") || void 0,
34384
+ isEnabled: Boolean(!isMultiqueryLoading && k8sResourceToFetchPrepared)
34385
+ });
34386
+ if (fetchUrlPrepared && isMultiqueryLoading) {
34387
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
34388
+ }
34389
+ if (k8sResourceToFetchPrepared && isMultiqueryLoading) {
34360
34390
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
34361
34391
  }
34362
- if (isFetchedDataLoading) {
34392
+ if (fetchUrlPrepared && isFetchedDataLoading) {
34393
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Flex, { justify: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Spin, {}) });
34394
+ }
34395
+ if (k8sResourceToFetchPrepared && isFetchedDataSocketLoading) {
34363
34396
  return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Flex, { justify: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Spin, {}) });
34364
34397
  }
34365
- if (fetchedDataError) {
34398
+ if (fetchUrlPrepared && fetchedDataError) {
34399
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34400
+ "Error: ",
34401
+ JSON.stringify(fetchedDataError)
34402
+ ] });
34403
+ }
34404
+ if (k8sResourceToFetchPrepared && fetchedDataSocketError) {
34366
34405
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34367
34406
  "Error: ",
34368
34407
  JSON.stringify(fetchedDataError)
34369
34408
  ] });
34370
34409
  }
34371
- const items = Array.isArray(pathToItems) ? _$1.get(fetchedData, pathToItems) : jp.query(fetchedData, `$${pathToItems}`)[0];
34410
+ const dataFromOneOfHooks = fetchedData || fetchedDataSocket?.items;
34411
+ const items = Array.isArray(pathToItems) ? _$1.get(dataFromOneOfHooks, pathToItems) : jp.query(dataFromOneOfHooks, `$${pathToItems}`)[0];
34372
34412
  if (!items) {
34373
34413
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34374
34414
  "No data on this path ",
@@ -34503,15 +34543,18 @@
34503
34543
  const namespacePrepared = parseAll({ text: namespace, replaceValues, multiQueryData });
34504
34544
  const podNamePrepared = parseAll({ text: podName, replaceValues, multiQueryData });
34505
34545
  const {
34506
- data: podInfo,
34546
+ data: podInfoList,
34507
34547
  isError: isPodInfoError,
34508
34548
  isLoading: isLoadingPodInfo
34509
- } = useDirectUnknownResource({
34510
- uri: `/api/clusters/${clusterPrepared}/k8s/api/v1/namespaces/${namespacePrepared}/pods/${podNamePrepared}`,
34511
- refetchInterval: 5e3,
34512
- queryKey: [clusterPrepared || "no-cluster", "pods", podNamePrepared],
34549
+ } = useK8sSmartResource({
34550
+ cluster: clusterPrepared,
34551
+ namespace: namespacePrepared,
34552
+ version: "v1",
34553
+ plural: "pods",
34554
+ fieldSelector: `metadata.name=${podNamePrepared}`,
34513
34555
  isEnabled: clusterPrepared !== void 0 && namespacePrepared !== void 0 && podNamePrepared !== void 0
34514
34556
  });
34557
+ const podInfo = podInfoList?.items && podInfoList.items.length > 0 ? podInfoList.items[0] : void 0;
34515
34558
  if (isMultiqueryLoading) {
34516
34559
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
34517
34560
  }
@@ -34619,15 +34662,18 @@
34619
34662
  const namespacePrepared = parseAll({ text: namespace, replaceValues, multiQueryData });
34620
34663
  const podNamePrepared = parseAll({ text: podName, replaceValues, multiQueryData });
34621
34664
  const {
34622
- data: podInfo,
34665
+ data: podInfoList,
34623
34666
  isError: isPodInfoError,
34624
34667
  isLoading: isLoadingPodInfo
34625
- } = useDirectUnknownResource({
34626
- uri: `/api/clusters/${clusterPrepared}/k8s/api/v1/namespaces/${namespacePrepared}/pods/${podNamePrepared}`,
34627
- refetchInterval: 5e3,
34628
- queryKey: [clusterPrepared || "no-cluster", "pods", podNamePrepared],
34668
+ } = useK8sSmartResource({
34669
+ cluster: clusterPrepared,
34670
+ namespace: namespacePrepared,
34671
+ version: "v1",
34672
+ plural: "pods",
34673
+ fieldSelector: `metadata.name=${podNamePrepared}`,
34629
34674
  isEnabled: clusterPrepared !== void 0 && namespacePrepared !== void 0 && podNamePrepared !== void 0
34630
34675
  });
34676
+ const podInfo = podInfoList?.items && podInfoList.items.length > 0 ? podInfoList.items[0] : void 0;
34631
34677
  if (isMultiqueryLoading) {
34632
34678
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
34633
34679
  }
@@ -50959,7 +51005,7 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
50959
51005
  fieldSelector: `metadata.name=${namespace}`,
50960
51006
  isEnabled: Boolean(clusterName !== void 0)
50961
51007
  });
50962
- const project = projectArr && projectArr.length > 0 ? projectArr[0] : void 0;
51008
+ const project = projectArr && projectArr.items && projectArr.items.length > 0 ? projectArr.items[0] : void 0;
50963
51009
  const [isDeleteModalOpen, setIsDeleteModalOpen] = K.useState(false);
50964
51010
  const updatePermission = usePermissions({
50965
51011
  group: baseProjectApiGroup,