@prorobotech/openapi-k8s-toolkit 1.2.0-alpha.18 → 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.
@@ -35430,6 +35430,7 @@
35430
35430
  cluster,
35431
35431
  nodeName,
35432
35432
  substractHeight,
35433
+ listPodTemplatesNs,
35433
35434
  ...props
35434
35435
  } = data;
35435
35436
  const { nodeTerminalDefaultProfile } = useFactoryConfig();
@@ -35439,6 +35440,7 @@
35439
35440
  return acc;
35440
35441
  }, {});
35441
35442
  const clusterPrepared = parseAll({ text: cluster, replaceValues, multiQueryData });
35443
+ const listPodTemplatesNsPrepared = listPodTemplatesNs ? parseAll({ text: listPodTemplatesNs, replaceValues, multiQueryData }) : void 0;
35442
35444
  const nodeNamePrepared = parseAll({ text: nodeName, replaceValues, multiQueryData });
35443
35445
  if (isMultiqueryLoading) {
35444
35446
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: "Loading multiquery" });
@@ -35451,6 +35453,7 @@
35451
35453
  nodeName: nodeNamePrepared,
35452
35454
  substractHeight: substractHeight || 340,
35453
35455
  defaultProfile: nodeTerminalDefaultProfile,
35456
+ listPodTemplatesNs: listPodTemplatesNsPrepared,
35454
35457
  ...props
35455
35458
  }
35456
35459
  ),
@@ -82558,6 +82561,19 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82558
82561
  ] });
82559
82562
  };
82560
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
+
82561
82577
  const CustomCard$3 = styled.div`
82562
82578
  visibility: ${({ $isVisible }) => $isVisible ? "visible" : "hidden"};
82563
82579
  height: calc(100vh - ${({ $substractHeight }) => $substractHeight}px);
@@ -82587,7 +82603,15 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82587
82603
  ProgressContainer
82588
82604
  };
82589
82605
 
82590
- 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
+ }) => {
82591
82615
  const [isLoading, setIsLoading] = React$1.useState(true);
82592
82616
  const [error, setError] = React$1.useState();
82593
82617
  const [isTerminalVisible, setIsTerminalVisible] = React$1.useState(false);
@@ -82632,12 +82656,13 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82632
82656
  const socket = new WebSocket(endpoint);
82633
82657
  socketRef.current = socket;
82634
82658
  socket.onopen = () => {
82635
- socket.send(
82636
- JSON.stringify({
82637
- type: "init",
82638
- payload: { nodeName, profile }
82639
- })
82640
- );
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 }));
82641
82666
  console.log(`[${nodeName}/${profile}]: WebSocket Client Connected`);
82642
82667
  setIsLoading(false);
82643
82668
  };
@@ -82711,7 +82736,7 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82711
82736
  socket.close();
82712
82737
  }
82713
82738
  };
82714
- }, [terminal, endpoint, nodeName, profile]);
82739
+ }, [terminal, endpoint, nodeName, profile, isCustomTemplate, podTemplateNamespace, containerName]);
82715
82740
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
82716
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%" } }) }) }),
82717
82742
  !isTerminalVisible && !error && isWarmingUp && /* @__PURE__ */ jsxRuntimeExports.jsxs(Styled$a.ProgressContainer, { $substractHeight: substractHeight, children: [
@@ -82739,32 +82764,110 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
82739
82764
  CustomSelect: CustomSelect$2
82740
82765
  };
82741
82766
 
82742
- 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
+ }) => {
82743
82775
  const [currentProfile, setCurrentProfile] = React$1.useState(defaultProfile || "general");
82776
+ const [currentContainer, setCurrentContainer] = React$1.useState();
82744
82777
  const endpoint = `/api/clusters/${cluster}/openapi-bff-ws/terminal/terminalNode/terminalNode`;
82745
- 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);
82746
82830
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
82747
- /* @__PURE__ */ jsxRuntimeExports.jsx(Styled$9.CustomSelect, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
82748
- antd.Select,
82749
- {
82750
- placeholder: "Select profile",
82751
- options: profiles.map((profile) => ({ value: profile, label: profile })),
82752
- filterOption: filterSelectOptions,
82753
- showSearch: true,
82754
- value: currentProfile,
82755
- onChange: (value) => setCurrentProfile(value)
82756
- }
82757
- ) }),
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
+ ] }),
82758
82858
  /* @__PURE__ */ jsxRuntimeExports.jsx(Spacer$1, { $space: 16, $samespace: true }),
82759
- currentProfile && /* @__PURE__ */ jsxRuntimeExports.jsx(
82859
+ canShowTerminal && /* @__PURE__ */ jsxRuntimeExports.jsx(
82760
82860
  XTerminal$1,
82761
82861
  {
82762
82862
  endpoint,
82763
82863
  nodeName,
82764
82864
  profile: currentProfile,
82865
+ isCustomTemplate: isPodTemplatesExist,
82866
+ podTemplateNamespace: isPodTemplatesExist ? listPodTemplatesNs : void 0,
82867
+ containerName: isPodTemplatesExist ? currentContainer : void 0,
82765
82868
  substractHeight
82766
82869
  },
82767
- `${cluster}-${nodeName}-${currentProfile}`
82870
+ `${cluster}-${nodeName}-${listPodTemplatesNs}-${currentProfile}-${currentContainer}`
82768
82871
  )
82769
82872
  ] });
82770
82873
  };
@@ -85411,19 +85514,6 @@ Take a look at the reducer(s) handling this action type: ${action.type}.
85411
85514
  });
85412
85515
  };
85413
85516
 
85414
- const useInfiniteSentinel = (sentinelRef, hasMore, onNeedMore) => {
85415
- React$1.useEffect(() => {
85416
- const el = sentinelRef.current;
85417
- if (!el) return void 0;
85418
- const io = new IntersectionObserver((entries) => {
85419
- const visible = entries.some((e) => e.isIntersecting);
85420
- if (visible && hasMore) onNeedMore();
85421
- });
85422
- io.observe(el);
85423
- return () => io.disconnect();
85424
- }, [sentinelRef, hasMore, onNeedMore]);
85425
- };
85426
-
85427
85517
  const useResourceScope = ({ plural, cluster, apiGroup, apiVersion }) => {
85428
85518
  const computedResourceType = apiGroup ? "api" : "builtin";
85429
85519
  const enabled = Boolean(cluster) && Boolean(plural) && (computedResourceType === "builtin" || Boolean(apiVersion));