seeder-st2110-components 1.1.3 → 1.1.5

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.js CHANGED
@@ -619,7 +619,8 @@ const useSystemOperations = function () {
619
619
  onRestart,
620
620
  confirmTitle = "Confirm",
621
621
  cancelText = "No",
622
- okText = "Yes"
622
+ okText = "Yes",
623
+ run
623
624
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
624
625
  const {
625
626
  modal: AntdModal
@@ -637,6 +638,11 @@ const useSystemOperations = function () {
637
638
  } else if (action === 'restart' && onRestart) {
638
639
  onRestart();
639
640
  }
641
+
642
+ // Call the run callback after successful operation
643
+ if (typeof run === 'function') {
644
+ run();
645
+ }
640
646
  }
641
647
  });
642
648
  } catch (error) {
@@ -1909,7 +1915,8 @@ const SystemOperations = _ref => {
1909
1915
  iconClassName = "iconfont icon-guanji1 text-2xl text-neutral-400",
1910
1916
  confirmTitle = "Confirm",
1911
1917
  cancelText = "No",
1912
- okText = "Yes"
1918
+ okText = "Yes",
1919
+ run
1913
1920
  } = _ref;
1914
1921
  const {
1915
1922
  modal: AntdModal
@@ -1939,6 +1946,11 @@ const SystemOperations = _ref => {
1939
1946
  } else if (action === 'restart' && onRestart) {
1940
1947
  onRestart();
1941
1948
  }
1949
+
1950
+ // Call the run callback after successful operation
1951
+ if (typeof run === 'function') {
1952
+ run();
1953
+ }
1942
1954
  }
1943
1955
  });
