seeder-st2110-components 1.0.0 → 1.0.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.
package/dist/index.esm.js CHANGED
@@ -54,14 +54,15 @@ const UsageItem = /*#__PURE__*/memo(_ref => {
54
54
  iconClass,
55
55
  text,
56
56
  children,
57
- ram
57
+ showRam,
58
+ ramValue
58
59
  } = _ref;
59
60
  const tooltipContent = useMemo(() => /*#__PURE__*/jsx(Tooltip, {
60
61
  title: /*#__PURE__*/jsxs(Fragment, {
61
62
  children: [/*#__PURE__*/jsx("div", {
62
63
  children: text
63
- }), ram && /*#__PURE__*/jsxs("div", {
64
- children: ["Total Memory: ", ram, "GB"]
64
+ }), showRam && /*#__PURE__*/jsxs("div", {
65
+ children: ["Total Memory: ", ramValue, "GB"]
65
66
  })]
66
67
  }),
67
68
  destroyOnHidden: false,
@@ -86,7 +87,8 @@ const UsageItem = /*#__PURE__*/memo(_ref => {
86
87
  const getTemperature = (supermicro, sensors) => {
87
88
  return supermicro?.cpu_temperature ?? sensors?.temperatures?.coretemp?.[0]?.current;
88
89
  };
89
- const useHardwareUsage = ps_status => {
90
+ const useHardwareUsage = function (ps_status) {
91
+ let showRam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
90
92
  return useMemo(() => {
91
93
  if (!ps_status || typeof ps_status !== 'object') return null;
92
94
  const {
@@ -109,7 +111,8 @@ const useHardwareUsage = ps_status => {
109
111
  }), mem && /*#__PURE__*/jsxs(UsageItem, {
110
112
  text: "Memory Usage",
111
113
  iconClass: "icon-shiyongshuai",
112
- ram: false,
114
+ showRam: showRam,
115
+ ramValue: (mem.total / (1024 * 1024 * 1024)).toFixed(1),
113
116
  children: [mem.percent, "%"]
114
117
  }), supermicro?.nic_temperature && /*#__PURE__*/jsxs(UsageItem, {
115
118
  text: "NIC Temperature",
@@ -330,68 +333,60 @@ const useUpgrade = _ref => {
330
333
  const hideLoader = () => setIsSpinning(false);
331
334
 
332
335
  // 构建菜单项 - 确保至少包含download和upload
336
+ // 构建菜单项 - 最终完美版本
333
337
  const finalMenuItems = useMemo(() => {
334
338
  const hasDownload = menuItems.some(item => item.key === 'download');
335
339
  const hasUpload = menuItems.some(item => item.key === 'upload');
336
-
337
- // 如果都已经存在,直接返回
338
340
  if (hasDownload && hasUpload) {
339
341
  return menuItems;
340
342
  }
341
- let finalItems = [...menuItems];
342
-
343
- // 查找license项的位置
344
- const licenseIndex = finalItems.findIndex(item => item.key === 'license');
345
-
346
- // 查找最后一个分隔符的位置(在license之前)
347
- let insertIndex = finalItems.length;
348
- let hasPrecedingDivider = false;
349
- if (licenseIndex !== -1) {
350
- // 如果找到license,在其前面插入
351
- insertIndex = licenseIndex;
352
-
353
- // 检查license前面是否有分隔符
354
- if (licenseIndex > 0 && finalItems[licenseIndex - 1].type === 'divider') {
355
- hasPrecedingDivider = true;
356
- insertIndex = licenseIndex - 1; // 在分隔符前面插入
357
- }
358
- } else {
359
- // 如果没有license,查找最后一个分隔符
360
- const lastDividerIndex = finalItems.map((item, idx) => item.type === 'divider' ? idx : -1).filter(idx => idx !== -1).pop();
361
- if (lastDividerIndex !== undefined) {
362
- insertIndex = lastDividerIndex + 1;
363
- }
364
- }
365
- const itemsToInsert = [];
343
+ const licenseIndex = menuItems.findIndex(item => item.key === 'license');
366
344
 
367
- // 添加缺少的download项
368
- if (!hasDownload) {
369
- itemsToInsert.push({
345
+ // 如果没有license,在末尾添加
346
+ if (licenseIndex === -1) {
347
+ const itemsToAdd = [];
348
+ if (menuItems.length > 0) itemsToAdd.push({
349
+ type: 'divider'
350
+ });
351
+ if (!hasDownload) itemsToAdd.push({
370
352
  key: "download",
371
353
  label: "Download Config File"
372
354
  });
373
- }
374
-
375
- // 添加缺少的upload项
376
- if (!hasUpload) {
377
- itemsToInsert.push({
355
+ if (!hasUpload) itemsToAdd.push({
378
356
  key: "upload",
379
357
  label: "Software Update"
380
358
  });
359
+ return [...menuItems, ...itemsToAdd];
381
360
  }
382
361
 
383
- // 在前面插入分隔符(如果还没有且需要插入项)
384
- if (!hasPrecedingDivider && itemsToInsert.length > 0 && insertIndex > 0) {
385
- itemsToInsert.unshift({
362
+ // 有license,在license前面插入
363
+ const beforeLicense = menuItems.slice(0, licenseIndex);
364
+ const licenseItem = menuItems[licenseIndex];
365
+ const afterLicense = menuItems.slice(licenseIndex + 1);
366
+ const itemsToInsert = [];
367
+
368
+ // 1. 前面的分隔符(如果beforeLicense不为空且最后一项不是分隔符)
369
+ if (beforeLicense.length > 0 && beforeLicense[beforeLicense.length - 1].type !== 'divider') {
370
+ itemsToInsert.push({
386
371
  type: 'divider'
387
372
  });
388
373
  }
389
374
 
390
- // 在指定位置插入项
391
- if (itemsToInsert.length > 0) {
392
- finalItems.splice(insertIndex, 0, ...itemsToInsert);
393
- }
394
- return finalItems;
375
+ // 2. 添加缺少的项
376
+ if (!hasDownload) itemsToInsert.push({
377
+ key: "download",
378
+ label: "Download Config File"
379
+ });
380
+ if (!hasUpload) itemsToInsert.push({
381
+ key: "upload",
382
+ label: "Software Update"
383
+ });
384
+
385
+ // 3. 后面的分隔符(与license之间)
386
+ itemsToInsert.push({
387
+ type: 'divider'
388
+ });
389
+ return [...beforeLicense, ...itemsToInsert, licenseItem, ...afterLicense];
395
390
  }, [menuItems]);
396
391
  const handleMenuClick = _ref2 => {
397
392
  let {