seeder-st2110-components 1.1.3 → 1.1.4

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,23 @@ 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,
2313
+ refreshSettings,
2295
2314
  modalProps = {},
2296
2315
  formProps = {},
2297
2316
  fieldConfig = {},
2298
- sections = ['LAN', 'QSFP']
2317
+ sections = ['LAN', 'QSFP'],
2318
+ showNetmask = {
2319
+ LAN: true,
2320
+ QSFP: false
2321
+ } // 控制各部分的netmask显示
2299
2322
  } = _ref2;
2300
2323
  const {
2301
2324
  message,
@@ -2310,30 +2333,63 @@ const NetworkSettingsModal = _ref2 => {
2310
2333
  hasFetched: false,
2311
2334
  hasInitialized: false
2312
2335
  });
2336
+ const preparedFieldConfig = react.useMemo(() => {
2337
+ const config = {
2338
+ ...fieldConfig
2339
+ };
2340
+
2341
+ // 确保LAN和QSFP的配置存在
2342
+ config.LAN = config.LAN || {};
2343
+ config.QSFP = config.QSFP || {};
2344
+ if (sections.includes('LAN')) {
2345
+ config.LAN.netmask = {
2346
+ ...(config.LAN.netmask || {}),
2347
+ enabled: showNetmask.LAN
2348
+ };
2349
+ }
2350
+ if (sections.includes('QSFP')) {
2351
+ config.QSFP.netmask = {
2352
+ ...(config.QSFP.netmask || {}),
2353
+ enabled: showNetmask.QSFP
2354
+ };
2355
+ }
2356
+ return config;
2357
+ }, [fieldConfig, showNetmask, sections]);
2313
2358
  react.useEffect(() => {
2314
2359
  if (!open) return;
2315
2360
  const fetchData = async () => {
2316
2361
  if (initializationStatus.current.hasFetched) return;
2317
2362
  try {
2318
2363
  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 || []);
2364
+ if (getConfig) {
2365
+ // 使用统一接口获取数据
2366
+ const config = await getConfig();
2367
+ if (sections.includes('LAN') && config.lan_interfaces) {
2368
+ setLanConfigs(config.lan_interfaces);
2331
2369
  }
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 || []);
2370
+ if (sections.includes('QSFP') && config.interfaces) {
2371
+ setSt2110Interfaces(config.interfaces);
2372
+ }
2373
+ } else {
2374
+ const promises = [];
2375
+ if (sections.includes('LAN')) {
2376
+ promises.push(getLanConfig());
2377
+ }
2378
+ if (sections.includes('QSFP')) {
2379
+ promises.push(getSysConfig());
2380
+ }
2381
+ const results = await Promise.allSettled(promises);
2382
+ if (sections.includes('LAN') && getLanConfig) {
2383
+ const lanResult = results[0];
2384
+ if (lanResult.status === 'fulfilled') {
2385
+ setLanConfigs(lanResult.value || []);
2386
+ }
2387
+ }
2388
+ if (sections.includes('QSFP') && getSysConfig) {
2389
+ const sysResult = sections.includes('LAN') ? results[1] : results[0];
2390
+ if (sysResult.status === 'fulfilled' && sysResult.value) {
2391
+ setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2392
+ }
2337
2393
  }
2338
2394
  }
2339
2395
  setIsInitialized(true);
@@ -2367,18 +2423,27 @@ const NetworkSettingsModal = _ref2 => {
2367
2423
  connection_id: config.connection_id,
2368
2424
  display_name: config.display_name,
2369
2425
  ip_address: config.ip_address,
2370
- netmask: config.netmask
2426
+ ...(showNetmask.LAN ? {
2427
+ netmask: config.netmask
2428
+ } : {})
2371
2429
  }));
2372
2430
  }
2373
2431
  if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
