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

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('styled-components'), require('react'), require('antd'), require('@ant-design/icons'), require('react-router-dom'), require('@tanstack/react-query')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'styled-components', 'react', 'antd', '@ant-design/icons', 'react-router-dom', '@tanstack/react-query'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@prorobotech/openapi-k8s-toolkit"] = {}, global.styled, global.React, global.antd, global.antdIcons, global.ReactRouterDOM, global.reactQuery));
5
- })(this, (function (exports, styled, K, antd, icons, reactRouterDom, reactQuery) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('styled-components'), require('react'), require('antd'), require('@ant-design/icons'), require('@tanstack/react-query'), require('react-router-dom')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'styled-components', 'react', 'antd', '@ant-design/icons', '@tanstack/react-query', 'react-router-dom'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@prorobotech/openapi-k8s-toolkit"] = {}, global.styled, global.React, global.antd, global.antdIcons, global.reactQuery, global.ReactRouterDOM));
5
+ })(this, (function (exports, styled, K, antd, icons, reactQuery, reactRouterDom) { 'use strict';
6
6
 
7
7
  const Spacer$1 = styled.div`
8
8
  height: ${({ $space, $spaceMob, $samespace }) => {
@@ -8315,6 +8315,63 @@
8315
8315
  padding: ${({ $padding }) => $padding};
8316
8316
  `;
8317
8317
 
8318
+ const getDirectUnknownResource = async ({ uri }) => {
8319
+ return axios.get(uri);
8320
+ };
8321
+
8322
+ const useDirectUnknownResource = ({
8323
+ uri,
8324
+ queryKey,
8325
+ refetchInterval,
8326
+ isEnabled
8327
+ }) => {
8328
+ return reactQuery.useQuery({
8329
+ queryKey,
8330
+ queryFn: async () => {
8331
+ const response = await getDirectUnknownResource({
8332
+ uri
8333
+ });
8334
+ const data = JSON.parse(JSON.stringify(response.data));
8335
+ if (data.metadata?.resourceVersion) {
8336
+ delete data.metadata.resourceVersion;
8337
+ }
8338
+ return data;
8339
+ },
8340
+ refetchInterval: refetchInterval !== void 0 ? refetchInterval : 5e3,
8341
+ enabled: isEnabled
8342
+ });
8343
+ };
8344
+
8345
+ const useK8sVerbs = ({
8346
+ cluster,
8347
+ group,
8348
+ version,
8349
+ plural,
8350
+ isEnabled = true
8351
+ }) => {
8352
+ const uri = `/api/clusters/${cluster}/openapi-bff/verbs/getResourceVerbs?${new URLSearchParams({
8353
+ ...group ? { group } : {},
8354
+ version,
8355
+ plural
8356
+ }).toString()}`;
8357
+ const { data, isError, isLoading, error } = useDirectUnknownResource({
8358
+ uri,
8359
+ queryKey: ["k8s-verbs", group || "", version, plural],
8360
+ refetchInterval: false,
8361
+ isEnabled
8362
+ });
8363
+ const verbs = data?.verbs || [];
8364
+ const canList = verbs.includes("list");
8365
+ const canWatch = verbs.includes("watch");
8366
+ return {
8367
+ canList,
8368
+ canWatch,
8369
+ isError,
8370
+ isLoading,
8371
+ error
8372
+ };
8373
+ };
8374
+
8318
8375
  const eventKey$1 = (e) => {
8319
8376
  const n = e.metadata?.name ?? "";
8320
8377
  const ns = e.metadata?.namespace ?? "";
@@ -8810,17 +8867,122 @@
8810
8867
  };
8811
8868
  };
8812
8869
 
8813
- const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
8814
- K.useEffect(() => {
8815
- const el = sentinelRef.current;
8816
- if (!el) return void 0;
8817
- const io = new IntersectionObserver((entries) => {
8818
- const visible = entries.some((e) => e.isIntersecting);
8819
- if (visible && hasMore) onNeedMore();
8820
- });
8821
- io.observe(el);
8822
- return () => io.disconnect();
8823
- }, [sentinelRef, hasMore, onNeedMore]);
8870
+ const buildApiPrefix = (group, version) => {
8871
+ const g = (group ?? "").trim();
8872
+ const v = (version ?? "").trim();
8873
+ const isCore = !g || g === "core" || g === "v1";
8874
+ return isCore ? `/api/${v}` : `/apis/${g}/${v}`;
8875
+ };
8876
+ const buildListUri = ({
8877
+ cluster,
8878
+ group,
8879
+ version,
8880
+ plural,
8881
+ namespace,
8882
+ fieldSelector,
8883
+ labelSelector,
8884
+ limit
8885
+ }) => {
8886
+ const prefix = buildApiPrefix(group, version);
8887
+ const ns = namespace ? `/namespaces/${namespace}` : "";
8888
+ const base = `/api/clusters/${cluster}/k8s${prefix}${ns}/${plural}/`;
8889
+ const params = new URLSearchParams();
8890
+ if (fieldSelector) params.append("fieldSelector", fieldSelector);
8891
+ if (labelSelector) params.append("labelSelector", labelSelector);
8892
+ if (limit) params.append("limit", String(limit));
8893
+ return params.toString() ? `${base}?${params.toString()}` : base;
8894
+ };
8895
+ const useK8sSmartResource = ({
8896
+ cluster,
8897
+ group,
8898
+ version,
8899
+ plural,
8900
+ namespace,
8901
+ fieldSelector,
8902
+ labelSelector,
8903
+ isEnabled = true,
8904
+ listRefetchInterval = 5e3,
8905
+ limit,
8906
+ mapListWatchState
8907
+ }) => {
8908
+ const {
8909
+ canList,
8910
+ canWatch,
8911
+ isLoading: verbsLoading,
8912
+ isError: verbsIsError,
8913
+ error: verbsErrorObj
8914
+ } = useK8sVerbs({
8915
+ cluster,
8916
+ group,
8917
+ version,
8918
+ plural,
8919
+ isEnabled
8920
+ });
8921
+ const listUri = buildListUri({
8922
+ cluster,
8923
+ group,
8924
+ version,
8925
+ plural,
8926
+ namespace,
8927
+ fieldSelector,
8928
+ labelSelector,
8929
+ limit
8930
+ });
8931
+ const restEnabled = Boolean(isEnabled && canList && !canWatch && !verbsLoading && !verbsIsError);
8932
+ const {
8933
+ data: restData,
8934
+ isLoading: restLoading,
8935
+ isError: restIsError,
8936
+ error: restError
8937
+ } = useDirectUnknownResource({
8938
+ uri: listUri,
8939
+ queryKey: [
8940
+ "k8s-list",
8941
+ cluster,
8942
+ group || "",
8943
+ version,
8944
+ namespace || "",
8945
+ plural,
8946
+ fieldSelector || "",
8947
+ labelSelector || ""
8948
+ ],
8949
+ refetchInterval: listRefetchInterval,
8950
+ isEnabled: restEnabled
8951
+ });
8952
+ const watchEnabled = Boolean(isEnabled && canList && canWatch && !verbsLoading && !verbsIsError);
8953
+ const { state, status, lastError } = useListWatch({
8954
+ wsUrl: `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`,
8955
+ paused: false,
8956
+ ignoreRemove: false,
8957
+ autoDrain: true,
8958
+ preserveStateOnUrlChange: true,
8959
+ isEnabled: watchEnabled,
8960
+ pageSize: limit,
8961
+ query: {
8962
+ apiGroup: group,
8963
+ apiVersion: version,
8964
+ plural,
8965
+ namespace,
8966
+ fieldSelector,
8967
+ labelSelector
8968
+ }
8969
+ });
8970
+ const defaultMap = (s) => ({ items: s.order.map((k) => s.byKey[k]) });
8971
+ const watchData = K.useMemo(
8972
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8973
+ () => watchEnabled ? (mapListWatchState ?? defaultMap)(state) : void 0,
8974
+ // eslint-disable-next-line react-hooks/exhaustive-deps
8975
+ [watchEnabled, state, mapListWatchState]
8976
+ );
8977
+ const used = !isEnabled ? "disabled" : verbsLoading ? "verbs-loading" : verbsIsError ? "verbs-error" : watchEnabled ? "watch" : restEnabled ? "list" : "disabled";
8978
+ const isLoading = isEnabled && verbsLoading || used === "watch" && status === "connecting" || used === "list" && restLoading;
8979
+ let error;
8980
+ if (verbsIsError) error = verbsErrorObj;
8981
+ else if (used === "watch" && status === "closed" && lastError) error = lastError;
8982
+ else if (used === "list" && restIsError) error = restError;
8983
+ const isError = Boolean(error);
8984
+ const data = used === "watch" ? watchData : used === "list" ? restData : void 0;
8985
+ return { data, isLoading, isError, error, _meta: { used } };
8824
8986
  };
8825
8987
 
8826
8988
  const prepareTemplate = ({
@@ -8960,7 +9122,7 @@
8960
9122
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$v.HeightDiv, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(CollapsibleBreadcrumb, { items: data.breadcrumbItems }) });
8961
9123
  };
8962
9124
  const ManageableBreadcrumbsWithDataProvider = ({
8963
- wsUrl,
9125
+ cluster,
8964
9126
  apiGroup,
8965
9127
  apiVersion,
8966
9128
  plural,
@@ -8969,28 +9131,17 @@
8969
9131
  pathname,
8970
9132
  idToCompare
8971
9133
  }) => {
8972
- const { state, status, lastError } = useListWatch({
8973
- wsUrl,
8974
- paused: false,
8975
- ignoreRemove: false,
8976
- autoDrain: true,
8977
- preserveStateOnUrlChange: true,
8978
- query: {
8979
- apiVersion,
8980
- apiGroup,
8981
- plural
8982
- },
9134
+ const {
9135
+ data: rawData,
9136
+ isError: rawDataError,
9137
+ isLoading: rawDataLoading
9138
+ } = useK8sSmartResource({
9139
+ cluster: cluster || "",
9140
+ group: apiGroup,
9141
+ version: apiVersion,
9142
+ plural,
8983
9143
  isEnabled
8984
9144
  });
8985
- const rawDataLoading = status === "connecting";
8986
- const rawDataError = status === "closed" && lastError ? lastError : void 0;
8987
- const rawData = {
8988
- items: state.order.map((key) => {
8989
- const res = state.byKey[key];
8990
- return res;
8991
- })
8992
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8993
- };
8994
9145
  if (rawDataError) {
8995
9146
  return null;
8996
9147
  }
@@ -9176,7 +9327,7 @@
9176
9327
  );
9177
9328
  };
9178
9329
  const ManageableSidebarWithDataProvider = ({
9179
- wsUrl,
9330
+ cluster,
9180
9331
  apiGroup,
9181
9332
  apiVersion,
9182
9333
  plural,
@@ -9188,28 +9339,17 @@
9188
9339
  hidden,
9189
9340
  noMarginTop
9190
9341
  }) => {
9191
- const { state, status, lastError } = useListWatch({
9192
- wsUrl,
9193
- paused: false,
9194
- ignoreRemove: false,
9195
- autoDrain: true,
9196
- preserveStateOnUrlChange: true,
9197
- query: {
9198
- apiVersion,
9199
- apiGroup,
9200
- plural
9201
- },
9342
+ const {
9343
+ data: rawData,
9344
+ isError: rawDataError,
9345
+ isLoading: rawDataLoading
9346
+ } = useK8sSmartResource({
9347
+ cluster,
9348
+ group: apiGroup,
9349
+ version: apiVersion,
9350
+ plural,
9202
9351
  isEnabled
9203
9352
  });
9204
- const rawDataLoading = status === "connecting";
9205
- const rawDataError = status === "closed" && lastError ? lastError : void 0;
9206
- const rawData = {
9207
- items: state.order.map((key) => {
9208
- const res = state.byKey[key];
9209
- return res;
9210
- })
9211
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9212
- };
9213
9353
  if (rawDataError) {
9214
9354
  return null;
9215
9355
  }
@@ -34008,33 +34148,6 @@
34008
34148
  });
34009
34149
  };
34010
34150
 
34011
- const getDirectUnknownResource = async ({ uri }) => {
34012
- return axios.get(uri);
34013
- };
34014
-
34015
- const useDirectUnknownResource = ({
34016
- uri,
34017
- queryKey,
34018
- refetchInterval,
34019
- isEnabled
34020
- }) => {
34021
- return reactQuery.useQuery({
34022
- queryKey,
34023
- queryFn: async () => {
34024
- const response = await getDirectUnknownResource({
34025
- uri
34026
- });
34027
- const data = JSON.parse(JSON.stringify(response.data));
34028
- if (data.metadata?.resourceVersion) {
34029
- delete data.metadata.resourceVersion;
34030
- }
34031
- return data;
34032
- },
34033
- refetchInterval: refetchInterval !== void 0 ? refetchInterval : 5e3,
34034
- enabled: isEnabled
34035
- });
34036
- };
34037
-
34038
34151
  const getBackLinkToTable = ({ fullPath }) => {
34039
34152
  return encodeURIComponent(fullPath);
34040
34153
  };
@@ -50308,28 +50421,14 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
50308
50421
  apiVersion,
50309
50422
  baseprefix
50310
50423
  });
