seeder-st2110-components 1.0.3 → 1.0.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
@@ -2270,10 +2270,12 @@ const NetworkFieldGroup = _ref => {
2270
2270
  }), mergedFieldConfig.ip.enabled && /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
2271
2271
  label: mergedFieldConfig.ip.label,
2272
2272
  name: [prefix, index, "ip_address"],
2273
+ initialValue: iface.ip_address,
2273
2274
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Input, {})
2274
2275
  }), mergedFieldConfig.netmask.enabled && /*#__PURE__*/jsxRuntime.jsx(antd.Form.Item, {
2275
2276
  label: mergedFieldConfig.netmask.label,
2276
2277
  name: [prefix, index, "netmask"],
2278
+ initialValue: iface.netmask,
2277
2279
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Input, {})
2278
2280
  }), index < interfaces.length - 1 && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {
2279
2281
  style: {
@@ -2305,59 +2307,79 @@ const NetworkSettingsModal = _ref2 => {
2305
2307
  const [st2110Interfaces, setSt2110Interfaces] = react.useState([]);
2306
2308
  const [lanConfigs, setLanConfigs] = react.useState([]);
2307
2309
  const [submitLoading, setSubmitLoading] = react.useState(false);
2308
- react.useEffect(() => {
2309
- const fetchInitialData = async () => {
2310
- try {
2311
- const promises = [];
2312
- if (sections.includes('LAN')) {
2313
- promises.push(getLanConfig());
2314
- }
2315
- if (sections.includes('QSFP')) {
2316
- promises.push(getSysConfig());
2317
- }
2318
- const results = await Promise.allSettled(promises);
2319
- if (sections.includes('LAN')) {
2320
- const lanResult = results[sections.indexOf('LAN')];
2321
- if (lanResult.status === 'fulfilled') {
2322
- setLanConfigs(lanResult.value);
2323
- }
2310
+ const [isInitialized, setIsInitialized] = react.useState(false);
2311
+ const fetchData = react.useCallback(async () => {
2312
+ if (!open) return;
2313
+ try {
2314
+ const promises = [];
2315
+ if (sections.includes('LAN')) {
2316
+ promises.push(getLanConfig());
2317
+ }
2318
+ if (sections.includes('QSFP')) {
2319
+ promises.push(getSysConfig());
2320
+ }
2321
+ const results = await Promise.allSettled(promises);
2322
+ if (sections.includes('LAN')) {
2323
+ const lanResult = results[0];
2324
+ if (lanResult.status === 'fulfilled') {
2325
+ setLanConfigs(lanResult.value || []);
2324
2326
  }
2325
- if (sections.includes('QSFP')) {
2326
- const sysResult = results[sections.indexOf('QSFP')];
2327
- if (sysResult.status === 'fulfilled' && sysResult.value) {
2328
- setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2329
- }
2327
+ }
2328
+ if (sections.includes('QSFP')) {
2329
+ const sysResult = sections.includes('LAN') ? results[1] : results[0];
2330
+ if (sysResult.status === 'fulfilled' && sysResult.value) {
2331
+ setSt2110Interfaces(sysResult.value.st2110_interfaces || []);
2330
2332
  }
2331
- } catch (error) {
2332
- console.error('Failed to fetch data:', error);
2333
2333
  }
2334
- };
2335
- if (open) {
2336
- fetchInitialData();
2334
+ setIsInitialized(true);
2335
+ } catch (error) {
2336
+ console.error('Failed to fetch data:', error);
2337
2337
  }
2338
2338
  }, [open, getLanConfig, getSysConfig, sections]);
2339
+ react.useEffect(() => {
2340
+ if (open) {
2341
+ fetchData();
2342
+ }
2343
+ }, [open, fetchData]);
2344
+
2345
+ // 当模态框关闭时重置状态
2346
+ react.useEffect(() => {
2347
+ if (!open) {
2348
+ setIsInitialized(false);
2349
+ setLanConfigs([]);
2350
+ setSt2110Interfaces([]);
2351
+ form.resetFields();
2352
+ }
2353
+ }, [open, form]);
2339
2354
 
2340
2355
  // 动态初始值配置
2341
2356
  const initialValues = react.useMemo(() => {
2342
2357
  const values = {};
2343
- if (sections.includes('LAN')) {
2358
+ if (sections.includes('LAN') && lanConfigs.length > 0) {
2344
2359
  values.LAN = lanConfigs.map(config => ({
2345
2360
  connection_id: config.connection_id,
2346
2361
  display_name: config.display_name,
2347
2362
  ip_address: config.ip_address,
2348
2363
  netmask: config.netmask
2349
- })) ?? [];
2364
+ }));
2350
2365
  }
2351
- if (sections.includes('QSFP')) {
2352
- values.QSFP = st2110Interfaces?.map(iface => ({
2366
+ if (sections.includes('QSFP') && st2110Interfaces.length > 0) {
2367
+ values.QSFP = st2110Interfaces.map(iface => ({
2353
2368
  id: iface.id,
2354
2369
  display_name: iface.display_name,
2355
2370
  ip_address: iface.ip_address
2356
- })) ?? [];
2371
+ }));
2357
2372
  }
2358
2373
  return values;
2359
2374
  }, [lanConfigs, st2110Interfaces, sections]);
2360
- const handleSuccess = async function () {
2375
+
2376
+ // 当初始值准备好后设置表单值
2377
+ react.useEffect(() => {
2378
+ if (isInitialized && Object.keys(initialValues).length > 0) {
2379
+ form.setFieldsValue(initialValues);
2380
+ }
2381
+ }, [initialValues, isInitialized, form]);
2382
+ const handleSuccess = react.useCallback(async function () {
2361
2383
  let isPopup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2362
2384
  let messageText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Success';
2363
2385
  message.success(messageText);
@@ -2378,8 +2400,8 @@ const NetworkSettingsModal = _ref2 => {
2378
2400
  }
2379
2401
  }
2380
2402
  onClose();
2381
- };
2382
- const handleSubmit = async () => {
2403
+ }, [message, modal, getSysConfig, restart, onClose]);
2404
+ const handleSubmit = react.useCallback(async () => {
2383
2405
  setSubmitLoading(true);
2384
2406
  try {
2385
2407
  const values = await form.validateFields();
@@ -2421,7 +2443,7 @@ const NetworkSettingsModal = _ref2 => {
2421
2443
  } finally {
2422
2444
  setSubmitLoading(false);
2423
2445
  }
2424
- };
2446
+ }, [form, sections, lanConfigs, st2110Interfaces, updateLanConfig, updateSysConfig, handleSuccess, message]);
2425
2447
 
2426
2448
  // 合并默认模态框属性和传入的属性
2427
2449
  const mergedModalProps = {
@@ -2445,7 +2467,6 @@ const NetworkSettingsModal = _ref2 => {
2445
2467
  // 合并默认表单属性和传入的属性
2446
2468
  const mergedFormProps = {
2447
2469
  form: form,
2448
- initialValues: initialValues,
2449
2470
  labelCol: {
2450
2471
  span: 6
2451
2472
  },
@@ -2459,15 +2480,15 @@ const NetworkSettingsModal = _ref2 => {
2459
2480
  ...mergedModalProps,
2460
2481
  children: /*#__PURE__*/jsxRuntime.jsxs(antd.Form, {
2461
2482
  ...mergedFormProps,
2462
- children: [sections.includes('LAN') && initialValues.LAN && initialValues.LAN.length > 0 && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2483
+ children: [sections.includes('LAN') && lanConfigs.length > 0 && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2463
2484
  children: [/*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2464
2485
  prefix: "LAN",
2465
- interfaces: initialValues.LAN,
2486
+ interfaces: lanConfigs,
2466
2487
  fieldConfig: fieldConfig.LAN
2467
- }), sections.includes('QSFP') && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2468
- }), sections.includes('QSFP') && initialValues.QSFP && initialValues.QSFP.length > 0 && /*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2488
+ }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(antd.Divider, {})]
2489
+ }), sections.includes('QSFP') && st2110Interfaces.length > 0 && /*#__PURE__*/jsxRuntime.jsx(NetworkFieldGroup, {
2469
2490
  prefix: "QSFP",
2470
- interfaces: initialValues.QSFP,
2491
+ interfaces: st2110Interfaces,
2471
2492
  fieldConfig: fieldConfig.QSFP
2472
2493
  })]
2473
2494
  })