@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.17 → 1.2.0-alpha.19

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.
@@ -8630,10 +8630,6 @@
8630
8630
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$y.HeightDiv, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(CollapsibleBreadcrumb, { items: data.breadcrumbItems }) });
8631
8631
  };
8632
8632
 
8633
- const getKinds = async ({ cluster }) => {
8634
- return axios.get(`/api/clusters/${cluster}/openapi-bff/search/kinds/getKinds`);
8635
- };
8636
-
8637
8633
  const kindByGvr = (entries) => (gvr) => {
8638
8634
  const [group = "", v = "", resource = ""] = gvr.split("~", 3);
8639
8635
  const norm = (s) => s.trim();
@@ -8642,6 +8638,10 @@
8642
8638
  return uniq.length === 1 ? uniq[0] : void 0;
8643
8639
  };
8644
8640
 
8641
+ const getKinds = async ({ cluster }) => {
8642
+ return axios.get(`/api/clusters/${cluster}/openapi-bff/search/kinds/getKinds`);
8643
+ };
8644
+
8645
8645
  const parseK8sVersion$1 = (raw) => {
8646
8646
  const m = /^v(?<major>\d+)(?:(?<stage>alpha|beta)(?<stageNum>\d+)?)?$/i.exec(raw ?? "");
8647
8647
  if (!m?.groups) return { rank: 0, major: -1, stageNum: -1 };
@@ -8686,6 +8686,23 @@
8686
8686
  );
8687
8687
  };
8688
8688
 
8689
+ const useKinds = ({
8690
+ cluster,
8691
+ refetchInterval,
8692
+ isEnabled
8693
+ }) => {
8694
+ return reactQuery.useQuery({
8695
+ queryKey: ["useKinds", cluster],
8696
+ queryFn: () => getKinds({ cluster }),
8697
+ select: (data) => ({
8698
+ kindIndex: data.data,
8699
+ kindsWithVersion: getSortedKindsAll(data.data)
8700
+ }),
8701
+ refetchInterval: refetchInterval !== void 0 ? refetchInterval : 6e4,
8702
+ enabled: isEnabled
8703
+ });
8704
+ };
8705
+
8689
8706
  const getDirectUnknownResource = async ({ uri }) => {
8690
8707
  return axios.get(uri);
8691
8708
  };
@@ -9392,27 +9409,11 @@
9392
9409
  const useK8sSmartResource = (params) => {
9393
9410
  const { cluster, apiGroup, apiVersion, plural } = params;
9394
9411
  const base = useK8sSmartResourceWithoutKinds(params);
9395
- const [kindsWithVersion, setKindsWithVersion] = React$1.useState(void 0);
9396
- React$1.useEffect(() => {
9397
- let cancelled = false;
9398
- if (!cluster) {
9399
- setKindsWithVersion(void 0);
9400
- return void 0;
9401
- }
9402
- getKinds({ cluster }).then((data) => {
9403
- if (cancelled) {
9404
- return;
9405
- }
9406
- setKindsWithVersion(getSortedKindsAll(data.data));
9407
- }).catch(() => {
9408
- if (!cancelled) {
9409
- setKindsWithVersion(void 0);
9410
- }
9411
- });
9412
- return () => {
9413
- cancelled = true;
9414
- };
9415
- }, [cluster]);
9412
+ const { data: kindsData } = useKinds({
9413
+ cluster,
9414
+ isEnabled: !!cluster
9415
+ });
9416
+ const kindsWithVersion = kindsData?.kindsWithVersion;
9416
9417
  const resolveKindByGvr = React$1.useMemo(
9417
9418
  () => kindsWithVersion ? kindByGvr(kindsWithVersion) : void 0,
9418
9419
  [kindsWithVersion]
@@ -35429,6 +35430,7 @@
35429
35430
  cluster,
35430
35431
  nodeName,
35431
35432
  substractHeight,
35433
+ listPodTemplatesNs,
35432
35434
  ...props
35433
35435
  } = data;
35434
35436
  const { nodeTerminalDefaultProfile } = useFactoryConfig();
@@ -35438,6 +35440,7 @@
35438
35440
  return acc;
35439
35441
  }, {});
35440
35442
  const clusterPrepared = parseAll({ text: cluster, replaceValues, multiQueryData });
