Skip to content

Commit

Permalink
feat(ui): allow to create schema as JsonSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Dec 4, 2021
1 parent 6e9cc67 commit f73ddb2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ class Form extends Root {
}

export default Form;

42 changes: 35 additions & 7 deletions client/src/containers/Schema/SchemaCreate/SchemaCreate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import React from 'react';
import Header from '../../Header';
import Joi from 'joi-browser';
import Form from '../../../components/Form/Form';
import { uriSchemaCreate } from '../../../utils/endpoints';
import { toast } from 'react-toastify';
import {uriSchemaCreate} from '../../../utils/endpoints';
import {toast} from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

class SchemaCreate extends Form {
state = {
formData: {
subject: '',
compatibilityLevel: 'BACKWARD',
schemaData: ''
schemaData: '',
schemaType: 'AVRO'
},
compatibilityLevelSelect: [
{ _id: 'NONE', name: 'NONE' },
Expand All @@ -22,6 +23,11 @@ class SchemaCreate extends Form {
{ _id: 'FULL', name: 'FULL' },
{ _id: 'FULL_TRANSITIVE', name: 'FULL_TRANSITIVE' }
],
schemaTypeSelect: [
{ _id: 'AVRO', name: 'AVRO' },
{ _id: 'JSON', name: 'JSON' },
{ _id: 'PROTOBUF', name: 'PROTOBUF' }
],
errors: {}
};

Expand All @@ -32,6 +38,9 @@ class SchemaCreate extends Form {
compatibilityLevel: Joi.string()
.label('Compatibility')
.required(),
schemaType: Joi.string()
.label('SchemaType')
.required(),
schemaData: Joi.string()
.label('SchemaData')
.required()
Expand All @@ -48,14 +57,23 @@ class SchemaCreate extends Form {
const { formData } = this.state;
const { clusterId } = this.props.match.params;

const parsedSchemaData = JSON.parse(formData.schemaData);
const schemaData = parsedSchemaData.schema ? JSON.stringify(parsedSchemaData.schema) : formData.schemaData;
const references = parsedSchemaData.references || [];
const schemaType = formData.schemaType;
let schemaData;
let references;

if (formData.schemaType === 'PROTOBUF') {
schemaData = formData.schemaData;
} else {
const parsedSchemaData = JSON.parse(formData.schemaData);
schemaData = parsedSchemaData.schema ? JSON.stringify(parsedSchemaData.schema) : formData.schemaData
references = parsedSchemaData.references || [];
}

const schema = {
cluster: clusterId,
subject: formData.subject,
schema: schemaData,
schemaType: schemaType,
references: references,
compatibilityLevel: formData.compatibilityLevel
};
Expand All @@ -70,7 +88,7 @@ class SchemaCreate extends Form {
}

render() {
const { compatibilityLevelSelect, formData } = this.state;
const { compatibilityLevelSelect, schemaTypeSelect, formData } = this.state;
return (
<div>
<form
Expand All @@ -91,6 +109,16 @@ class SchemaCreate extends Form {
'col-sm-10'
)}

{this.renderSelect(
'schemaType',
'Schema Type',
schemaTypeSelect,
value => {
this.setState({ formData: { ...formData, schemaType: value.target.value } });
},
'col-sm-10'
)}

{this.renderJSONInput('schemaData', 'Schema', value => {
this.setState({
formData: {
Expand Down
5 changes: 5 additions & 0 deletions client/src/containers/Schema/SchemaList/SchemaList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class SchemaList extends Root {
accessor: 'subject',
colName: 'Subject'
},
{
id: 'schemaType',
accessor: 'schemaType',
colName: 'Schema Type'
},
{
id: 'version',
accessor: 'version',
Expand Down

0 comments on commit f73ddb2

Please sign in to comment.