@prorobotech/openapi-k8s-toolkit 1.1.0-alpha.5 → 1.1.0-alpha.7

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");
@@ -8456,6 +8456,7 @@
8456
8456
  const [lastError, setLastError] = K.useState(void 0);
8457
8457
  const [isPaused, setIsPaused] = K.useState(paused);
8458
8458
  const [isRemoveIgnored, setIsRemoveIgnored] = K.useState(ignoreRemove);
8459
+ const [hasInitial, setHasInitial] = K.useState(false);
8459
8460
  const queryRef = K.useRef(query);
8460
8461
  const wsRef = K.useRef(null);
8461
8462
  const connectingRef = K.useRef(false);
@@ -8627,19 +8628,6 @@
8627
8628
  wsRef.current = null;
8628
8629
  connect();
8629
8630
  }, [closeWS, connect, setStatusSafe]);
8630
- K.useEffect(() => {
8631
- if (!mountedRef.current) return;
8632
- if (isEnabled) {
8633
- connect();
8634
- } else {
8635
- if (reconnectTimerRef.current) {
8636
- window.clearTimeout(reconnectTimerRef.current);
8637
- reconnectTimerRef.current = null;
8638
- }
8639
- closeWS();
8640
- setStatusSafe("closed");
8641
- }
8642
- }, [isEnabled, closeWS, connect, setStatusSafe]);
8643
8631
  const setUrl = K.useCallback(
8644
8632
  (next) => {
8645
8633
  const changed = next !== urlRef.current;
@@ -8653,6 +8641,7 @@
8653
8641
  setHasMore(false);
8654
8642
  anchorRVRef.current = void 0;
8655
8643
  haveAnchorRef.current = false;
8644
+ setHasInitial(false);
8656
8645
  }
8657
8646
  if (enabledRef.current) reconnect();
8658
8647
  }
@@ -8671,6 +8660,7 @@
8671
8660
  dispatch({ type: "RESET", items: [] });
8672
8661
  setContToken(void 0);
8673
8662
  setHasMore(false);
8663
+ setHasInitial(false);
8674
8664
  }
8675
8665
  if (prevId !== nextId) {
8676
8666
  anchorRVRef.current = void 0;
@@ -8693,6 +8683,17 @@
8693
8683
  return;
8694
8684
  }
8695
8685
  if (!frame) return;
8686
+ if (frame.type === "SERVER_LOG") {
8687
+ const level = frame.level || "info";
8688
+ const msg = frame.message;
8689
+ (console[level] || console.log).call(console, "[useListWatch][server]", msg);
8690
+ return;
8691
+ }
8692
+ if (frame.type === "INITIAL_ERROR") {
8693
+ const msg = frame.message;
8694
+ setErrorSafe(msg);
8695
+ return;
8696
+ }
8696
8697
  if (frame.type === "INITIAL") {
8697
8698
  dispatch({ type: "RESET", items: frame.items });
8698
8699
  setContToken(frame.continue);
@@ -8705,6 +8706,7 @@
8705
8706
  anchorRVRef.current = snapshotRV;
8706
8707
  haveAnchorRef.current = true;
8707
8708
  }
8709
+ setHasInitial(true);
8708
8710
  return;
8709
8711
  }