1944
1956
  } catch (error) {
@@ -1973,7 +1985,8 @@ SystemOperations.propTypes = {
1973
1985
  iconClassName: PropTypes.string,
1974
1986
  confirmTitle: PropTypes.string,
1975
1987
  cancelText: PropTypes.string,
1976
- okText: PropTypes.string
1988
+ okText: PropTypes.string,
1989
+ run: PropTypes.func
1977
1990
  };
1978
1991
 
1979
1992
  const defaultFieldConfigs = {
@@ -2232,6 +2245,7 @@ const NetworkFieldGroup = _ref => {
2232
2245
  interfaces,
2233
2246
  fieldConfig = {}
2234
2247
  } = _ref;
2248
+ // 默认字段配置
2235
2249
  const defaultFieldConfig = {
2236
2250
  name: {
2237
2251
  label: "Name",
@@ -2243,7 +2257,7 @@ const NetworkFieldGroup = _ref => {
2243
2257
  },
2244
2258
  netmask: {
2245
2259
  label: "Netmask",
2246
- enabled: prefix === "LAN"
2260
+ enabled: true
2247
2261
  }
2248
2262
  };
2249
2263
  const mergedFieldConfig = {
@@ -2288,14 +2302,22 @@ const NetworkSettingsModal = _ref2 => {
2288
2302
  open,
2289
2303
  onClose,
2290
2304
  getLanConfig,
2305
+ // 可选 - 单独获取LAN配置的函数
2291
2306
  getSysConfig,
2307
+ // 可选 - 单独获取QSFP配置的函数
2308
+ getConfig,
2309
+ // 可选 - 统一获取配置的函数
2292
2310
  updateLanConfig,
2293
2311
  updateSysConfig,
2294
2312
  restart,
2295
2313
  modalProps = {},
2296
2314
  formProps = {},
2297
2315
  fieldConfig = {},
2298
- sections = ['LAN', 'QSFP']
2316
+ sections = ['LAN', 'QSFP'],
2317
+ showNetmask = {
2318
+ LAN: true,
2319
+ QSFP: false
2320
+ }
2299
2321
  } = _ref2;
2300
2322
  const {
2301
2323
  message,
@@ -2310,30 +2332,63 @@ const NetworkSettingsModal = _ref2 => {
2310
2332
  hasFetched: false,
2311
2333
  hasInitialized: false
2312
2334
  });
2335
+ const preparedFieldConfig = react.useMemo(() => {
2336
+ const config = {
2337
+ ...fieldConfig
2338
+ };
2339
+
2340
+ // 确保LAN和QSFP的配置存在
2341
+ config.LAN = config.LAN || {};
2342
+ config.QSFP = config.QSFP || {};
2343
+ if (sections.includes('LAN')) {
2344
+ config.LAN.netmask = {
2345
+ ...(config.LAN.netmask || {}),
2346
+ enabled: showNetmask.LAN
2347
+ };
2348
+ }
2349
+ if (sections.includes('QSFP')) {
2350
+ config.QSFP.netmask = {
2351
+ ...(config.QSFP.netmask || {}),
2352
+ enabled: showNetmask.QSFP
2353
+ };
2354
+ }
2355
+ return config;
2356
+ }, [fieldConfig, showNetmask, sections]);
2313
2357
  react.useEffect(() => {
2314
2358
  if (!open) return;
2315
2359
  const fetchData = async () => {
2316
2360
  if (initializationStatus.current.hasFetched) return;
2317
2361
  try {
2318
2362
  initializationStatus.current.hasFetched = true;
2319
- const promises = [];
2320
- if (sections.includes('LAN')) {
2321
- promises.push(getLanConfig());
2322
- }
2323
- if (sections.includes('QSFP')) {
2324
- promises.push(getSysConfig());
2325
- }
2326
- const results = await Promise.allSettled(promises);
2327
- if (sections.includes('LAN')) {
2328
- const lanResult = results[0];
2329
- if (lanResult.status === 'fulfilled') {
2330
- setLanConfigs(lanResult.value || []);
2363
+ if (getConfig) {
2364
+ // 使用统一接口获取数据
2365
+ const config = await getConfig();
2366
+ if (sections.includes('LAN') && config.lan_interfaces) {
2367
+ setLanConfigs(config.lan_interfaces);
2331
2368
  }
2332
- }
2333
- if (sections.includes('QSFP')) {
2334
- const sysResult = sections.includes('LAN') ? results[1] : results[0];
2335
- if (sysResult.status === 'fulfilled' && sysResult.value) {
2336
- setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2369
+ if (sections.includes('QSFP') && config.interfaces) {
2370
+ setSt2110Interfaces(config.interfaces);
2371
+ }
2372
+ } else {
2373
+ const promises = [];
2374
+ if (sections.includes('LAN')) {
2375
+ promises.push(getLanConfig());
2376
+ }
2377
+ if (sections.includes('QSFP')) {
2378
+ promises.push(getSysConfig());
2379
+ }
2380
+ const results = await Promise.allSettled(promises);
2381
+ if (sections.includes('LAN') && getLanConfig) {
2382
+ const lanResult = results[0];
2383
+ if (lanResult.status === 'fulfilled') {
2384
+ setLanConfigs(lanResult.value || []);
2385
+ }
2386
+ }
2387
+ if (sections.includes('QSFP') && getSysConfig) {
2388
+ const sysResult = sections.includes('LAN') ? results[1] : results[0];
2389
+ if (sysResult.status === 'fulfilled' && sysResult.value) {
2390
+ setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2391
+ }
2337
2392
  }
2338
2393
  }
2339
2394
  setIsInitialized(true);
@@ -2367,18 +2422,27 @@ const NetworkSettingsModal = _ref2 => {
2367
2422
  connection_id: config.connection_id,
2368
2423
  display_name: config.display_name,
2369
2424
  ip_address: config.ip_address,
2370
- netmask: config.netmask
2425
+ ...(showNetmask.LAN ? {
2426
+ netmask: config.netmask
2427
+ } : {})
2371
2428
  }));
2372
2429
  }
2373
2430
  if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
2374
2431
  values.QSFP = st2110Interfaces.map(iface => ({
2375
- id: iface.id,
2432
+ // 只有当iface中存在id字段时才包含id
2433
+ ...(iface.id !== undefined && {
2434
+ id: iface.id
2435
+ }),
2376
2436
  display_name: iface.display_name,
2377
- ip_address: iface.ip_address
2437
+ ip_address: iface.ip_address || iface.ip,
2438
+ // 优先取ip_address,没有则取ip
2439
+ ...(showNetmask.QSFP ? {
2440
+ netmask: iface.netmask
2441
+ } : {})
2378
2442
  }));
2379
2443
  }
2380
2444
  return values;
2381
- }, [lanConfigs, st2110Interfaces, sections]);
2445
+ }, [lanConfigs, st2110Interfaces, sections, showNetmask]);
2382
2446
 
2383
2447
  // 当初始值准备好后设置表单值
2384
2448
  react.useEffect(() => {
@@ -2388,10 +2452,28 @@ const NetworkSettingsModal = _ref2 => {
2388
2452
  }
2389
2453
  }, [isInitialized, form, initialValues]);
2390
2454
  const handleSuccess = react.useCallback(async function () {
2391
- let isPopup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2392
- let messageText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Success';
2455
+ let {
2456
+ messageText = 'Success',
2457
+ isPopup = !!restart,
2458
+ refresh = !restart
2459
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2393
2460
  message.success(messageText);
2394
- if (isPopup) {
2461
+ if (refresh && getConfig) {
2462
+ try {
2463
+ const newConfig = await getConfig();
2464
+ if (sections.includes('LAN') && newConfig.lan_interfaces) {
2465
+ setLanConfigs(newConfig.lan_interfaces);
2466
+ }
2467
+ if (sections.includes('QSFP') && newConfig.interfaces) {
2468
+ setSt2110Interfaces(newConfig.interfaces);
2469
+ }
2470
+ } catch (error) {
2471
+ console.error('Failed to refresh config:', error);
2472
+ }
2473
+ }
2474
+
2475
+ // 如果有restart函数,则显示重启确认框
2476
+ if (isPopup && restart) {
2395
2477
  try {
2396
2478
  const updatedConfig = await getSysConfig();
2397
2479
  if (updatedConfig && updatedConfig.is_restart_required) {
@@ -2422,7 +2504,9 @@ const NetworkSettingsModal = _ref2 => {
2422
2504
  const lanData = values.LAN.map((item, index) => ({
2423
2505
  connection_id: lanConfigs[index]?.connection_id,
2424
2506
  ip_address: item.ip_address,
2425
- netmask: item.netmask
2507
+ ...(showNetmask.LAN ? {
2508
+ netmask: item.netmask
2509
+ } : {})
2426
2510
  }));
2427
2511
  updatePromises.push(updateLanConfig(lanData));
2428
2512
  }
@@ -2431,8 +2515,14 @@ const NetworkSettingsModal = _ref2 => {
2431
2515
  if (sections.includes('QSFP') && values.QSFP) {
2432
2516
  const st2110Data = {
2433
2517
  st2110_interfaces: values.QSFP.map((item, index) => ({
2434
- id: st2110Interfaces?.[index]?.id,
2435
- ip_address: item.ip_address
2518
+ // 只有当原始数据中存在id时才包含id
2519
+ ...(st2110Interfaces?.[index]?.id !== undefined && {
2520
+ id: st2110Interfaces?.[index]?.id
2521
+ }),
2522
+ ip_address: item.ip_address,
2523
+ ...(showNetmask.QSFP ? {
2524
+ netmask: item.netmask
2525
+ } : {})
2436
2526
  }))
2437
2527
  };
2438
2528
  updatePromises.push(updateSysConfig(st2110Data));
@@ -2493,12 +2583,12 @@ const NetworkSettingsModal = _ref2 => {
2493
2583
  children: [/*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2494
2584
  prefix: "LAN",
2495
2585
  interfaces: lanConfigs,
2496
- fieldConfig: fieldConfig.LAN
2586
+ fieldConfig: preparedFieldConfig.LAN
2497
2587
  }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2498
2588
  }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2499
2589
  prefix: "QSFP",
2500
2590
  interfaces: st2110Interfaces,
2501
- fieldConfig: fieldConfig.QSFP
2591
+ fieldConfig: preparedFieldConfig.QSFP
2502
2592
  })]
2503
2593
  })
2504
2594
  });