2374
2432
  values.QSFP = st2110Interfaces.map(iface => ({
2375
- id: iface.id,
2433
+ // 只有当iface中存在id字段时才包含id
2434
+ ...(iface.id !== undefined && {
2435
+ id: iface.id
2436
+ }),
2376
2437
  display_name: iface.display_name,
2377
- ip_address: iface.ip_address
2438
+ ip_address: iface.ip_address || iface.ip,
2439
+ // 优先取ip_address,没有则取ip
2440
+ ...(showNetmask.QSFP ? {
2441
+ netmask: iface.netmask
2442
+ } : {})
2378
2443
  }));
2379
2444
  }
2380
2445
  return values;
2381
- }, [lanConfigs, st2110Interfaces, sections]);
2446
+ }, [lanConfigs, st2110Interfaces, sections, showNetmask]);
2382
2447
 
2383
2448
  // 当初始值准备好后设置表单值
2384
2449
  react.useEffect(() => {
@@ -2388,10 +2453,16 @@ const NetworkSettingsModal = _ref2 => {
2388
2453
  }
2389
2454
  }, [isInitialized, form, initialValues]);
2390
2455
  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';
2456
+ let {
2457
+ messageText = 'Success',
2458
+ isPopup = !!restart,
2459
+ refresh = !!refreshSettings
2460
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2393
2461
  message.success(messageText);
2394
- if (isPopup) {
2462
+ if (refresh && refreshSettings) {
2463
+ await refreshSettings();
2464
+ }
2465
+ if (isPopup && restart) {
2395
2466
  try {
2396
2467
  const updatedConfig = await getSysConfig();
2397
2468
  if (updatedConfig && updatedConfig.is_restart_required) {
@@ -2408,7 +2479,7 @@ const NetworkSettingsModal = _ref2 => {
2408
2479
  }
2409
2480
  }
2410
2481
  onClose();
2411
- }, [message, modal, getSysConfig, restart, onClose]);
2482
+ }, [message, modal, getSysConfig, restart, refreshSettings, onClose]);
2412
2483
  const handleSubmit = react.useCallback(async () => {
2413
2484
  setSubmitLoading(true);
2414
2485
  try {
@@ -2422,7 +2493,9 @@ const NetworkSettingsModal = _ref2 => {
2422
2493
  const lanData = values.LAN.map((item, index) => ({
2423
2494
  connection_id: lanConfigs[index]?.connection_id,
2424
2495
  ip_address: item.ip_address,
2425
- netmask: item.netmask
2496
+ ...(showNetmask.LAN ? {
2497
+ netmask: item.netmask
2498
+ } : {})
2426
2499
  }));
2427
2500
  updatePromises.push(updateLanConfig(lanData));
2428
2501
  }
@@ -2431,8 +2504,14 @@ const NetworkSettingsModal = _ref2 => {
2431
2504
  if (sections.includes('QSFP') && values.QSFP) {
2432
2505
  const st2110Data = {
2433
2506
  st2110_interfaces: values.QSFP.map((item, index) => ({
2434
- id: st2110Interfaces?.[index]?.id,
2435
- ip_address: item.ip_address
2507
+ // 只有当原始数据中存在id时才包含id
2508
+ ...(st2110Interfaces?.[index]?.id !== undefined && {
2509
+ id: st2110Interfaces?.[index]?.id
2510
+ }),
2511
+ ip_address: item.ip_address,
2512
+ ...(showNetmask.QSFP ? {
2513
+ netmask: item.netmask
2514
+ } : {})
2436
2515
  }))
2437
2516
  };
2438
2517
  updatePromises.push(updateSysConfig(st2110Data));
@@ -2493,12 +2572,12 @@ const NetworkSettingsModal = _ref2 => {
2493
2572
  children: [/*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2494
2573
  prefix: "LAN",
2495
2574
  interfaces: lanConfigs,
2496
- fieldConfig: fieldConfig.LAN
2575
+ fieldConfig: preparedFieldConfig.LAN
2497
2576
  }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2498
2577
  }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2499
2578
  prefix: "QSFP",
2500
2579
  interfaces: st2110Interfaces,
2501
- fieldConfig: fieldConfig.QSFP
2580
+ fieldConfig: preparedFieldConfig.QSFP
2502
2581
  })]
2503
2582
  })
2504
2583
  });