8710
8712
  if (frame.type === "PAGE") {
@@ -8763,12 +8765,26 @@
8763
8765
  K.useEffect(() => {
8764
8766
  if (wsUrl !== urlRef.current) setUrl(wsUrl);
8765
8767
  }, [wsUrl, setUrl]);
8768
+ K.useEffect(() => {
8769
+ if (!mountedRef.current) return;
8770
+ if (isEnabled) {
8771
+ connect();
8772
+ } else {
8773
+ if (reconnectTimerRef.current) {
8774
+ window.clearTimeout(reconnectTimerRef.current);
8775
+ reconnectTimerRef.current = null;
8776
+ }
8777
+ closeWS();
8778
+ setStatusSafe("closed");
8779
+ }
8780
+ }, [isEnabled, closeWS, connect, setStatusSafe]);
8766
8781
  K.useEffect(() => {
8767
8782
  if (resIdRef.current !== resId) {
8768
8783
  clearErrorSafe();
8769
8784
  suppressErrorsRef.current = true;
8770
8785
  anchorRVRef.current = void 0;
8771
8786
  haveAnchorRef.current = false;
8787
+ setHasInitial(false);
8772
8788
  resIdRef.current = resId;
8773
8789
  queryRef.current = query;
8774
8790
  if (enabledRef.current) reconnect();
@@ -8853,6 +8869,7 @@
8853
8869
  continueToken,
8854
8870
  status,
8855
8871
  lastError,
8872
+ hasInitial,
8856
8873
  setPaused: setIsPaused,
8857
8874
  setIgnoreRemove: setIsRemoveIgnored,
8858
8875
  sendScroll,
@@ -8912,7 +8929,7 @@
8912
8929
  group,
8913
8930
  version,
8914
8931
  plural,
8915
- isEnabled
8932
+ isEnabled: Boolean(isEnabled && cluster && cluster.length > 0)
8916
8933
  });
8917
8934
  const listUri = buildListUri({
8918
8935
  cluster,
@@ -8924,7 +8941,9 @@
8924
8941
  labelSelector,
8925
8942
  limit
8926
8943
  });
8927
- const restEnabled = Boolean(isEnabled && canList && !canWatch && !verbsLoading && !verbsIsError);
8944
+ const restEnabled = Boolean(
8945
+ cluster && cluster.length > 0 && isEnabled && canList && !canWatch && !verbsLoading && !verbsIsError
8946
+ );
8928
8947
  const {
8929
8948
  data: restData,
8930
8949
  isLoading: restLoading,
@@ -8945,8 +8964,10 @@
8945
8964
  refetchInterval: listRefetchInterval,
8946
8965
  isEnabled: restEnabled
8947
8966
  });
8948
- const watchEnabled = Boolean(isEnabled && canList && canWatch && !verbsLoading && !verbsIsError);
8949
- const { state, status, lastError } = useListWatch({
8967
+ const watchEnabled = Boolean(
8968
+ cluster && cluster.length > 0 && isEnabled && canList && canWatch && !verbsLoading && !verbsIsError
8969
+ );
8970
+ const { state, status, hasInitial, lastError } = useListWatch({
8950
8971
  wsUrl: `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`,
8951
8972
  paused: false,
8952
8973
  ignoreRemove: false,
@@ -8971,7 +8992,7 @@
8971
8992
  [watchEnabled, state, mapListWatchState]
8972
8993
  );
8973
8994
  const used = !isEnabled ? "disabled" : verbsLoading ? "verbs-loading" : verbsIsError ? "verbs-error" : watchEnabled ? "watch" : restEnabled ? "list" : "disabled";
8974
- const isLoading = isEnabled && verbsLoading || used === "watch" && status === "connecting" || used === "list" && restLoading;
8995
+ const isLoading = isEnabled && verbsLoading || used === "watch" && status === "connecting" || used === "watch" && status === "open" && !hasInitial || used === "list" && restLoading;
8975
8996
  let error;
8976
8997
  if (verbsIsError) error = verbsErrorObj;
8977
8998
  else if (used === "watch" && status === "closed" && lastError) error = lastError;
@@ -34397,7 +34418,7 @@
34397
34418
  JSON.stringify(fetchedDataError)
34398
34419
  ] });
34399
34420
  }
34400
- const dataFromOneOfHooks = fetchedData || fetchedDataSocket?.items;
34421
+ const dataFromOneOfHooks = fetchedData || fetchedDataSocket;
34401
34422
  const items = Array.isArray(pathToItems) ? _$1.get(dataFromOneOfHooks, pathToItems) : jp.query(dataFromOneOfHooks, `$${pathToItems}`)[0];
34402
34423
  if (!items) {
34403
34424
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
@@ -34699,6 +34720,37 @@
34699
34720
  ] });
34700
34721
  };
34701
34722
 
