@prorobotech/openapi-k8s-toolkit 1.1.0-alpha.2 → 1.1.0-alpha.3

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.
@@ -33609,49 +33609,95 @@ const AntdText = ({
33609
33609
  };
33610
33610
 
33611
33611
  const MultiQueryContext = createContext(void 0);
33612
- const MultiQueryProvider = ({ urls, dataToApplyToContext, children }) => {
33613
- const queries = useQueries({
33614
- queries: urls.map((url, index) => ({
33615
- queryKey: ["multi", index, url],
33612
+ const makeEmptyEntry = () => ({
33613
+ data: void 0,
33614
+ isLoading: false,
33615
+ isError: false,
33616
+ error: null
33617
+ });
33618
+ const aggReducer = (state, action) => {
33619
+ switch (action.type) {
33620
+ case "RESET":
33621
+ return { entries: Array.from({ length: action.total }, makeEmptyEntry) };
33622
+ case "SET_ENTRY": {
33623
+ const entries = state.entries.slice();
33624
+ entries[action.index] = action.entry;
33625
+ return { entries };
33626
+ }
33627
+ default:
33628
+ return state;
33629
+ }
33630
+ };
33631
+ const K8sFetcher = ({ index, params, dispatch }) => {
33632
+ const res = useK8sSmartResource(params);
33633
+ useEffect(() => {
33634
+ dispatch({
33635
+ type: "SET_ENTRY",
33636
+ index,
33637
+ entry: {
33638
+ data: res.data,
33639
+ isLoading: res.isLoading,
33640
+ isError: res.isError,
33641
+ error: res.error ?? null
33642
+ }
33643
+ });
33644
+ }, [index, res.data, res.isLoading, res.isError, res.error, dispatch]);
33645
+ return null;
33646
+ };
33647
+ const MultiQueryProvider = ({ items, dataToApplyToContext, children }) => {
33648
+ const k8sItems = useMemo(
33649
+ () => items.filter((x) => typeof x !== "string"),
33650
+ [items]
33651
+ );
33652
+ const urlItems = useMemo(() => items.filter((x) => typeof x === "string"), [items]);
33653
+ const k8sCount = k8sItems.length;
33654
+ const urlCount = urlItems.length;
33655
+ const [state, dispatch] = useReducer(aggReducer, { entries: Array.from({ length: k8sCount }, makeEmptyEntry) });
33656
+ useEffect(() => {
33657
+ dispatch({ type: "RESET", total: k8sCount });
33658
+ }, [k8sCount]);
33659
+ const urlQueries = useQueries({
33660
+ queries: urlItems.map((url, i) => ({
33661
+ queryKey: ["multi-url", i, url],
33616
33662
  queryFn: async () => {
33617
- const response = await axios.get(url);
33618
- return response.data;
33663
+ const res = await axios.get(url);
33664
+ return res.data;
33619
33665
  }
33620
33666
  }))
33621
33667
  });
33622
- const data = {};
33623
- const errors = [];
33624
- let isLoading;
33625
- let isError;
33626
- if (!dataToApplyToContext) {
33627
- queries.forEach((q, i) => {
33628
- data[`req${i}`] = q.data;
33629
- errors[i] = q.error ?? null;
33630
- });
33631
- isLoading = queries.some((q) => q.isLoading);
33632
- isError = queries.some((q) => q.isError);
33633
- } else {
33634
- data.req0 = dataToApplyToContext;
33635
- isLoading = false;
33636
- isError = false;
33637
- }
33638
- const value = useMemo(
33639
- () => ({ data, isLoading, isError, errors }),
33640
- /*
33641
- We use JSON.stringify(data) and JSON.stringify(errors) as dependencies to safely memoize when values deeply change (since data is a new object every render).
33642
- Alternatively, you could use a deep comparison hook or lodash.isEqual if needed.
33643
- */
33644
- // eslint-disable-next-line react-hooks/exhaustive-deps
33645
- [JSON.stringify(data), isLoading, isError, JSON.stringify(errors)]
33646
- );
33647
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MultiQueryContext.Provider, { value, children });
33668
+ const value = useMemo(() => {
33669
+ if (typeof dataToApplyToContext !== "undefined") {
33670
+ return { data: { req0: dataToApplyToContext }, isLoading: false, isError: false, errors: [] };
33671
+ }
33672
+ const data = {};
33673
+ const errors = [];
33674
+ for (let i = 0; i < k8sCount; i++) {
33675
+ const e = state.entries[i] ?? makeEmptyEntry();
33676
+ data[`req${i}`] = e.data;
33677
+ errors[i] = e.isError ? e.error : null;
33678
+ }
33679
+ for (let i = 0; i < urlCount; i++) {
33680
+ const q = urlQueries[i];
33681
+ const idx = k8sCount + i;
33682
+ data[`req${idx}`] = q?.data;
33683
+ errors[idx] = q?.isError ? q.error ?? null : null;
33684
+ }
33685
+ const isLoading = state.entries.some((e) => e.isLoading) || urlQueries.some((q) => q.isLoading);
33686
+ const isError = state.entries.some((e) => e.isError) || urlQueries.some((q) => q.isError);
33687
+ return { data, isLoading, isError, errors };
33688
+ }, [dataToApplyToContext, k8sCount, urlCount, state.entries, urlQueries]);
33689
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(MultiQueryContext.Provider, { value, children: [
33690
+ k8sItems.map((params, i) => (
33691
+ // eslint-disable-next-line react/no-array-index-key
33692
+ /* @__PURE__ */ jsxRuntimeExports.jsx(K8sFetcher, { index: i, params, dispatch }, i)
33693
+ )),
33694
+ children
33695
+ ] });
33648
33696
  };
33649
33697
  const useMultiQuery = () => {
33650
- const context = useContext(MultiQueryContext);
33651
- if (!context) {
33652
- throw new Error("useMultiQuery must be used within a MultiQueryProvider");
33653
- }
33654
- return context;
33698
+ const ctx = useContext(MultiQueryContext);
33699
+ if (!ctx) throw new Error("useMultiQuery must be used within a MultiQueryProvider");
33700
+ return ctx;
33655
33701
  };
33656
33702
 
33657
33703
  const createContextFactory = () => {
@@ -33879,7 +33925,7 @@ const MultiQuery = ({ data }) => {
33879
33925
  if (isError) {
33880
33926
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33881
33927
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33882
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33928
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33883
33929
  ] });
33884
33930
  }
33885
33931
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: preparedText });
@@ -33909,7 +33955,7 @@ const ParsedText = ({ data }) => {
33909
33955
  if (isError) {
33910
33956
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33911
33957
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33912
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33958
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33913
33959
  ] });
33914
33960
  }
33915
33961
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -33946,7 +33992,7 @@ const ProjectInfoCard$1 = ({
33946
33992
  if (isError) {
33947
33993
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
33948
33994
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
33949
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
33995
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
33950
33996
  ] });
33951
33997
  }
33952
33998
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ProjectInfoCard, { clusterName, namespace, accessGroups: parsedAccessGroups, ...props, children });
@@ -34063,7 +34109,7 @@ const StatusText$1 = ({
34063
34109
  if (isError) {
34064
34110
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34065
34111
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34066
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34112
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34067
34113
  ] });
34068
34114
  }
34069
34115
  const { type, text } = getResult({
@@ -34768,7 +34814,7 @@ const ArrayOfObjectsToKeyValues = ({ data, children }) => {
34768
34814
  if (isMultiQueryErrors) {
34769
34815
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34770
34816
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34771
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34817
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34772
34818
  ] });
34773
34819
  }
34774
34820
  const jsonRoot = multiQueryData[`req${reqIndex}`];
@@ -34835,7 +34881,7 @@ const ItemCounter = ({
34835
34881
  if (isMultiQueryErrors) {
34836
34882
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34837
34883
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34838
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34884
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34839
34885
  ] });
34840
34886
  }
34841
34887
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -34892,7 +34938,7 @@ const KeyCounter = ({
34892
34938
  if (isMultiQueryErrors) {
34893
34939
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
34894
34940
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
34895
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
34941
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
34896
34942
  ] });
34897
34943
  }
34898
34944
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35277,7 +35323,7 @@ const Labels = ({ data, children }) => {
35277
35323
  if (isMultiQueryErrors) {
35278
35324
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35279
35325
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35280
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35326
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35281
35327
  ] });
35282
35328
  }
35283
35329
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35552,7 +35598,7 @@ const LabelsToSearchParams = ({ data, children }) => {
35552
35598
  if (isMultiQueryErrors) {
35553
35599
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35554
35600
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35555
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35601
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35556
35602
  ] });
35557
35603
  }
35558
35604
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -35821,7 +35867,7 @@ const Taints = ({ data, children }) => {
35821
35867
  if (isMultiQueryErrors) {
35822
35868
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35823
35869
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
35824
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
35870
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
35825
35871
  ] });
35826
35872
  }
35827
35873
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36194,7 +36240,7 @@ const Tolerations = ({
36194
36240
  if (isMultiQueryErrors) {
36195
36241
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36196
36242
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36197
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36243
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36198
36244
  ] });
36199
36245
  }
36200
36246
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36475,7 +36521,7 @@ const Annotations = ({
36475
36521
  if (isMultiQueryErrors) {
36476
36522
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36477
36523
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36478
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36524
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36479
36525
  ] });
36480
36526
  }
36481
36527
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -36693,7 +36739,7 @@ const ConverterBytes = ({ data }) => {
36693
36739
  if (isError) {
36694
36740
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
36695
36741
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
36696
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
36742
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
36697
36743
  ] });
36698
36744
  }
36699
36745
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -37510,7 +37556,7 @@ const SecretBase64Plain = ({ data }) => {
37510
37556
  if (isError) {
37511
37557
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
37512
37558
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
37513
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
37559
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
37514
37560
  ] });
37515
37561
  }
37516
37562
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value, index) => {
@@ -37642,7 +37688,7 @@ const ResourceBadge = ({ data }) => {
37642
37688
  if (isError) {
37643
37689
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
37644
37690
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { children: "Errors:" }),
37645
- /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: e.message }, i)) })
37691
+ /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { children: errors.map((e, i) => e && /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: typeof e === "string" ? e : e.message }, i)) })
37646
37692
  ] });
37647
37693
  }
37648
37694
  const replaceValues = partsOfUrl.partsOfUrl.reduce((acc, value2, index) => {
@@ -37823,13 +37869,30 @@ const prepareUrlsToFetchForDynamicRenderer = ({
37823
37869
  );
37824
37870
  };
37825
37871
 
37872
+ const STRING_KEYS = ["cluster", "group", "version", "plural", "namespace", "fieldSelector", "labelSelector"];
37826
37873
  const DynamicRendererWithProviders = (props) => {
37827
37874
  const location = useLocation();
37828
37875
  const { urlsToFetch, dataToApplyToContext, theme, nodeTerminalDefaultProfile, disableEventBubbling } = props;
37876
+ const directUrls = urlsToFetch.filter((el) => typeof el === "string");
37877
+ const k8sResourcesUrls = urlsToFetch.filter((el) => typeof el !== "string");
37829
37878
  const preparedUrlsToFetch = prepareUrlsToFetchForDynamicRenderer({
37830
- urls: urlsToFetch,
37879
+ urls: directUrls,
37831
37880
  locationPathname: location.pathname
37832
37881
  });
37882
+ const preparedK8sResoucesUrls = k8sResourcesUrls.map((res) => {
37883
+ let next = { ...res };
37884
+ for (const key of STRING_KEYS) {
37885
+ const val = next[key];
37886
+ if (typeof val === "string" && val.length > 0) {
37887
+ const prepared = prepareUrlsToFetchForDynamicRenderer({
37888
+ urls: [val],
37889
+ locationPathname: location.pathname
37890
+ });
37891
+ next = { ...next, [key]: prepared[0] ?? val };
37892
+ }
37893
+ }
37894
+ return next;
37895
+ });
37833
37896
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
37834
37897
  CursorDefaultDiv,
37835
37898
  {
@@ -37839,7 +37902,14 @@ const DynamicRendererWithProviders = (props) => {
37839
37902
  e.stopPropagation();
37840
37903
  }
37841
37904
  },
37842
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FactoryConfigContextProvider, { value: { nodeTerminalDefaultProfile }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PartsOfUrlProvider, { value: { partsOfUrl: location.pathname.split("/") }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(MultiQueryProvider, { urls: preparedUrlsToFetch, dataToApplyToContext, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DynamicRenderer, { ...props }) }) }) }) })
37905
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FactoryConfigContextProvider, { value: { nodeTerminalDefaultProfile }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PartsOfUrlProvider, { value: { partsOfUrl: location.pathname.split("/") }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
37906
+ MultiQueryProvider,
37907
+ {
37908
+ items: [...preparedK8sResoucesUrls, ...preparedUrlsToFetch],
37909
+ dataToApplyToContext,
37910
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(DynamicRenderer, { ...props })
37911
+ }
37912
+ ) }) }) })
37843
37913
  }
37844
37914
  );
37845
37915
  };