Advertisement
S11as

Draggable attributes example

Mar 21st, 2024
624
0
120 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public render(): JSX.Element {
  2.         const { label, onSkeletonSubmit } = this.props;
  3.         const isSkeleton = !!onSkeletonSubmit;
  4.  
  5.         return (
  6.             <Form
  7.                 initialValues={{
  8.                     name: label?.name || '',
  9.                     type: label?.type || (isSkeleton ? LabelType.SKELETON : LabelType.ANY),
  10.                     color: label?.color || undefined,
  11.                     attributes: (label?.attributes || []).map((attr) => ({
  12.                         id: attr.id,
  13.                         name: attr.name,
  14.                         type: attr.input_type,
  15.                         values: attr.values,
  16.                         mutable: attr.mutable,
  17.                         default_value: attr.default_value,
  18.                     })),
  19.                 }}
  20.                 onFinish={this.handleSubmit}
  21.                 layout='vertical'
  22.                 ref={this.formRef}
  23.             >
  24.                 <Row justify='start' align='top'>
  25.                     <Col span={8}>{this.renderLabelNameInput()}</Col>
  26.                     <Col span={3} offset={1}>{this.renderLabelTypeInput()}</Col>
  27.                     <Col span={3} offset={1}>
  28.                         {this.renderChangeColorButton()}
  29.                     </Col>
  30.                     <Col offset={1}>
  31.                         {this.renderNewAttributeButton()}
  32.                     </Col>
  33.                 </Row>
  34.                 <Row justify='start' align='top'>
  35.                     <Col span={24}>
  36.                         <Form.List name='attributes'>
  37.                             {(fieldInstances) => {
  38.                                 const layout = fieldInstances.map((field, index) => ({
  39.                                     i: field.key.toString(),
  40.                                     x: 0,
  41.                                     y: index,
  42.                                     h: 1,
  43.                                     w: 1,
  44.                                 }));
  45.                                 return (
  46.                                     <ReactGridLayout
  47.                                         layout={layout}
  48.                                         rowHeight={30}
  49.                                         cols={1}
  50.                                         width={600}
  51.                                     >
  52.                                         {fieldInstances.map(this.renderAttribute)}
  53.                                     </ReactGridLayout>
  54.                                 );
  55.                             }}
  56.                         </Form.List>
  57.                     </Col>
  58.                 </Row>
  59.                 <Row justify='start' align='middle'>
  60.                     <Col>{this.renderSaveButton()}</Col>
  61.                     <Col offset={1}>{this.renderCancelButton()}</Col>
  62.                 </Row>
  63.             </Form>
  64.         );
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement