@dovetail-v2/refine 0.0.15 → 0.0.16

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.
Files changed (55) hide show
  1. package/dist/{MonacoYamlDiffEditor.15656940.js → MonacoYamlDiffEditor.4fe9fad1.js} +1 -1
  2. package/dist/{index.82c82bb4.js → index.8dfa48ab.js} +656 -151
  3. package/dist/refine.js +72 -62
  4. package/dist/refine.umd.cjs +596 -91
  5. package/dist/style.css +1 -32594
  6. package/lib/src/Dovetail.d.ts +0 -2
  7. package/lib/src/components/CronJobDropdown/index.d.ts +2 -2
  8. package/lib/src/components/DrawerShow/DrawerShow.d.ts +1 -1
  9. package/lib/src/components/K8sDropdown/index.d.ts +2 -2
  10. package/lib/src/components/ListPage/index.d.ts +1 -1
  11. package/lib/src/components/PageShow/PageShow.d.ts +2 -2
  12. package/lib/src/components/PodLog/index.d.ts +1 -1
  13. package/lib/src/components/ResourceCRUD/create/index.d.ts +1 -1
  14. package/lib/src/components/ResourceCRUD/list/index.d.ts +2 -2
  15. package/lib/src/components/ResourceCRUD/show/index.d.ts +2 -2
  16. package/lib/src/components/ShowContent/ShowContent.d.ts +2 -2
  17. package/lib/src/components/ShowContent/fields.d.ts +1 -1
  18. package/lib/src/components/Table/index.d.ts +6 -2
  19. package/lib/src/components/WorkloadDropdown/index.d.ts +2 -2
  20. package/lib/src/components/WorkloadReplicas/index.d.ts +1 -1
  21. package/lib/src/contexts/component.d.ts +6 -0
  22. package/lib/src/contexts/global-store.d.ts +6 -0
  23. package/lib/src/contexts/index.d.ts +1 -0
  24. package/lib/src/hooks/index.d.ts +1 -0
  25. package/lib/src/hooks/useEagleTable/columns.d.ts +3 -3
  26. package/lib/src/hooks/useEagleTable/useEagleTable.d.ts +2 -2
  27. package/lib/src/hooks/useGlobalStore.d.ts +3 -0
  28. package/lib/src/index.d.ts +2 -0
  29. package/lib/src/main.d.ts +2 -0
  30. package/lib/src/model/pod-model.d.ts +2 -0
  31. package/lib/src/models/cronjob-model.d.ts +14 -0
  32. package/lib/src/models/event-model.d.ts +8 -0
  33. package/lib/src/models/index.d.ts +9 -0
  34. package/lib/src/models/job-model.d.ts +15 -0
  35. package/lib/src/models/pod-metrics-model.d.ts +9 -0
  36. package/lib/src/models/pod-model.d.ts +20 -0
  37. package/lib/src/models/resource-model.d.ts +21 -0
  38. package/lib/src/models/types/index.d.ts +1 -0
  39. package/lib/src/models/types/metric.d.ts +25 -0
  40. package/lib/src/models/workload-base-model.d.ts +13 -0
  41. package/lib/src/models/workload-model.d.ts +17 -0
  42. package/lib/src/pages/configmaps/index.d.ts +1 -1
  43. package/lib/src/pages/jobs/index.d.ts +1 -1
  44. package/lib/src/pages/secrets/index.d.ts +1 -1
  45. package/lib/src/pages/services/index.d.ts +1 -1
  46. package/lib/src/plugins/index.d.ts +2 -0
  47. package/lib/src/plugins/model-plugin.d.ts +12 -0
  48. package/lib/src/plugins/relation-plugin.d.ts +27 -0
  49. package/lib/src/plugins/type.d.ts +8 -0
  50. package/lib/src/providers/router-provider/index.d.ts +1 -1
  51. package/lib/src/types/resource.d.ts +4 -5
  52. package/lib/src/utils/error.d.ts +2 -2
  53. package/lib/src/utils/match-selector.d.ts +3 -0
  54. package/lib/src/utils/selector.d.ts +1 -1
  55. package/package.json +10 -4