50311
- const { state, status, lastError } = useListWatch({
50312
- wsUrl: `/api/clusters/${clusterName}/openapi-bff-ws/listThenWatch/listWatchWs`,
50313
- paused: false,
50314
- ignoreRemove: false,
50315
- autoDrain: true,
50316
- preserveStateOnUrlChange: true,
50317
- query: {
50318
- namespace,
50319
- apiVersion: apiVersion || "",
50320
- apiGroup,
50321
- plural: type
50322
- },
50424
+ const { data: k8sList, error: k8sListError } = useK8sSmartResource({
50425
+ cluster: clusterName || "",
50426
+ namespace,
50427
+ group: apiGroup,
50428
+ version: apiVersion || "",
50429
+ plural: type,
50323
50430
  isEnabled: Boolean(apiVersion && addedMode && type !== "direct")
50324
50431
  });
50325
- const k8sListError = status === "closed" && lastError ? lastError : void 0;
50326
- const k8sList = {
50327
- items: state.order.map((key) => {
50328
- const res = state.byKey[key];
50329
- return res;
50330
- })
50331
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50332
- };
50333
50432
  if (addedMode && (k8sListError || type === "direct") && !showZeroResources) {
50334
50433
  return null;
50335
50434
  }
@@ -50458,30 +50557,17 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
50458
50557
  const [filteredAndSortedData, setFilterAndSortedData] = K.useState([]);
50459
50558
  const [uniqueTags, setUniqueTags] = K.useState([]);
50460
50559
  const [selectedTags, setSelectedTags] = K.useState([]);
50461
- const { state, status, lastError } = useListWatch({
50462
- wsUrl: `/api/clusters/${clusterName}/openapi-bff-ws/listThenWatch/listWatchWs`,
50463
- paused: false,
50464
- ignoreRemove: false,
50465
- autoDrain: true,
50466
- preserveStateOnUrlChange: true,
50467
- query: {
50468
- apiVersion: baseApiVersion,
50469
- apiGroup: baseApiGroup,
50470
- plural: mpResourceName
50471
- },
50472
- isEnabled: clusterName !== void 0
50560
+ const {
50561
+ data: marketplacePanels,
50562
+ isLoading,
50563
+ error
50564
+ } = useK8sSmartResource({
50565
+ cluster: clusterName || "",
50566
+ group: baseApiGroup,
50567
+ version: baseApiVersion,
50568
+ plural: mpResourceName,
50569
+ isEnabled: Boolean(clusterName !== void 0)
50473
50570
  });
50474
- const isLoading = status === "connecting";
50475
- const error = status === "closed" && lastError ? lastError : void 0;
50476
- const marketplacePanels = K.useMemo(() => {
50477
- return {
50478
- items: state.order.map((key) => {
50479
- const res = state.byKey[key];
50480
- return res;
50481
- })
50482
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50483
- };
50484
- }, [state]);
50485
50571
  const createPermission = usePermissions({
50486
50572
  group: baseApiGroup,
50487
50573
  resource: mpResourceName,
@@ -50780,52 +50866,30 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
50780
50866
  children
50781
50867
  }) => {
50782
50868
  const navigate = reactRouterDom.useNavigate();
50783
- const { state, status } = useListWatch({
50784
- wsUrl: `/api/clusters/${clusterName}/openapi-bff-ws/listThenWatch/listWatchWs`,
50785
- paused: false,
50786
- ignoreRemove: false,
50787
- autoDrain: true,
50788
- preserveStateOnUrlChange: true,
50789
- query: {
50790
- apiVersion: baseApiVersion,
50791
- apiGroup: baseApiGroup,
50792
- plural: mpResourceName
50793
- },
50794
- isEnabled: clusterName !== void 0
50795
- });
50796
- const marketplaceIsLoading = status === "connecting";
50797
- const marketplacePanels = {
50798
- items: state.order.map((key) => {
50799
- const res = state.byKey[key];
50800
- return res;
50801
- })
50802
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50803
- };
50804
50869
  const {
50805
- state: stateProject,
50806
- status: statusProject,
50807
- lastError: lastErrorProject
50808
- } = useListWatch({
50809
- wsUrl: `/api/clusters/${clusterName}/openapi-bff-ws/listThenWatch/listWatchWs`,
50810
- paused: false,
50811
- ignoreRemove: false,
50812
- autoDrain: true,
50813
- preserveStateOnUrlChange: true,
50814
- query: {
50815
- apiVersion: baseProjectVersion,
50816
- apiGroup: baseProjectApiGroup,
50817
- plural: projectResourceName,
50818
- fieldSelector: `metadata.name=${namespace}`
50819
- },
50820
- isEnabled: clusterName !== void 0
50870
+ data: marketplacePanels,
50871
+ isLoading: marketplaceIsLoading
50872
+ // error: marketplaceError,
50873
+ } = useK8sSmartResource({
50874
+ cluster: clusterName || "",
50875
+ group: baseApiGroup,
50876
+ version: baseApiVersion,
50877
+ plural: mpResourceName,
50878
+ isEnabled: Boolean(clusterName !== void 0)
50821
50879
  });
50822
- const isLoading = statusProject === "connecting";
50823
- const error = statusProject === "closed" && lastErrorProject ? lastErrorProject : void 0;
50824
- const projectArr = stateProject.order.map((key) => {
50825
- const res = stateProject.byKey[key];
50826
- return res;
50880
+ const {
50881
+ data: projectArr,
50882
+ isLoading,
50883
+ error
50884
+ } = useK8sSmartResource({
50885
+ cluster: clusterName || "",
50886
+ group: baseProjectApiGroup,
50887
+ version: baseProjectVersion,
50888
+ plural: projectResourceName,
50889
+ fieldSelector: `metadata.name=${namespace}`,
50890
+ isEnabled: Boolean(clusterName !== void 0)
50827
50891
  });
50828
- const project = projectArr.length > 0 ? projectArr[0] : void 0;
50892
+ const project = projectArr && projectArr.length > 0 ? projectArr[0] : void 0;
50829
50893
  const [isDeleteModalOpen, setIsDeleteModalOpen] = K.useState(false);
50830
50894
  const updatePermission = usePermissions({
50831
50895
  group: baseProjectApiGroup,
@@ -53467,6 +53531,19 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
53467
53531
  });
53468
53532
  };
53469
53533
 
53534
+ const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
53535
+ K.useEffect(() => {
53536
+ const el = sentinelRef.current;
53537
+ if (!el) return void 0;
53538
+ const io = new IntersectionObserver((entries) => {
53539
+ const visible = entries.some((e) => e.isIntersecting);
53540
+ if (visible && hasMore) onNeedMore();
53541
+ });
53542
+ io.observe(el);
53543
+ return () => io.disconnect();
53544
+ }, [sentinelRef, hasMore, onNeedMore]);
53545
+ };
53546
+
53470
53547
  exports.BackToDefaultIcon = BackToDefaultIcon;
53471
53548
  exports.BlackholeForm = BlackholeForm;
53472
53549
  exports.BlackholeFormDataProvider = BlackholeFormDataProvider;
@@ -53585,6 +53662,8 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
53585
53662
  exports.useCrdResources = useCrdResources;
53586
53663
  exports.useDirectUnknownResource = useDirectUnknownResource;
53587
53664
  exports.useInfiniteSentinel = useInfiniteSentinel;
53665
+ exports.useK8sSmartResource = useK8sSmartResource;
53666
+ exports.useK8sVerbs = useK8sVerbs;
53588
53667
  exports.useListWatch = useListWatch;
53589
53668
  exports.usePermissions = usePermissions;
53590
53669