34723
+ const getDataByPath = ({
34724
+ prefillValuesRaw,
34725
+ pathToData
34726
+ }) => {
34727
+ return Array.isArray(pathToData) ? _$1.get(prefillValuesRaw, pathToData) : jp.query(prefillValuesRaw, `$${pathToData}`)[0];
34728
+ };
34729
+ const getPrefillValuesWithForces = ({
34730
+ prefillValues,
34731
+ forcedKind,
34732
+ apiGroup,
34733
+ apiVersion
34734
+ }) => {
34735
+ if (!forcedKind) {
34736
+ return prefillValues;
34737
+ }
34738
+ const newValues = { ...prefillValues };
34739
+ if (typeof newValues === "object" && newValues !== null) {
34740
+ if ("kind" in newValues) {
34741
+ delete newValues.kind;
34742
+ }
34743
+ if ("apiVersion" in newValues) {
34744
+ delete newValues.apiVersion;
34745
+ }
34746
+ }
34747
+ return {
34748
+ kind: forcedKind,
34749
+ apiVersion: `${apiGroup ? `${apiGroup}/` : ""}${apiVersion}`,
34750
+ ...newValues
34751
+ };
34752
+ };
34753
+
34702
34754
  const YamlEditorSingleton$1 = ({
34703
34755
  data,
34704
34756
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -34714,7 +34766,9 @@
34714
34766
  apiGroup,
34715
34767
  apiVersion,
34716
34768
  typeName,
34769
+ forcedKind,
34717
34770
  prefillValuesRequestIndex,
34771
+ pathToData,
34718
34772
  substractHeight,
34719
34773
  ...props
34720
34774
  } = data;
@@ -34740,7 +34794,9 @@
34740
34794
  const apiGroupPrepared = apiGroup ? parseAll({ text: apiGroup, replaceValues, multiQueryData }) : "no-api-group";
34741
34795
  const apiVersionPrepared = apiVersion ? parseAll({ text: apiVersion, replaceValues, multiQueryData }) : "no-api-version";
34742
34796
  const typeNamePrepared = parseAll({ text: typeName, replaceValues, multiQueryData });
34743
- const prefillValues = multiQueryData[`req${prefillValuesRequestIndex}`];
34797
+ const prefillValuesRaw = multiQueryData[`req${prefillValuesRequestIndex}`];
34798
+ const prefillValues = pathToData ? getDataByPath({ prefillValuesRaw, pathToData }) : prefillValuesRaw;
34799
+ const prefillValuesWithForces = getPrefillValuesWithForces({ prefillValues, forcedKind, apiGroup, apiVersion });
34744
34800
  if (isMultiqueryLoading) {
34745
34801
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
34746
34802
  }
@@ -34750,7 +34806,7 @@
34750
34806
  {
34751
34807
  cluster: clusterPrepared,
34752
34808
  theme,
34753
- prefillValuesSchema: prefillValues,
34809
+ prefillValuesSchema: prefillValuesWithForces,
34754
34810
  isNameSpaced,
34755
34811
  isCreate: false,
34756
34812
  type,
@@ -36146,10 +36202,15 @@
36146
36202
  ...restField,
36147
36203
  name: [name, "operator"],
36148
36204
  rules: [
36149
- { required: true, message: "Operator is required." },
36150
- {
36151
- validator: (_, v) => v && operatorOptions.includes(v) ? Promise.resolve() : Promise.reject(new Error("Select a valid operator."))
36152
- }
36205
+ ({ getFieldValue }) => ({
36206
+ validator(_, v) {
36207
+ const nameV = getFieldValue(["tolerations", name, "key"]);
36208
+ if ((nameV === "nameV" || !nameV) && (!v || v !== "Exists")) {
36209
+ return Promise.reject(new Error("Operator must be Exists when `key` is empty"));
36210
+ }
36211
+ return Promise.resolve();
36212
+ }
36213
+ })
36153
36214
  ],
36154
36215
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
36155
36216
  antd.Select,
@@ -46870,9 +46931,23 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
46870
46931
  const [yamlData, setYamlData] = K.useState("");
46871
46932
  const [isLoading, setIsLoading] = K.useState(false);
46872
46933
  const [error, setError] = K.useState();
46934
+ const initialPrefillYamlRef = K.useRef(null);
46935
+ const latestPrefillYamlRef = K.useRef(null);
46873
46936
  K.useEffect(() => {
46874
- setYamlData(stringify(prefillValuesSchema));
46937
+ if (prefillValuesSchema === void 0) return;
46938
+ const nextYaml = stringify(prefillValuesSchema);
46939
+ if (initialPrefillYamlRef.current === null) {
46940
+ initialPrefillYamlRef.current = nextYaml;
46941
+ setYamlData(nextYaml);
46942
+ }
46943
+ latestPrefillYamlRef.current = nextYaml;
46875
46944
  }, [prefillValuesSchema]);
46945
+ const handleReload = () => {
46946
+ const nextYaml = latestPrefillYamlRef.current ?? initialPrefillYamlRef.current;
46947
+ if (nextYaml !== null) {
46948
+ setYamlData(nextYaml);
46949
+ }
46950
+ };
46876
46951
  const onSubmit = () => {
46877
46952
  setIsLoading(true);
46878
46953
  setError(void 0);
@@ -46944,7 +47019,8 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
46944
47019
  ) }),
46945
47020
  !readOnly && /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$j.ControlsRowContainer, { $bgColor: token.colorPrimaryBg, $designNewLayout: designNewLayout, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Flex, { gap: designNewLayout ? 10 : 16, align: "center", children: [
46946
47021
  /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Button, { type: "primary", onClick: onSubmit, loading: isLoading, children: "Submit" }),
46947
- backlink && /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Button, { onClick: () => navigate(backlink), children: "Cancel" })
47022
+ backlink && /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Button, { onClick: () => navigate(backlink), children: "Cancel" }),
47023
+ /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Button, { onClick: handleReload, children: "Reload" })
46948
47024
  ] }) }),
46949
47025
  error && /* @__PURE__ */ jsxRuntimeExports.jsxs(
46950
47026
  antd.Modal,
@@ -50995,7 +51071,7 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
50995
51071
  fieldSelector: `metadata.name=${namespace}`,
50996
51072
  isEnabled: Boolean(clusterName !== void 0)
50997
51073
  });
50998
- const project = projectArr && projectArr.length > 0 ? projectArr[0] : void 0;
51074
+ const project = projectArr && projectArr.items && projectArr.items.length > 0 ? projectArr.items[0] : void 0;
50999
51075
  const [isDeleteModalOpen, setIsDeleteModalOpen] = K.useState(false);
51000
51076
  const updatePermission = usePermissions({
51001
51077
  group: baseProjectApiGroup,