@@ -5,8 +5,8 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  (function(global2, factory) {
8
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@refinedev/core"), require("qs"), require("react"), require("react-router-dom"), require("@cloudtower/eagle"), require("js-yaml"), require("lodash-es"), require("sunflower-antd"), require("i18next"), require("@cloudtower/icons-react"), require("monaco-editor"), require("monaco-yaml"), require("react-dom"), require("antd"), require("k8s-api-provider")) : typeof define === "function" && define.amd ? define(["exports", "@refinedev/core", "qs", "react", "react-router-dom", "@cloudtower/eagle", "js-yaml", "lodash-es", "sunflower-antd", "i18next", "@cloudtower/icons-react", "monaco-editor", "monaco-yaml", "react-dom", "antd", "k8s-api-provider"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.dovetail = {}, global2.core, global2.qs, global2.React, global2.reactRouterDom, global2.eagle, global2.yaml, global2.lodashEs, global2.sunflowerAntd, global2.i18n, global2.iconsReact, global2.monaco, global2.monacoYaml, global2.ReactDOM, global2.antd$1, global2.k8sApiProvider));
9
- })(this, function(exports2, core, qs, React, reactRouterDom, eagle, yaml, lodashEs, sunflowerAntd, i18n, iconsReact, monaco, monacoYaml, ReactDOM, antd$1, k8sApiProvider) {
8
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@refinedev/core"), require("qs"), require("react"), require("react-router-dom"), require("@cloudtower/eagle"), require("js-yaml"), require("lodash-es"), require("sunflower-antd"), require("i18next"), require("@cloudtower/icons-react"), require("monaco-editor"), require("monaco-yaml"), require("react-dom"), require("antd"), require("k8s-api-provider")) : typeof define === "function" && define.amd ? define(["exports", "@refinedev/core", "qs", "react", "react-router-dom", "@cloudtower/eagle", "js-yaml", "lodash-es", "sunflower-antd", "i18next", "@cloudtower/icons-react", "monaco-editor", "monaco-yaml", "react-dom", "antd", "k8s-api-provider"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.dovetail = {}, global2.core, global2.qs, global2.React, global2.reactRouterDom, global2.eagle, global2.yaml, global2.lodashEs, global2.sunflowerAntd, global2.i18n, global2.iconsReact, global2.monaco, global2.monacoYaml, global2.ReactDOM, global2.antd, global2.k8sApiProvider));
9
+ })(this, function(exports2, core, qs, React, reactRouterDom, eagle, yaml, lodashEs, sunflowerAntd, i18n, iconsReact, monaco, monacoYaml, ReactDOM, antd, k8sApiProvider) {
10
10
  "use strict";
11
11
  const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
12
12
  function _interopNamespace(e) {
@@ -6782,6 +6782,10 @@ var __publicField = (obj, key, value) => {
6782
6782
  const content = yaml__default.default.dump(merged);
6783
6783
  return content.replace(/(')(#.+?)(')/g, "$2").replace(/( +)(#)/g, "$2$1");
6784
6784
  }
6785
+ const GlobalStoreContext = React.createContext({});
6786
+ const useGlobalStore = () => {
6787
+ return React.useContext(GlobalStoreContext);
6788
+ };
6785
6789
  const useEagleForm = ({
6786
6790
  action,
6787
6791
  resource,
@@ -6820,6 +6824,7 @@ var __publicField = (obj, key, value) => {
6820
6824
  const [editorErrors, setEditorErrors] = React.useState([]);
6821
6825
  const [errorResponseBody, setErrorResponseBody] = React.useState(null);
6822
6826
  const useResourceResult = core.useResource();
6827
+ const { globalStore } = useGlobalStore();
6823
6828
  const kit = eagle.useUIKit();
6824
6829
  const {
6825
6830
  schema,
@@ -6924,7 +6929,7 @@ var __publicField = (obj, key, value) => {
6924
6929
  }
6925
6930
  }
6926
6931
  };
6927
- const initialValues = ((_c = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _c.data) ? queryResult.data.data.restore() : void 0;
6932
+ const initialValues = ((_c = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _c.data) ? globalStore == null ? void 0 : globalStore.restoreItem(queryResult.data.data) : void 0;
6928
6933
  if (initialValues) {
6929
6934
  pruneBeforeEdit(initialValues);
6930
6935
  }
@@ -7410,7 +7415,7 @@ var __publicField = (obj, key, value) => {
7410
7415
  const currentReplicas = lodashEs.get(record, "spec.replicas", 0);
7411
7416
  const scale = (delta) => {
7412
7417
  const v = record.scale(currentReplicas + delta);
7413
- const id = v.id;
7418
+ const id = record.id;
7414
7419
  pruneBeforeEdit(v);
7415
7420
  mutate({
7416
7421
  id,
@@ -7795,7 +7800,7 @@ var __publicField = (obj, key, value) => {
7795
7800
  };
7796
7801
  };
7797
7802
  const ServiceTypeColumnRenderer = () => {
7798
- const dataIndex = ["rawYaml", "spec", "type"];
7803
+ const dataIndex = ["spec", "type"];
7799
7804
  return {
7800
7805
  key: "type",
7801
7806
  title: i18n__default.default.t("dovetail.type"),
@@ -7846,8 +7851,9 @@ var __publicField = (obj, key, value) => {
7846
7851
  return { edit: edit2 };
7847
7852
  }
7848
7853
  function K8sDropdown(props) {
7849
- const { data: data2 } = props;
7854
+ const { record } = props;
7850
7855
  const kit = eagle.useUIKit();
7856
+ const { globalStore } = useGlobalStore();
7851
7857
  const useResourceResult = core.useResource();
7852
7858
  const resource = useResourceResult.resource;
7853
7859
  const { edit: edit2 } = useEdit();
@@ -7865,8 +7871,8 @@ var __publicField = (obj, key, value) => {
7865
7871
  kit.menuItem,
7866
7872
  {
7867
7873
  onClick: () => {
7868
- if (data2.id) {
7869
- edit2(data2.id);
7874
+ if (record.id) {
7875
+ edit2(record.id);
7870
7876
  }
7871
7877
  },
7872
7878
  children: /* @__PURE__ */ jsxRuntime.exports.jsx(eagle.Icon, { src: iconsReact.EditPen16PrimaryIcon, children: t("dovetail.edit") })
@@ -7877,7 +7883,7 @@ var __publicField = (obj, key, value) => {
7877
7883
  {
7878
7884
  danger: true,
7879
7885
  onClick: () => {
7880
- openDeleteConfirmModal(data2.id);
7886
+ openDeleteConfirmModal(record.id);
7881
7887
  },
7882
7888
  children: /* @__PURE__ */ jsxRuntime.exports.jsx(eagle.Icon, { src: iconsReact.TrashBinDelete16Icon, children: t("dovetail.delete") })
7883
7889
  }
@@ -7887,10 +7893,10 @@ var __publicField = (obj, key, value) => {
7887
7893
  {
7888
7894
  onClick: () => {
7889
7895
  var _a;
7890
- if (data2.id) {
7896
+ if (record.id) {
7891
7897
  download2({
7892
- name: ((_a = data2.metadata) == null ? void 0 : _a.name) || data2.kind || "",
7893
- item: data2.restore()
7898
+ name: ((_a = record.metadata) == null ? void 0 : _a.name) || record.kind || "",
7899
+ item: (globalStore == null ? void 0 : globalStore.restoreItem(record)) || record
7894
7900
  });
7895
7901
  }
7896
7902
  },
@@ -8087,6 +8093,7 @@ var __publicField = (obj, key, value) => {
8087
8093
  const { columns, tableProps, formatter, Dropdown = K8sDropdown } = params;
8088
8094
  const [selectedKeys, setSelectedKeys] = React.useState([]);
8089
8095
  const [currentPage, setCurrentPage] = React.useState((tableProps == null ? void 0 : tableProps.currentPage) || 1);
8096
+ const { resource } = core.useResource();
8090
8097
  const { value: nsFilter } = useNamespacesFilter();
8091
8098
  const useTableParams = React.useMemo(() => {
8092
8099
  const mergedParams = lodashEs.merge(params.useTableParams, {
@@ -8112,21 +8119,13 @@ var __publicField = (obj, key, value) => {
8112
8119
  },
8113
8120
  [setCurrentPage]
8114
8121
  );
8115
- const actionColumn = {
8116
- key: "action",
8117
- display: true,
8118
- dataIndex: [],
8119
- title: () => /* @__PURE__ */ jsxRuntime.exports.jsx(eagle.Icon, { src: iconsReact.SettingsGear16GradientGrayIcon }),
8120
- render: (_, record) => {
8121
- return /* @__PURE__ */ jsxRuntime.exports.jsx(Dropdown, { data: record });
8122
- }
8123
- };
8124
8122
  const data2 = (_a = table.tableQueryResult.data) == null ? void 0 : _a.data;
8125
8123
  const finalDataSource = formatter ? data2 == null ? void 0 : data2.map(formatter) : data2;
8126
8124
  const finalProps = {
8125
+ tableKey: (resource == null ? void 0 : resource.name) || "table",
8127
8126
  loading: table.tableQueryResult.isLoading,
8128
- dataSource: finalDataSource || [],
8129
- columns: [...columns, actionColumn],
8127
+ data: finalDataSource || [],
8128
+ columns,
8130
8129
  refetch: () => null,
8131
8130
  error: false,
8132
8131
  rowKey: "id",
@@ -8135,7 +8134,8 @@ var __publicField = (obj, key, value) => {
8135
8134
  onPageChange,
8136
8135
  onSelect: (keys) => {
8137
8136
  setSelectedKeys(keys);
8138
- }
8137
+ },
8138
+ RowMenu: Dropdown
8139
8139
  };
8140
8140
  return { tableProps: finalProps, selectedKeys, ...table };
8141
8141
  };
@@ -8504,23 +8504,23 @@ var __publicField = (obj, key, value) => {
8504
8504
  filteredProps.className = options.atomic ? cx_default(options.class, filteredProps.className || className) : cx_default(filteredProps.className || className, options.class);
8505
8505
  const { vars } = options;
8506
8506
  if (vars) {
8507
- const style2 = {};
8507
+ const style = {};
8508
8508
  for (const name2 in vars) {
8509
8509
  const variable = vars[name2];
8510
8510
  const result = variable[0];
8511
8511
  const unit = variable[1] || "";
8512
8512
  const value = typeof result === "function" ? result(props) : result;
8513
8513
  warnIfInvalid(value, options.name);
8514
- style2[`--${name2}`] = `${value}${unit}`;
8514
+ style[`--${name2}`] = `${value}${unit}`;
8515
8515
  }
8516
8516
  const ownStyle = filteredProps.style || {};
8517
8517
  const keys = Object.keys(ownStyle);
8518
8518
  if (keys.length > 0) {
8519
8519
  keys.forEach((key) => {
8520
- style2[key] = ownStyle[key];
8520
+ style[key] = ownStyle[key];
8521
8521
  });
8522
8522
  }
8523
- filteredProps.style = style2;
8523
+ filteredProps.style = style;
8524
8524
  }
8525
8525
  if (tag.__linaria && tag !== component) {
8526
8526
  filteredProps.as = component;
@@ -8561,12 +8561,13 @@ var __publicField = (obj, key, value) => {
8561
8561
  const {
8562
8562
  loading,
8563
8563
  error,
8564
- dataSource,
8564
+ data: dataSource,
8565
8565
  rowKey,
8566
8566
  columns,
8567
8567
  scroll,
8568
8568
  currentPage,
8569
8569
  currentSize,
8570
+ RowMenu,
8570
8571
  refetch,
8571
8572
  onSelect,
8572
8573
  onPageChange,
@@ -8579,6 +8580,23 @@ var __publicField = (obj, key, value) => {
8579
8580
  pageSize: currentSize,
8580
8581
  onChange: onPageChange
8581
8582
  }), [currentPage, currentSize, onPageChange]);
8583
+ const finalColumns = React.useMemo(() => {
8584
+ if (RowMenu) {
8585
+ const actionColumn = {
8586
+ key: "_action_",
8587
+ display: true,
8588
+ dataIndex: [],
8589
+ title: "",
8590
+ render: (_, record) => {
8591
+ return /* @__PURE__ */ jsxRuntime.exports.jsx(RowMenu, {
8592
+ record
8593
+ });
8594
+ }
8595
+ };
8596
+ return [...columns, actionColumn];
8597
+ }
8598
+ return columns;
8599
+ }, [columns, RowMenu]);
8582
8600
  if (loading) {
8583
8601
  return /* @__PURE__ */ jsxRuntime.exports.jsx(kit.loading, {});
8584
8602
  } else if (error) {
@@ -8607,7 +8625,7 @@ var __publicField = (obj, key, value) => {
8607
8625
  onSelect == null ? void 0 : onSelect(keys, rows);
8608
8626
  }
8609
8627
  } : void 0,
8610
- columns,
8628
+ columns: finalColumns,
8611
8629
  dataSource,
8612
8630
  pagination,
8613
8631
  error,
@@ -8748,8 +8766,9 @@ var __publicField = (obj, key, value) => {
8748
8766
  selectedKeys,
8749
8767
  hideCreate: true
8750
8768
  }), /* @__PURE__ */ jsxRuntime.exports.jsx(Table, {
8769
+ tableKey: "cronjobs",
8751
8770
  loading: !dataSource,
8752
- dataSource: dataSource || [],
8771
+ data: dataSource || [],
8753
8772
  columns,
8754
8773
  onSelect: (keys) => setSelectedKeys(keys),
8755
8774
  rowKey: "id",
@@ -8793,7 +8812,7 @@ var __publicField = (obj, key, value) => {
8793
8812
  }
8794
8813
  );
8795
8814
  };
8796
- function matchSelector(pod, selector) {
8815
+ function matchSelector$1(pod, selector) {
8797
8816
  var _a, _b, _c;
8798
8817
  let match = true;
8799
8818
  for (const key in selector.matchLabels) {
@@ -8821,7 +8840,7 @@ var __publicField = (obj, key, value) => {
8821
8840
  });
8822
8841
  const dataSource = React.useMemo(() => {
8823
8842
  return data2 == null ? void 0 : data2.data.filter((p) => {
8824
- return selector ? matchSelector(p, selector) : true;
8843
+ return selector ? matchSelector$1(p, selector) : true;
8825
8844
  });
8826
8845
  }, [data2 == null ? void 0 : data2.data, selector]);
8827
8846
  const columns = [PhaseColumnRenderer(), NameColumnRenderer("pods"), NodeNameColumnRenderer(), WorkloadImageColumnRenderer(), RestartCountColumnRenderer()];
@@ -8833,8 +8852,9 @@ var __publicField = (obj, key, value) => {
8833
8852
  selectedKeys,
8834
8853
  hideCreate: true
8835
8854
  }), /* @__PURE__ */ jsxRuntime.exports.jsx(Table, {
8855
+ tableKey: "pods",
8836
8856
  loading: !dataSource,
8837
- dataSource: dataSource || [],
8857
+ data: dataSource || [],
8838
8858
  columns,
8839
8859
  onSelect: (keys) => setSelectedKeys(keys),
8840
8860
  rowKey: "id",
@@ -8920,7 +8940,7 @@ var __publicField = (obj, key, value) => {
8920
8940
  return {
8921
8941
  key: "data",
8922
8942
  title: i18n__default.default.t("dovetail.data"),
8923
- path: ["rawYaml", "data"],
8943
+ path: ["data"],
8924
8944
  render: (val) => {
8925
8945
  return /* @__PURE__ */ jsxRuntime.exports.jsx(KeyValue, { value: val });
8926
8946
  }
@@ -8930,7 +8950,7 @@ var __publicField = (obj, key, value) => {
8930
8950
  return {
8931
8951
  key: "data",
8932
8952
  title: i18n__default.default.t("dovetail.data"),
8933
- path: ["rawYaml", "data"],
8953
+ path: ["data"],
8934
8954
  render: (val) => {
8935
8955
  const decodeVal = {};
8936
8956
  for (const key in val) {
@@ -8954,21 +8974,21 @@ var __publicField = (obj, key, value) => {
8954
8974
  return {
8955
8975
  key: "type",
8956
8976
  title: i18n__default.default.t("dovetail.type"),
8957
- path: ["rawYaml", "spec", "type"]
8977
+ path: ["spec", "type"]
8958
8978
  };
8959
8979
  };
8960
8980
  const ClusterIpField = () => {
8961
8981
  return {
8962
8982
  key: "clusterIp",
8963
8983
  title: i18n__default.default.t("dovetail.clusterIp"),
8964
- path: ["rawYaml", "spec", "clusterIP"]
8984
+ path: ["spec", "clusterIP"]
8965
8985
  };
8966
8986
  };
8967
8987
  const SessionAffinityField = () => {
8968
8988
  return {
8969
8989
  key: "clusterIp",
8970
8990
  title: i18n__default.default.t("dovetail.sessionAffinity"),
8971
- path: ["rawYaml", "spec", "sessionAffinity"]
8991
+ path: ["spec", "sessionAffinity"]
8972
8992
  };
8973
8993
  };
8974
8994
  const ServicePodsField = () => {
@@ -9164,51 +9184,51 @@ var __publicField = (obj, key, value) => {
9164
9184
  {
9165
9185
  key: "type",
9166
9186
  display: true,
9167
- dataIndex: ["rawYaml", "type"],
9187
+ dataIndex: ["type"],
9168
9188
  title: i18n2.t("dovetail.type"),
9169
9189
  sortable: true,
9170
- sorter: CommonSorter(["rawYaml", "type"])
9190
+ sorter: CommonSorter(["type"])
9171
9191
  },
9172
9192
  {
9173
9193
  key: "reason",
9174
9194
  display: true,
9175
- dataIndex: ["rawYaml", "reason"],
9195
+ dataIndex: ["reason"],
9176
9196
  title: i18n2.t("dovetail.reason"),
9177
9197
  sortable: true,
9178
- sorter: CommonSorter(["rawYaml", "reason"])
9198
+ sorter: CommonSorter(["reason"])
9179
9199
  },
9180
9200
  {
9181
9201
  key: "object",
9182
9202
  display: true,
9183
- dataIndex: ["rawYaml", "regarding", "name"],
9203
+ dataIndex: ["regarding", "name"],
9184
9204
  title: i18n2.t("dovetail.object"),
9185
9205
  sortable: true,
9186
- sorter: CommonSorter(["rawYaml", "regarding", "name"])
9206
+ sorter: CommonSorter(["regarding", "name"])
9187
9207
  },
9188
9208
  {
9189
9209
  key: "note",
9190
9210
  display: true,
9191
- dataIndex: ["rawYaml", "note"],
9211
+ dataIndex: ["note"],
9192
9212
  title: i18n2.t("dovetail.note"),
9193
9213
  sortable: true,
9194
- sorter: CommonSorter(["rawYaml", "note"])
9214
+ sorter: CommonSorter(["note"])
9195
9215
  },
9196
9216
  AgeColumnRenderer()
9197
9217
  ],
9198
9218
  [i18n2]
9199
9219
  );
9200
- const dataSource = React.useMemo(
9201
- () => addId((data2 == null ? void 0 : data2.data) || [], "metadata.uid").filter((d) => {
9220
+ const dataSource = React.useMemo(() => {
9221
+ return data2 == null ? void 0 : data2.data.filter((d) => {
9202
9222
  const objectId = `${d.regarding.namespace}/${d.regarding.name}`;
9203
9223
  return objectId === parsed.id;
9204
- }),
9205
- [data2 == null ? void 0 : data2.data, parsed]
9206
- );
9224
+ });
9225
+ }, [data2 == null ? void 0 : data2.data, parsed]);
9207
9226
  return /* @__PURE__ */ jsxRuntime.exports.jsx(
9208
9227
  Table,
9209
9228
  {
9229
+ tableKey: "events",
9210
9230
  loading: isLoading,
9211
- dataSource: dataSource || [],
9231
+ data: dataSource || [],
9212
9232
  columns,
9213
9233
  rowKey: "id",
9214
9234
  error: false,
@@ -9252,6 +9272,9 @@ var __publicField = (obj, key, value) => {
9252
9272
  Dropdown = K8sDropdown
9253
9273
  } = props;
9254
9274
  const kit = eagle.useUIKit();
9275
+ const {
9276
+ globalStore
9277
+ } = useGlobalStore();
9255
9278
  const parsed = core.useParsed();
9256
9279
  const {
9257
9280
  resource
@@ -9359,7 +9382,7 @@ var __publicField = (obj, key, value) => {
9359
9382
  children: "YAML"
9360
9383
  })]
9361
9384
  }), /* @__PURE__ */ jsxRuntime.exports.jsx(Dropdown, {
9362
- data: record
9385
+ record
9363
9386
  })]
9364
9387
  })]
9365
9388
  });
@@ -9400,7 +9423,7 @@ var __publicField = (obj, key, value) => {
9400
9423
  }),
9401
9424
  ["yaml"]: /* @__PURE__ */ jsxRuntime.exports.jsx(MonacoYamlEditor$1, {
9402
9425
  className: EditorStyle$1,
9403
- defaultValue: yaml__default.default.dump(model.restore()),
9426
+ defaultValue: yaml__default.default.dump(globalStore == null ? void 0 : globalStore.restoreItem(model)),
9404
9427
  schema: {},
9405
9428
  onEditorCreate: (editor) => {
9406
9429
  fold(editor);
@@ -9538,16 +9561,16 @@ var __publicField = (obj, key, value) => {
9538
9561
  );
9539
9562
  };
9540
9563
  function WorkloadDropdown(props) {
9541
- const { data: data2 } = props;
9564
+ const { record } = props;
9542
9565
  const kit = eagle.useUIKit();
9543
9566
  const { resource } = core.useResource();
9544
9567
  const { mutate } = core.useUpdate();
9545
9568
  const { t } = useTranslation();
9546
- return /* @__PURE__ */ jsxRuntime.exports.jsx(K8sDropdown, { data: data2, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
9569
+ return /* @__PURE__ */ jsxRuntime.exports.jsx(K8sDropdown, { record, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
9547
9570
  kit.menu.Item,
9548
9571
  {
9549
9572
  onClick: () => {
9550
- const v = data2.redeploy();
9573
+ const v = record.redeploy();
9551
9574
  const id = v.id;
9552
9575
  pruneBeforeEdit(v);
9553
9576
  mutate({
@@ -9560,6 +9583,7 @@ var __publicField = (obj, key, value) => {
9560
9583
  }
9561
9584
  ) });
9562
9585
  }
9586
+ const ComponentContext = React.createContext({});
9563
9587
  const index_3lw8k1 = "";
9564
9588
  const ListPageStyle = "laykzsq";
9565
9589
  const TableStyle = "t1ng0psc";
@@ -9569,12 +9593,16 @@ var __publicField = (obj, key, value) => {
9569
9593
  selectedKeys,
9570
9594
  tableProps
9571
9595
  } = props;
9596
+ const {
9597
+ Table: TableComponent
9598
+ } = React.useContext(ComponentContext);
9599
+ const Table$1 = TableComponent || Table;
9572
9600
  return /* @__PURE__ */ jsxRuntime.exports.jsxs("div", {
9573
9601
  className: ListPageStyle,
9574
9602
  children: [/* @__PURE__ */ jsxRuntime.exports.jsx(TableToolBar, {
9575
9603
  title,
9576
9604
  selectedKeys
9577
- }), /* @__PURE__ */ jsxRuntime.exports.jsx(Table, {
9605
+ }), /* @__PURE__ */ jsxRuntime.exports.jsx(Table$1, {
9578
9606
  ...tableProps,
9579
9607
  className: TableStyle,
9580
9608
  scroll: {
@@ -9585,7 +9613,6 @@ var __publicField = (obj, key, value) => {
9585
9613
  }
9586
9614
  function ResourceList(props) {
9587
9615
  const { formatter, name: name2, columns, Dropdown } = props;
9588
- useTranslation();
9589
9616
  const { tableProps, selectedKeys } = useEagleTable({
9590
9617
  useTableParams: {},
9591
9618
  columns: [
@@ -10149,7 +10176,8 @@ var __publicField = (obj, key, value) => {
10149
10176
  } = useEagleForm({
10150
10177
  editorOptions: {
10151
10178
  isSkipSchema: schemaStrategy === "None"
10152
- }
10179
+ },
10180
+ liveMode: "off"
10153
10181
  });
10154
10182
  const kit = eagle.useUIKit();
10155
10183
  const {
@@ -10157,6 +10185,9 @@ var __publicField = (obj, key, value) => {
10157
10185
  i18n: i18n2
10158
10186
  } = useTranslation();
10159
10187
  const responseErrors = errorResponseBody ? getCommonErrors(errorResponseBody, i18n2) : [];
10188
+ const schema = React.useMemo(() => {
10189
+ return editorProps.schema || {};
10190
+ }, [editorProps.schema]);
10160
10191
  return /* @__PURE__ */ jsxRuntime.exports.jsx(FormLayout, {
10161
10192
  children: /* @__PURE__ */ jsxRuntime.exports.jsx(kit.form, {
10162
10193
  ...formProps,
@@ -10175,7 +10206,7 @@ var __publicField = (obj, key, value) => {
10175
10206
  children: /* @__PURE__ */ jsxRuntime.exports.jsx(YamlEditorComponent, {
10176
10207
  ...editorProps,
10177
10208
  className: EditorStyle,
10178
- schema: editorProps.schema || {},
10209
+ schema,
10179
10210
  collapsable: false
10180
10211
  })
10181
10212
  }), /* @__PURE__ */ jsxRuntime.exports.jsxs(kit.form.Item, {
@@ -10222,7 +10253,6 @@ var __publicField = (obj, key, value) => {
10222
10253
  }
10223
10254
  const ResourceCRUD = (props) => {
10224
10255
  const { configs, urlPrefix } = props;
10225
- const { i18n: i18n2 } = useTranslation();
10226
10256
  return /* @__PURE__ */ jsxRuntime.exports.jsx(jsxRuntime.exports.Fragment, { children: configs.map((config) => {
10227
10257
  var _a, _b;
10228
10258
  return /* @__PURE__ */ jsxRuntime.exports.jsxs(React__default.default.Fragment, { children: [
@@ -10231,7 +10261,7 @@ var __publicField = (obj, key, value) => {
10231
10261
  {
10232
10262
  name: config.kind,
10233
10263
  formatter: config.formatter,
10234
- columns: ((_a = config.columns) == null ? void 0 : _a.call(config, i18n2)) || [],
10264
+ columns: ((_a = config.columns) == null ? void 0 : _a.call(config)) || [],
10235
10265
  Dropdown: config.Dropdown
10236
10266
  }
10237
10267
  ) }),
@@ -10239,7 +10269,7 @@ var __publicField = (obj, key, value) => {
10239
10269
  ResourceShow,
10240
10270
  {
10241
10271
  formatter: config.formatter,
10242
- filedGroups: ((_b = config.showFields) == null ? void 0 : _b.call(config, i18n2)) || [],
10272
+ filedGroups: ((_b = config.showFields) == null ? void 0 : _b.call(config)) || [],
10243
10273
  Dropdown: config.Dropdown
10244
10274
  }
10245
10275
  ) }),
@@ -10249,19 +10279,19 @@ var __publicField = (obj, key, value) => {
10249
10279
  }) });
10250
10280
  };
10251
10281
  function CronJobDropdown(props) {
10252
- const { data: data2 } = props;
10253
- const { spec } = data2;
10282
+ const { record } = props;
10283
+ const { spec } = record;
10254
10284
  const kit = eagle.useUIKit();
10255
10285
  const { resource } = core.useResource();
10256
10286
  const { mutate } = core.useUpdate();
10257
10287
  const { t } = useTranslation();
10258
10288
  const suspended = Boolean(spec == null ? void 0 : spec.suspend);
10259
- return /* @__PURE__ */ jsxRuntime.exports.jsx(K8sDropdown, { data: data2, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
10289
+ return /* @__PURE__ */ jsxRuntime.exports.jsx(K8sDropdown, { record, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
10260
10290
  kit.menu.Item,
10261
10291
  {
10262
10292
  onClick: () => {
10263
- const v = suspended ? data2.resume() : data2.suspend();
10264
- const id = data2.id;
10293
+ const v = suspended ? record.resume() : record.suspend();
10294
+ const id = record.id;
10265
10295
  pruneBeforeEdit(v);
10266
10296
  mutate({
10267
10297
  id,
@@ -10275,6 +10305,41 @@ var __publicField = (obj, key, value) => {
10275
10305
  }
10276
10306
  const UNITS = ["", "K", "M", "G", "T", "P"];
10277
10307
  const FRACTIONAL = ["", "m", "u", "n", "p", "f"];
10308
+ function formatSi(inValue, options) {
10309
+ const {
10310
+ increment = 1e3,
10311
+ suffix = null,
10312
+ firstSuffix = null,
10313
+ startingExponent = 0,
10314
+ minExponent = 0,
10315
+ maxPrecision = 2,
10316
+ atLeastOne = true
10317
+ } = options || {};
10318
+ let val = inValue;
10319
+ let exp = startingExponent;
10320
+ while (val >= increment && exp + 1 < UNITS.length || exp < minExponent) {
10321
+ val = val / increment;
10322
+ exp++;
10323
+ }
10324
+ let out = 0;
10325
+ if (val < 10 && maxPrecision >= 2) {
10326
+ out = Math.round(val * 100) / 100;
10327
+ } else if (val < 100 && maxPrecision >= 1) {
10328
+ out = Math.round(val * 10) / 10;
10329
+ } else {
10330
+ out = Math.round(val);
10331
+ }
10332
+ if (atLeastOne && out === 0) {
10333
+ out = 1;
10334
+ }
10335
+ let outStr = String(out);
10336
+ if (exp === 0 && firstSuffix !== null) {
10337
+ outStr += `${firstSuffix}`;
10338
+ } else {
10339
+ outStr += `${UNITS[exp]}${suffix}` || "";
10340
+ }
10341
+ return outStr;
10342
+ }
10278
10343
  function parseSi(inValue, increment = null, allowFractional = true) {
10279
10344
  if (!inValue || typeof inValue !== "string" || !inValue.length) {
10280
10345
  return NaN;
@@ -10460,7 +10525,7 @@ var __publicField = (obj, key, value) => {
10460
10525
  const { queryResult } = core.useShow({ id: (_a = parsed == null ? void 0 : parsed.params) == null ? void 0 : _a.id });
10461
10526
  const { isLoading } = queryResult;
10462
10527
  return /* @__PURE__ */ jsxRuntime.exports.jsx(
10463
- antd$1.Drawer,
10528
+ antd.Drawer,
10464
10529
  {
10465
10530
  title: "Show Drawer",
10466
10531
  placement: "right",
@@ -14850,7 +14915,7 @@ var __publicField = (obj, key, value) => {
14850
14915
  return "&#x27;";
14851
14916
  }
14852
14917
  });
14853
- const LogViewerRow = React.memo(({ index, style: style2, data: data2, ansiUp }) => {
14918
+ const LogViewerRow = React.memo(({ index, style, data: data2, ansiUp }) => {
14854
14919
  const { parsedData, searchedWordIndexes, rowInFocus } = data2;
14855
14920
  const context = React.useContext(LogViewerContext);
14856
14921
  const getData = (index2) => parsedData ? parsedData[index2] : null;
@@ -14894,7 +14959,7 @@ var __publicField = (obj, key, value) => {
14894
14959
  };
14895
14960
  return React__default.default.createElement(
14896
14961
  "div",
14897
- { style: style2, className: css(styles$1.logViewerListItem) },
14962
+ { style, className: css(styles$1.logViewerListItem) },
14898
14963
  React__default.default.createElement("span", { className: css(styles$1.logViewerIndex) }, getRowIndex(index)),
14899
14964
  React__default.default.createElement("span", { className: css(styles$1.logViewerText), style: { width: "fit-content" }, dangerouslySetInnerHTML: { __html: ansiUp.ansi_to_html(getFormattedData()) } })
14900
14965
  );
@@ -15022,19 +15087,19 @@ var __publicField = (obj, key, value) => {
15022
15087
  this._getItemStyle = (index) => {
15023
15088
  const { itemSize } = this.props;
15024
15089
  const itemStyleCache = this._getItemStyleCache(shouldResetStyleCacheOnItemSizeChange && itemSize);
15025
- let style2;
15090
+ let style;
15026
15091
  if (itemStyleCache.hasOwnProperty(index)) {
15027
- style2 = itemStyleCache[index];
15092
+ style = itemStyleCache[index];
15028
15093
  } else {
15029
15094
  const offset = getItemOffset(this.props, index, this._instanceProps);
15030
15095
  const size = getItemSize(this.props, index, this._instanceProps);
15031
- itemStyleCache[index] = style2 = {
15096
+ itemStyleCache[index] = style = {
15032
15097
  position: "absolute",
15033
15098
  top: offset,
15034
15099
  height: size
15035
15100
  };
15036
15101
  }
15037
- return style2;
15102
+ return style;
15038
15103
  };
15039
15104
  this._getItemStyleCache = memoizeOne(() => ({}));
15040
15105
  this._onScrollVertical = (event2) => {
@@ -15151,7 +15216,7 @@ var __publicField = (obj, key, value) => {
15151
15216
  });
15152
15217
  }
15153
15218
  render() {
15154
- const { children, outerClassName, innerClassName, height, innerRef, innerElementType, innerTagName, itemCount, itemData, itemKey = defaultItemKey, outerElementType, outerTagName, style: style2, useIsScrolling, width, isTextWrapped, hasLineNumbers, indexWidth, ansiUp } = this.props;
15219
+ const { children, outerClassName, innerClassName, height, innerRef, innerElementType, innerTagName, itemCount, itemData, itemKey = defaultItemKey, outerElementType, outerTagName, style, useIsScrolling, width, isTextWrapped, hasLineNumbers, indexWidth, ansiUp } = this.props;
15155
15220
  const { isScrolling } = this.state;
15156
15221
  const onScroll = this._onScrollVertical;
15157
15222
  const [startIndex, stopIndex] = this._getRangeToRender();
@@ -15174,7 +15239,7 @@ var __publicField = (obj, key, value) => {
15174
15239
  onScroll,
15175
15240
  ref: this._outerRefSetter,
15176
15241
  tabIndex: 0,
15177
- style: Object.assign({ height, paddingTop: 0, paddingBottom: 0, WebkitOverflowScrolling: "touch", overflowX: isTextWrapped ? "hidden" : "auto" }, style2)
15242
+ style: Object.assign({ height, paddingTop: 0, paddingBottom: 0, WebkitOverflowScrolling: "touch", overflowX: isTextWrapped ? "hidden" : "auto" }, style)
15178
15243
  }, React.createElement(innerElementType || innerTagName || "div", {
15179
15244
  className: innerClassName,
15180
15245
  ref: innerRef,
@@ -16144,19 +16209,449 @@ var __publicField = (obj, key, value) => {
16144
16209
  })]
16145
16210
  });
16146
16211
  };
16212
+ function getSecondsDiff(startDate, endDate) {
16213
+ return Math.round(Math.abs(Date.parse(endDate) - Date.parse(startDate)) / 1e3);
16214
+ }
16215
+ function elapsedTime(seconds) {
16216
+ if (!seconds) {
16217
+ return {};
16218
+ }
16219
+ if (seconds < 120) {
16220
+ return {
16221
+ diff: 1,
16222
+ label: `${seconds}s`
16223
+ };
16224
+ }
16225
+ const minutes = Math.floor(seconds / 60);
16226
+ if (minutes < 10) {
16227
+ return {
16228
+ diff: 1,
16229
+ label: `${minutes}m${seconds - minutes * 60}s`
16230
+ };
16231
+ }
16232
+ const hours = Math.floor(seconds / 3600);
16233
+ if (hours < 3) {
16234
+ return {
16235
+ diff: 60,
16236
+ label: `${minutes}m`
16237
+ };
16238
+ }
16239
+ const days = Math.floor(seconds / (3600 * 24));
16240
+ if (days > 1) {
16241
+ return {
16242
+ diff: 60,
16243
+ label: `${days}d${hours - days * 24}h`
16244
+ };
16245
+ }
16246
+ if (hours > 7) {
16247
+ return {
16248
+ diff: 60,
16249
+ label: `${hours}h`
16250
+ };
16251
+ }
16252
+ return {
16253
+ diff: 60,
16254
+ label: `${hours}h${minutes - hours * 60}m`
16255
+ };
16256
+ }
16257
+ function shortenedImage(image2) {
16258
+ return (image2 || "").replace(/^(index\.)?docker.io\/(library\/)?/, "").replace(/:latest$/, "").replace(/^(.*@sha256:)([0-9a-f]{8})[0-9a-f]+$/i, "$1$2\u2026");
16259
+ }
16260
+ class ResourceModel {
16261
+ constructor(_rawYaml, _globalStore) {
16262
+ __publicField(this, "id");
16263
+ __publicField(this, "apiVersion");
16264
+ __publicField(this, "kind");
16265
+ __publicField(this, "metadata");
16266
+ this._rawYaml = _rawYaml;
16267
+ this._globalStore = _globalStore;
16268
+ Object.keys(_rawYaml).forEach((key) => {
16269
+ Object.defineProperty(this, key, {
16270
+ value: _rawYaml[key]
16271
+ });
16272
+ });
16273
+ }
16274
+ async init() {
16275
+ }
16276
+ get name() {
16277
+ var _a;
16278
+ return (_a = this._rawYaml.metadata) == null ? void 0 : _a.name;
16279
+ }
16280
+ get namespace() {
16281
+ var _a;
16282
+ return (_a = this._rawYaml.metadata) == null ? void 0 : _a.namespace;
16283
+ }
16284
+ get labels() {
16285
+ var _a;
16286
+ return (_a = this._rawYaml.metadata) == null ? void 0 : _a.labels;
16287
+ }
16288
+ get annotations() {
16289
+ var _a;
16290
+ return (_a = this._rawYaml.metadata) == null ? void 0 : _a.annotations;
16291
+ }
16292
+ restore() {
16293
+ return this._rawYaml;
16294
+ }
16295
+ }
16296
+ class WorkloadBaseModel extends ResourceModel {
16297
+ constructor(_rawYaml, _globalStore) {
16298
+ super(_rawYaml, _globalStore);
16299
+ this._rawYaml = _rawYaml;
16300
+ this._globalStore = _globalStore;
16301
+ }
16302
+ get imageNames() {
16303
+ var _a, _b, _c, _d;
16304
+ const containers = this._rawYaml.spec && "jobTemplate" in this._rawYaml.spec ? (_b = (_a = this._rawYaml.spec.jobTemplate.spec) == null ? void 0 : _a.template.spec) == null ? void 0 : _b.containers : this._rawYaml.spec && "template" in this._rawYaml.spec ? (_d = (_c = this._rawYaml.spec) == null ? void 0 : _c.template.spec) == null ? void 0 : _d.containers : [];
16305
+ return (containers == null ? void 0 : containers.map((container2) => shortenedImage(container2.image || ""))) || [];
16306
+ }
16307
+ }
16308
+ class JobModel extends WorkloadBaseModel {
16309
+ constructor(_rawYaml, _globalStore) {
16310
+ super(_rawYaml, _globalStore);
16311
+ this._rawYaml = _rawYaml;
16312
+ this._globalStore = _globalStore;
16313
+ }
16314
+ get duration() {
16315
+ var _a, _b;
16316
+ const completionTime = (_a = this._rawYaml.status) == null ? void 0 : _a.completionTime;
16317
+ const startTime = (_b = this._rawYaml.status) == null ? void 0 : _b.startTime;
16318
+ if (!completionTime && startTime) {
16319
+ return getSecondsDiff(startTime, Date.now().toString());
16320
+ }
16321
+ if (completionTime && startTime) {
16322
+ return getSecondsDiff(startTime, completionTime);
16323
+ }
16324
+ return 0;
16325
+ }
16326
+ get durationDisplay() {
16327
+ return elapsedTime(this.duration).label;
16328
+ }
16329
+ get completionsDisplay() {
16330
+ var _a, _b;
16331
+ return `${((_a = this._rawYaml.status) == null ? void 0 : _a.succeeded) || 0}/${(_b = this._rawYaml.spec) == null ? void 0 : _b.completions}`;
16332
+ }
16333
+ }
16334
+ function matchSelector(pod, selector) {
16335
+ var _a, _b, _c;
16336
+ let match = true;
16337
+ for (const key in selector.matchLabels) {
16338
+ if (!((_b = (_a = pod.metadata) == null ? void 0 : _a.labels) == null ? void 0 : _b[key]) || ((_c = pod.metadata.labels) == null ? void 0 : _c[key]) !== selector.matchLabels[key]) {
16339
+ match = false;
16340
+ }
16341
+ }
16342
+ return match;
16343
+ }
16344
+ class WorkloadModel extends WorkloadBaseModel {
16345
+ constructor(_rawYaml, _globalStore) {
16346
+ super(_rawYaml, _globalStore);
16347
+ __publicField(this, "restarts", 0);
16348
+ this._rawYaml = _rawYaml;
16349
+ this._globalStore = _globalStore;
16350
+ }
16351
+ async init() {
16352
+ await this.getRestarts();
16353
+ }
16354
+ async getRestarts() {
16355
+ const pods = await this._globalStore.get("pods", {
16356
+ resourceBasePath: "/api/v1",
16357
+ kind: "Pod"
16358
+ });
16359
+ const myPods = pods.items.filter(
16360
+ (p) => {
16361
+ var _a, _b;
16362
+ return ((_a = this.spec) == null ? void 0 : _a.selector) ? matchSelector(p, (_b = this.spec) == null ? void 0 : _b.selector) : false;
16363
+ }
16364
+ );
16365
+ const result = lodash.exports.sumBy(myPods, "restartCount");
16366
+ this.restarts = result;
16367
+ }
16368
+ redeploy() {
16369
+ const rawYaml = this._globalStore.restoreItem(this);
16370
+ const newOne = lodash.exports.cloneDeep(rawYaml);
16371
+ const path = "spec.template.metadata.annotations";
16372
+ const annotations = lodash.exports.get(newOne, path, {});
16373
+ lodash.exports.set(newOne, path, {
16374
+ ...annotations,
16375
+ [TIMESTAMP_LABEL]: new Date().toISOString().replace(/\.\d+Z$/, "Z")
16376
+ });
16377
+ return newOne;
16378
+ }
16379
+ scale(value) {
16380
+ const rawYaml = this._globalStore.restoreItem(this);
16381
+ const newOne = lodash.exports.cloneDeep(rawYaml);
16382
+ if (newOne.kind === "Deployment" || newOne.kind === "StatefulSet") {
16383
+ lodash.exports.set(newOne, "spec.replicas", value);
16384
+ }
16385
+ return newOne;
16386
+ }
16387
+ }
16388
+ class PodModel extends WorkloadBaseModel {
16389
+ constructor(_rawYaml, _globalStore) {
16390
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
16391
+ super(_rawYaml, _globalStore);
16392
+ __publicField(this, "request");
16393
+ __publicField(this, "limit");
16394
+ this._rawYaml = _rawYaml;
16395
+ this._globalStore = _globalStore;
16396
+ let cpuRequestNum = 0;
16397
+ let memoryRequestNum = 0;
16398
+ let cpuLimitNum = 0;
16399
+ let memoryLimitNum = 0;
16400
+ for (const container2 of ((_a = _rawYaml.spec) == null ? void 0 : _a.containers) || []) {
16401
+ cpuRequestNum += parseSi(((_c = (_b = container2.resources) == null ? void 0 : _b.requests) == null ? void 0 : _c.cpu) || "0");
16402
+ memoryRequestNum += parseSi(((_e = (_d = container2.resources) == null ? void 0 : _d.requests) == null ? void 0 : _e.memory) || "0");
16403
+ cpuLimitNum += parseSi(((_g = (_f = container2.resources) == null ? void 0 : _f.limits) == null ? void 0 : _g.cpu) || "0");
16404
+ memoryLimitNum += parseSi(((_i = (_h = container2.resources) == null ? void 0 : _h.limits) == null ? void 0 : _i.memory) || "0");
16405
+ }
16406
+ this.request = {
16407
+ cpu: {
16408
+ value: cpuRequestNum,
16409
+ si: formatSi(cpuRequestNum, {
16410
+ suffix: "m"
16411
+ })
16412
+ },
16413
+ memory: {
16414
+ value: memoryRequestNum,
16415
+ si: formatSi(memoryRequestNum, {
16416
+ suffix: "i"
16417
+ })
16418
+ }
16419
+ };
16420
+ this.limit = {
16421
+ cpu: {
16422
+ value: cpuLimitNum,
16423
+ si: formatSi(cpuLimitNum, {
16424
+ suffix: "m"
16425
+ })
16426
+ },
16427
+ memory: {
16428
+ value: memoryLimitNum,
16429
+ si: formatSi(memoryLimitNum, {
16430
+ suffix: "i"
16431
+ })
16432
+ }
16433
+ };
16434
+ }
16435
+ get imageNames() {
16436
+ var _a;
16437
+ return ((_a = this._rawYaml.spec) == null ? void 0 : _a.containers.map(
16438
+ (container2) => shortenedImage(container2.image || "")
16439
+ )) || [];
16440
+ }
16441
+ get restartCount() {
16442
+ var _a, _b;
16443
+ if ((_a = this._rawYaml.status) == null ? void 0 : _a.containerStatuses) {
16444
+ return ((_b = this._rawYaml.status) == null ? void 0 : _b.containerStatuses[0].restartCount) || 0;
16445
+ }
16446
+ return 0;
16447
+ }
16448
+ get readyDisplay() {
16449
+ var _a, _b, _c;
16450
+ return `${(_b = (_a = this._rawYaml.status) == null ? void 0 : _a.containerStatuses) == null ? void 0 : _b.filter((c) => c.ready).length}/${(_c = this._rawYaml.spec) == null ? void 0 : _c.containers.length}`;
16451
+ }
16452
+ get readyContainerCount() {
16453
+ var _a, _b;
16454
+ return (_b = (_a = this._rawYaml.status) == null ? void 0 : _a.containerStatuses) == null ? void 0 : _b.filter((c) => c.ready).length;
16455
+ }
16456
+ get containerCount() {
16457
+ var _a;
16458
+ return (_a = this._rawYaml.spec) == null ? void 0 : _a.containers.length;
16459
+ }
16460
+ }
16461
+ class PodMetricsModel extends ResourceModel {
16462
+ constructor(_rawYaml, _globalStore) {
16463
+ super(_rawYaml, _globalStore);
16464
+ __publicField(this, "usage");
16465
+ this._rawYaml = _rawYaml;
16466
+ this._globalStore = _globalStore;
16467
+ let cpuUsageNum = 0;
16468
+ let memoryUsageNum = 0;
16469
+ for (const container2 of _rawYaml.containers) {
16470
+ cpuUsageNum += parseSi(container2.usage.cpu || "0");
16471
+ memoryUsageNum += parseSi(container2.usage.memory || "0");
16472
+ }
16473
+ this.usage = {
16474
+ cpu: {
16475
+ value: cpuUsageNum,
16476
+ si: formatSi(1e3 * cpuUsageNum, {
16477
+ suffix: "m",
16478
+ maxPrecision: 0
16479
+ })
16480
+ },
16481
+ memory: {
16482
+ value: memoryUsageNum,
16483
+ si: formatSi(memoryUsageNum, {
16484
+ suffix: "i",
16485
+ maxPrecision: 0
16486
+ })
16487
+ }
16488
+ };
16489
+ }
16490
+ }
16491
+ class CronJobModel extends WorkloadBaseModel {
16492
+ constructor(_rawYaml, _globalStore) {
16493
+ super(_rawYaml, _globalStore);
16494
+ this._rawYaml = _rawYaml;
16495
+ this._globalStore = _globalStore;
16496
+ }
16497
+ suspend() {
16498
+ const newOne = lodash.exports.cloneDeep(this._rawYaml);
16499
+ if (this._rawYaml.kind === "CronJob") {
16500
+ lodash.exports.set(newOne, "spec.suspend", true);
16501
+ }
16502
+ return newOne;
16503
+ }
16504
+ resume() {
16505
+ const newOne = lodash.exports.cloneDeep(this._rawYaml);
16506
+ if (this._rawYaml.kind === "CronJob") {
16507
+ lodash.exports.set(newOne, "spec.suspend", false);
16508
+ }
16509
+ return newOne;
16510
+ }
16511
+ }
16512
+ class EventModel extends ResourceModel {
16513
+ constructor(_rawYaml, _globalStore) {
16514
+ super(_rawYaml, _globalStore);
16515
+ this._rawYaml = _rawYaml;
16516
+ this._globalStore = _globalStore;
16517
+ this.id = _rawYaml.metadata.uid || _rawYaml.id;
16518
+ }
16519
+ }
16520
+ const ModelMap = {
16521
+ Deployment: WorkloadModel,
16522
+ DaemonSet: WorkloadModel,
16523
+ StatefulSet: WorkloadModel,
16524
+ CronJob: CronJobModel,
16525
+ Job: JobModel,
16526
+ Pod: PodModel,
16527
+ Event: EventModel
16528
+ };
16529
+ class ModelPlugin {
16530
+ constructor() {
16531
+ __publicField(this, "_globalStore");
16532
+ }
16533
+ init(globalStore) {
16534
+ this._globalStore = globalStore;
16535
+ }
16536
+ async processData(res) {
16537
+ const { kind, apiVersion } = res;
16538
+ const items = await Promise.all(
16539
+ res.items.map((item) => {
16540
+ const newItem = { ...item };
16541
+ newItem.kind = kind.replace(/List$/g, "");
16542
+ newItem.apiVersion = apiVersion;
16543
+ return this.processItem(newItem);
16544
+ })
16545
+ );
16546
+ return {
16547
+ ...res,
16548
+ items
16549
+ };
16550
+ }
16551
+ async processItem(item) {
16552
+ const Model = ModelMap[item.kind] || ResourceModel;
16553
+ const result = new Model(item, this._globalStore);
16554
+ await result.init();
16555
+ return result;
16556
+ }
16557
+ restoreData(res) {
16558
+ ({ ...res });
16559
+ res.items.map((item) => this.restoreItem(item));
16560
+ return res;
16561
+ }
16562
+ restoreItem(item) {
16563
+ return item._rawYaml;
16564
+ }
16565
+ }
16566
+ const modelPlugin = new ModelPlugin();
16567
+ class RelationPlugin {
16568
+ constructor() {
16569
+ __publicField(this, "globalStore");
16570
+ }
16571
+ init(globalStore) {
16572
+ this.globalStore = globalStore;
16573
+ }
16574
+ async processData(res) {
16575
+ const { kind, apiVersion } = res;
16576
+ const items = await Promise.all(
16577
+ res.items.map(
16578
+ (item) => this.processItem({
16579
+ ...item,
16580
+ kind: kind.replace(/List$/g, ""),
16581
+ apiVersion
16582
+ })
16583
+ )
16584
+ );
16585
+ return {
16586
+ ...res,
16587
+ items
16588
+ };
16589
+ }
16590
+ async processItem(item) {
16591
+ this.processPodSelector(item);
16592
+ return item;
16593
+ }
16594
+ restoreData(res) {
16595
+ res.items = res.items.map((item) => this.restoreItem(item));
16596
+ return res;
16597
+ }
16598
+ restoreItem(item) {
16599
+ return {
16600
+ ...item,
16601
+ metadata: lodash.exports.omit(item.metadata, "relations")
16602
+ };
16603
+ }
16604
+ processPodSelector(item) {
16605
+ const { spec, kind } = item;
16606
+ const selector = spec == null ? void 0 : spec.selector;
16607
+ if (!selector) {
16608
+ return item;
16609
+ }
16610
+ if (!kind || ![
16611
+ "Deployment",
16612
+ "DaemonSet",
16613
+ "StatefulSet",
16614
+ "ReplicaSet",
16615
+ "Job",
16616
+ "Service"
16617
+ ].includes(kind)) {
16618
+ return item;
16619
+ }
16620
+ if (!selector.matchLabels && !selector.matchExpressions) {
16621
+ selector.matchLabels = {};
16622
+ for (const key of Object.keys(selector)) {
16623
+ if (key === "matchLabels") {
16624
+ continue;
16625
+ }
16626
+ selector.matchLabels[key] = selector[key];
16627
+ delete selector[key];
16628
+ }
16629
+ }
16630
+ this.appendRelation(item, {
16631
+ kind: "Pod",
16632
+ apiVersion: "v1",
16633
+ type: kind === "Service" ? "selects" : "creates",
16634
+ selector,
16635
+ inbound: false
16636
+ });
16637
+ return item;
16638
+ }
16639
+ appendRelation(item, relation) {
16640
+ const metadata = item.metadata;
16641
+ if (!metadata.relations) {
16642
+ metadata.relations = [];
16643
+ }
16644
+ metadata.relations.push(relation);
16645
+ return item;
16646
+ }
16647
+ }
16648
+ const relationPlugin = new RelationPlugin();
16649
+ const ProviderPlugins = [relationPlugin, modelPlugin];
16147
16650
  const styles = "";
16148
- const antd = "";
16149
- const style = "";
16150
16651
  const Dovetail = (props) => {
16151
- const {
16152
- resourcesConfig,
16153
- urlPrefix = "",
16154
- Layout: Layout2,
16155
- history,
16156
- globalStoreParams
16157
- } = props;
16652
+ const { resourcesConfig, urlPrefix = "", Layout: Layout2, history, globalStoreParams } = props;
16158
16653
  const globalStore = React.useMemo(() => {
16159
- return new k8sApiProvider.GlobalStore(globalStoreParams, k8sApiProvider.ProviderPlugins);
16654
+ return new k8sApiProvider.GlobalStore(globalStoreParams, ProviderPlugins);
16160
16655
  }, [globalStoreParams]);
16161
16656
  const notCustomResources = React.useMemo(() => {
16162
16657
  return resourcesConfig.filter((c) => !c.isCustom);
@@ -16171,7 +16666,7 @@ var __publicField = (obj, key, value) => {
16171
16666
  }
16172
16667
  return _content;
16173
16668
  }, [Layout2, notCustomResources, props.children, urlPrefix]);
16174
- return /* @__PURE__ */ jsxRuntime.exports.jsx(reactRouterDom.Router, { history, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
16669
+ return /* @__PURE__ */ jsxRuntime.exports.jsx(reactRouterDom.Router, { history, children: /* @__PURE__ */ jsxRuntime.exports.jsx(GlobalStoreContext.Provider, { value: { globalStore }, children: /* @__PURE__ */ jsxRuntime.exports.jsx(
16175
16670
  core.Refine,
16176
16671
  {
16177
16672
  dataProvider: {
@@ -16200,7 +16695,7 @@ var __publicField = (obj, key, value) => {
16200
16695
  }),
16201
16696
  children: content
16202
16697
  }
16203
- ) });
16698
+ ) }) });
16204
16699
  };
16205
16700
  var RESOURCE_GROUP = /* @__PURE__ */ ((RESOURCE_GROUP2) => {
16206
16701
  RESOURCE_GROUP2["WORKLOAD"] = "WORKLOAD";
@@ -16258,10 +16753,12 @@ var __publicField = (obj, key, value) => {
16258
16753
  exports2.ColumnKeys = ColumnKeys;
16259
16754
  exports2.CommonSorter = CommonSorter;
16260
16755
  exports2.CompletionsCountColumnRenderer = CompletionsCountColumnRenderer;
16756
+ exports2.ComponentContext = ComponentContext;
16261
16757
  exports2.ConditionsField = ConditionsField;
16262
16758
  exports2.ConditionsTable = ConditionsTable;
16263
16759
  exports2.CreateButton = CreateButton;
16264
16760
  exports2.CronJobDropdown = CronJobDropdown;
16761
+ exports2.CronJobModel = CronJobModel;
16265
16762
  exports2.CronjobJobsTable = CronjobJobsTable;
16266
16763
  exports2.DAEMONSET_INIT_VALUE = DAEMONSET_INIT_VALUE;
16267
16764
  exports2.DEPLOYMENT_INIT_VALUE = DEPLOYMENT_INIT_VALUE;
@@ -16272,9 +16769,11 @@ var __publicField = (obj, key, value) => {
16272
16769
  exports2.DrawerShow = DrawerShow;
16273
16770
  exports2.DurationColumnRenderer = DurationColumnRenderer;
16274
16771
  exports2.EditButton = EditButton;
16772
+ exports2.EventModel = EventModel;
16275
16773
  exports2.ImageField = ImageField;
16276
16774
  exports2.ImageNames = ImageNames;
16277
16775
  exports2.JOB_INIT_VALUE = JOB_INIT_VALUE;
16776
+ exports2.JobModel = JobModel;
16278
16777
  exports2.JobsField = JobsField;
16279
16778
  exports2.KeyValue = KeyValue;
16280
16779
  exports2.KeyValueListWidget = KeyValueListWidget;
@@ -16294,6 +16793,8 @@ var __publicField = (obj, key, value) => {
16294
16793
  exports2.PhaseColumnRenderer = PhaseColumnRenderer;
16295
16794
  exports2.PodContainersTable = PodContainersTable;
16296
16795
  exports2.PodLog = PodLog;
16796
+ exports2.PodMetricsModel = PodMetricsModel;
16797
+ exports2.PodModel = PodModel;
16297
16798
  exports2.PodsField = PodsField;
16298
16799
  exports2.RESOURCE_GROUP = RESOURCE_GROUP;
16299
16800
  exports2.ReplicaField = ReplicaField;
@@ -16301,6 +16802,7 @@ var __publicField = (obj, key, value) => {
16301
16802
  exports2.ResourceCRUD = ResourceCRUD;
16302
16803
  exports2.ResourceForm = ResourceForm;
16303
16804
  exports2.ResourceList = ResourceList;
16805
+ exports2.ResourceModel = ResourceModel;
16304
16806
  exports2.ResourceShow = ResourceShow;
16305
16807
  exports2.ResourceUsageBar = ResourceUsageBar;
16306
16808
  exports2.RestartCountColumnRenderer = RestartCountColumnRenderer;
@@ -16318,8 +16820,10 @@ var __publicField = (obj, key, value) => {
16318
16820
  exports2.StateTag = StateTag;
16319
16821
  exports2.TIMESTAMP_LABEL = TIMESTAMP_LABEL;
16320
16822
  exports2.Tags = Tags;
16823
+ exports2.WorkloadBaseModel = WorkloadBaseModel;
16321
16824
  exports2.WorkloadDropdown = WorkloadDropdown;
16322
16825
  exports2.WorkloadImageColumnRenderer = WorkloadImageColumnRenderer;
16826
+ exports2.WorkloadModel = WorkloadModel;
16323
16827
  exports2.WorkloadPodsTable = WorkloadPodsTable;
16324
16828
  exports2.WorkloadReplicas = WorkloadReplicas;
16325
16829
  exports2.WorkloadRestartsColumnRenderer = WorkloadRestartsColumnRenderer;
@@ -16333,6 +16837,7 @@ var __publicField = (obj, key, value) => {
16333
16837
  exports2.useDownloadYAML = useDownloadYAML;
16334
16838
  exports2.useEagleTable = useEagleTable;
16335
16839
  exports2.useEdit = useEdit;
16840
+ exports2.useGlobalStore = useGlobalStore;
16336
16841
  exports2.useNamespacesFilter = useNamespacesFilter;
16337
16842
  exports2.useSchema = useSchema;
16338
16843
  Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });