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