edit.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import React from 'react';
  2. import { Edit, useForm } from "@refinedev/antd";
  3. import { Form, Input, Select, Card, Alert } from 'antd';
  4. import { Component, ComponentFormData } from '../../types/component';
  5. export const ComponentEdit = () => {
  6. const { formProps, saveButtonProps, queryResult } = useForm<ComponentFormData>();
  7. const record = queryResult?.data?.data as Component;
  8. const renderValidationStatus = () => {
  9. if ((record?.status === 'invalid' || record?.status === 'failed') && record?.error_msg) {
  10. return (
  11. <Alert
  12. message={record.status === 'invalid' ? "Component Validation Failed" : "Component Build Failed"}
  13. description={record.error_msg}
  14. type="error"
  15. showIcon
  16. style={{ marginBottom: 16 }}
  17. />
  18. );
  19. }
  20. if (record?.status === 'validating' || record?.status === 'building') {
  21. return (
  22. <Alert
  23. message={record.status === 'validating' ? "Component Validation in Progress" : "Component Build in Progress"}
  24. description={
  25. record.status === 'validating'
  26. ? "The system is currently validating your repository. Changes will trigger re-validation."
  27. : "The component is currently being built. Changes will trigger a new build."
  28. }
  29. type="info"
  30. showIcon
  31. style={{ marginBottom: 16 }}
  32. />
  33. );
  34. }
  35. return null;
  36. };
  37. return (
  38. <Edit saveButtonProps={saveButtonProps}>
  39. <Form {...formProps} layout="vertical">
  40. {renderValidationStatus()}
  41. <Card title="Component Information">
  42. <Form.Item
  43. label="Name"
  44. name="name"
  45. rules={[{ required: true, message: 'Please enter a component name' }]}
  46. >
  47. <Input placeholder="Enter component name" />
  48. </Form.Item>
  49. <Form.Item
  50. label="Description"
  51. name="description"
  52. >
  53. <Input.TextArea
  54. placeholder="Enter component description (optional)"
  55. rows={3}
  56. />
  57. </Form.Item>
  58. <Form.Item
  59. label="Type"
  60. name="type"
  61. rules={[{ required: true, message: 'Please select a component type' }]}
  62. >
  63. <Select placeholder="Select component type">
  64. <Select.Option value="frontend">Frontend</Select.Option>
  65. <Select.Option value="backend">Backend</Select.Option>
  66. <Select.Option value="api">API</Select.Option>
  67. <Select.Option value="database">Database</Select.Option>
  68. <Select.Option value="microservice">Microservice</Select.Option>
  69. </Select>
  70. </Form.Item>
  71. <Form.Item
  72. label="Git Repository URL"
  73. name="repository"
  74. rules={[
  75. { required: true, message: 'Please enter the Git repository URL' },
  76. { type: 'url', message: 'Please enter a valid URL' }
  77. ]}
  78. >
  79. <Input placeholder="https://github.com/username/repo" />
  80. </Form.Item>
  81. <Form.Item
  82. label="Branch"
  83. name="branch"
  84. >
  85. <Input placeholder="Enter branch name (default: main)"/>
  86. </Form.Item>
  87. <Form.Item
  88. label="Configuration"
  89. name="config"
  90. >
  91. <Input.TextArea
  92. placeholder="Enter JSON configuration (optional)"
  93. rows={4}
  94. />
  95. </Form.Item>
  96. </Card>
  97. </Form>
  98. </Edit>
  99. );
  100. };