35443
+ const listPodTemplatesNsPrepared = listPodTemplatesNs ? parseAll({ text: listPodTemplatesNs, replaceValues, multiQueryData }) : void 0;
35441
35444
  const nodeNamePrepared = parseAll({ text: nodeName, replaceValues, multiQueryData });
35442
35445
  if (isMultiqueryLoading) {
35443
35446
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
@@ -35450,6 +35453,7 @@
35450
35453
  nodeName: nodeNamePrepared,
35451
35454
  substractHeight: substractHeight || 340,
35452
35455
  defaultProfile: nodeTerminalDefaultProfile,
35456
+ listPodTemplatesNs: listPodTemplatesNsPrepared,
35453
35457
  ...props
35454
35458
  }
35455
35459
  ),
@@ -46511,23 +46515,6 @@ if (_IS_WORKLET) registerPaint("spoiler", SpoilerPainterWorklet);
46511
46515
  return uniq.length === 1 ? uniq[0] : void 0;
46512
46516
  };
46513
46517
 
46514
- const useKinds = ({
46515
- cluster,
46516
- refetchInterval,
46517
- isEnabled
46518
- }) => {
46519
- return reactQuery.useQuery({
46520
- queryKey: ["useKinds", cluster],
46521
- queryFn: () => getKinds({ cluster }),
46522
- select: (data) => ({
46523
- kindIndex: data.data,
46524
- kindsWithVersion: getSortedKindsAll(data.data)
46525
- }),
46526
- refetchInterval: refetchInterval !== void 0 ? refetchInterval : 6e4,
46527
- enabled: isEnabled
46528
- });
46529
- };
46530
-
46531
46518
  const findOwnerReferencePath = (rawObject, jsonPathToArrayOfRefs, reference) => {
46532
46519
  if (!rawObject || !jsonPathToArrayOfRefs) return void 0;
46533
46520
  let arrayJsonPath = jsonPathToArrayOfRefs.trim();
@@ -82574,6 +82561,19 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82574
82561
  ] });
82575
82562
  };
82576
82563
 
82564
+ const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
82565
+ React$1.useEffect(() => {
82566
+ const el = sentinelRef.current;
82567
+ if (!el) return void 0;
82568
+ const io = new IntersectionObserver((entries) => {
82569
+ const visible = entries.some((e) => e.isIntersecting);
82570
+ if (visible && hasMore) onNeedMore();
82571
+ });
82572
+ io.observe(el);
82573
+ return () => io.disconnect();
82574
+ }, [sentinelRef, hasMore, onNeedMore]);
82575
+ };
82576
+
82577
82577
  const CustomCard$3 = styled.div`
82578
82578
  visibility: ${({ $isVisible }) => $isVisible ? "visible" : "hidden"};
82579
82579
  height: calc(100vh - ${({ $substractHeight }) => $substractHeight}px);
@@ -82603,7 +82603,15 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82603
82603
  ProgressContainer
82604
82604
  };
82605
82605
 
82606
- const XTerminal$1 = ({ endpoint, nodeName, profile, substractHeight }) => {
82606
+ const XTerminal$1 = ({
82607
+ endpoint,
82608
+ nodeName,
82609
+ profile,
82610
+ isCustomTemplate,
82611
+ podTemplateNamespace,
82612
+ containerName,
82613
+ substractHeight
82614
+ }) => {
82607
82615
  const [isLoading, setIsLoading] = React$1.useState(true);
82608
82616
  const [error, setError] = React$1.useState();
82609
82617
  const [isTerminalVisible, setIsTerminalVisible] = React$1.useState(false);
@@ -82648,12 +82656,13 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82648
82656
  const socket = new WebSocket(endpoint);
82649
82657
  socketRef.current = socket;
82650
82658
  socket.onopen = () => {
82651
- socket.send(
82652
- JSON.stringify({
82653
- type: "init",
82654
- payload: { nodeName, profile }
82655
- })
82656
- );
82659
+ const payload = { nodeName, profile };
82660
+ if (isCustomTemplate) {
82661
+ payload.podTemplateName = profile;
82662
+ payload.podTemplateNamespace = podTemplateNamespace;
82663
+ payload.containerName = containerName;
82664
+ }
82665
+ socket.send(JSON.stringify({ type: "init", payload }));
82657
82666
  console.log(`[${nodeName}/${profile}]: WebSocket Client Connected`);
82658
82667
  setIsLoading(false);
82659
82668
  };
@@ -82727,7 +82736,7 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82727
82736
  socket.close();
82728
82737
  }
82729
82738
  };
82730
- }, [terminal, endpoint, nodeName, profile]);
82739
+ }, [terminal, endpoint, nodeName, profile, isCustomTemplate, podTemplateNamespace, containerName]);
82731
82740
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
82732
82741
  /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$a.CustomCard, { $isVisible: isTerminalVisible, $substractHeight: substractHeight, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$a.FullWidthDiv, { $substractHeight: substractHeight, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: terminalRef, style: { width: "100%", height: "100%" } }) }) }),
82733
82742
  !isTerminalVisible && !error && isWarmingUp && /* @__PURE__ */ jsxRuntimeExports.jsxs(Styled$a.ProgressContainer, { $substractHeight: substractHeight, children: [
@@ -82755,32 +82764,110 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82755
82764
  CustomSelect: CustomSelect$2
82756
82765
  };
82757
82766
 
82758
- const NodeTerminal = ({ cluster, nodeName, substractHeight, defaultProfile }) => {
82767
+ const PREDEFINED_PROFILES = ["legacy", "general", "baseline", "netadmin", "restricted", "sysadmin"];
82768
+ const NodeTerminal = ({
82769
+ cluster,
82770
+ nodeName,
82771
+ substractHeight,
82772
+ defaultProfile,
82773
+ listPodTemplatesNs
82774
+ }) => {
82759
82775
  const [currentProfile, setCurrentProfile] = React$1.useState(defaultProfile || "general");
82776
+ const [currentContainer, setCurrentContainer] = React$1.useState();
82760
82777
  const endpoint = `/api/clusters/${cluster}/openapi-bff-ws/terminal/terminalNode/terminalNode`;
82761
- const profiles = ["legacy", "general", "baseline", "netadmin", "restricted", "sysadmin"];
82778
+ const isUsingPodTemplates = Boolean(listPodTemplatesNs && listPodTemplatesNs.length > 0);
82779
+ const podTemplatesWsUrl = `/api/clusters/${cluster}/openapi-bff-ws/listThenWatch/listWatchWs`;
82780
+ const podTemplates = useListWatch({
82781
+ wsUrl: podTemplatesWsUrl,
82782
+ query: {
82783
+ apiVersion: "v1",
82784
+ plural: "podtemplates",
82785
+ namespace: listPodTemplatesNs
82786
+ },
82787
+ isEnabled: isUsingPodTemplates
82788
+ });
82789
+ const podTemplateNames = React$1.useMemo(() => {
82790
+ const values = Object.values(podTemplates.state.byKey ?? {}).map((it) => String(it?.metadata?.name ?? "")).filter(Boolean);
82791
+ return Array.from(new Set(values)).sort((a, b) => a.localeCompare(b));
82792
+ }, [podTemplates.state.byKey]);
82793
+ const hasPodTemplates = podTemplateNames.length > 0;
82794
+ const isPodTemplatesExist = isUsingPodTemplates && hasPodTemplates;
82795
+ React$1.useEffect(() => {
82796
+ if (hasPodTemplates && !podTemplateNames.includes(currentProfile)) {
82797
+ setCurrentProfile(podTemplateNames[0]);
82798
+ } else if (!hasPodTemplates && !PREDEFINED_PROFILES.includes(currentProfile)) {
82799
+ setCurrentProfile(defaultProfile || "general");
82800
+ }
82801
+ }, [hasPodTemplates, podTemplateNames, currentProfile, defaultProfile]);
82802
+ const containerNames = React$1.useMemo(() => {
82803
+ if (!isPodTemplatesExist) {
82804
+ return [];
82805
+ }
82806
+ const selectedTemplate = Object.values(podTemplates.state.byKey ?? {}).find(
82807
+ (it) => it?.metadata?.name === currentProfile
82808
+ );
82809
+ const containers = selectedTemplate?.template?.spec?.containers ?? [];
82810
+ return containers.map((c) => c.name).filter((name) => Boolean(name));
82811
+ }, [isPodTemplatesExist, podTemplates.state.byKey, currentProfile]);
82812
+ const hasMultipleContainers = containerNames.length > 1;
82813
+ React$1.useEffect(() => {
82814
+ if (isPodTemplatesExist && containerNames.length > 0) {
82815
+ setCurrentContainer(containerNames[0]);
82816
+ } else {
82817
+ setCurrentContainer(void 0);
82818
+ }
82819
+ }, [isPodTemplatesExist, containerNames]);
82820
+ const selectOptions = React$1.useMemo(() => {
82821
+ if (hasPodTemplates) {
82822
+ return podTemplateNames.map((name) => ({ value: name, label: name }));
82823
+ }
82824
+ return PREDEFINED_PROFILES.map((profile) => ({
82825
+ value: profile,
82826
+ label: profile
82827
+ }));
82828
+ }, [hasPodTemplates, podTemplateNames]);
82829
+ const canShowTerminal = currentProfile && (!isPodTemplatesExist || currentContainer);
82762
82830
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
82763
- /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$9.CustomSelect, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
82764
- antd.Select,
82765
- {
82766
- placeholder: "Select profile",
82767
- options: profiles.map((profile) => ({ value: profile, label: profile })),
82768
- filterOption: filterSelectOptions,
82769
- showSearch: true,
82770
- value: currentProfile,
82771
- onChange: (value) => setCurrentProfile(value)
82772
- }
82773
- ) }),
82831
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Flex, { gap: 16, children: [
82832
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$9.CustomSelect, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
82833
+ antd.Select,
82834
+ {
82835
+ placeholder: "Select profile",
82836
+ options: selectOptions,
82837
+ filterOption: filterSelectOptions,
82838
+ showSearch: true,
82839
+ value: currentProfile,
82840
+ onChange: (value) => {
82841
+ setCurrentProfile(value);
82842
+ setCurrentContainer(void 0);
82843
+ }
82844
+ }
82845
+ ) }),
82846
+ isPodTemplatesExist && hasMultipleContainers && /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$9.CustomSelect, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
82847
+ antd.Select,
82848
+ {
82849
+ placeholder: "Select container",
82850
+ options: containerNames.map((name) => ({ value: name, label: name })),
82851
+ filterOption: filterSelectOptions,
82852
+ showSearch: true,
82853
+ value: currentContainer,
82854
+ onChange: (value) => setCurrentContainer(value)
82855
+ }
82856
+ ) })
82857
+ ] }),
82774
82858
  /* @__PURE__ */ jsxRuntimeExports.jsx(Spacer$1, { $space: 16, $samespace: true }),
82775
- currentProfile && /* @__PURE__ */ jsxRuntimeExports.jsx(
82859
+ canShowTerminal && /* @__PURE__ */ jsxRuntimeExports.jsx(
82776
82860
  XTerminal$1,
82777
82861
  {
82778
82862
  endpoint,
82779
82863
  nodeName,
82780
82864
  profile: currentProfile,
82865
+ isCustomTemplate: isPodTemplatesExist,
82866
+ podTemplateNamespace: isPodTemplatesExist ? listPodTemplatesNs : void 0,
82867
+ containerName: isPodTemplatesExist ? currentContainer : void 0,
82781
82868
  substractHeight
82782
82869
  },
82783
- `${cluster}-${nodeName}-${currentProfile}`
82870
+ `${cluster}-${nodeName}-${listPodTemplatesNs}-${currentProfile}-${currentContainer}`
82784
82871
  )
82785
82872
  ] });
82786
82873
  };
@@ -85427,19 +85514,6 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
85427
85514
  });
85428
85515
  };
85429
85516
 
85430
- const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
85431
- React$1.useEffect(() => {
85432
- const el = sentinelRef.current;
85433
- if (!el) return void 0;
85434
- const io = new IntersectionObserver((entries) => {
85435
- const visible = entries.some((e) => e.isIntersecting);
85436
- if (visible && hasMore) onNeedMore();
85437
- });
85438
- io.observe(el);
85439
- return () => io.disconnect();
85440
- }, [sentinelRef, hasMore, onNeedMore]);
85441
- };
85442
-
85443
85517
  const useResourceScope = ({ plural, cluster, apiGroup, apiVersion }) => {
85444
85518
  const computedResourceType = apiGroup ? "api" : "builtin";
85445
85519
  const enabled = Boolean(cluster) && Boolean(plural) && (computedResourceType === "builtin" || Boolean(apiVersion));