Repository: provectus/kafka-ui
Issue: Messages: Produce: "Keep contents" prevents new dummy data from being generated
Labels: type/bug
good first issue
scope/frontend
status/accepted
status/confirmed
area/messages

Since #2672
Setup:
1. Topic "test"
2. Two JSON schemas, "test-key", "test-value":
```json
{
	"schema": "http://json-schema.org/draft-07/schema#",
	"id": "http://example.com/myURI.schema.json",
	"title": "TestRecord",
	"type": "object",
	"properties": {
		"f1": {
			"type": "integer"
		}
	}
}
```

Steps to reproduce:
1. Click "produce message". Observe that dummy data is generated for value
2. Produce a message
3. Open produce message again. No new data has been generated

#3901 

Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Messages/getDefaultSerdeName.ts b/kafka-ui-react-app/src/components/Topics/Topic/Messages/getDefaultSerdeName.ts
index 27fc112c819..a5235e9ac5b 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/Messages/getDefaultSerdeName.ts
+++ b/kafka-ui-react-app/src/components/Topics/Topic/Messages/getDefaultSerdeName.ts
@@ -1,8 +1,8 @@
 import { SerdeDescription } from 'generated-sources';
-import { getPrefferedDescription } from 'components/Topics/Topic/SendMessage/utils';
+import { getPreferredDescription } from 'components/Topics/Topic/SendMessage/utils';
 
 export const getDefaultSerdeName = (serdes: SerdeDescription[]) => {
-  const preffered = getPrefferedDescription(serdes);
+  const preffered = getPreferredDescription(serdes);
   if (preffered) {
     return preffered.name || '';
   }
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/SendMessage.tsx b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/SendMessage.tsx
index b7f31a230bd..bef7a4dddb5 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/SendMessage.tsx
+++ b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/SendMessage.tsx
@@ -118,8 +118,8 @@ const SendMessage: React.FC<{ closeSidebar: () => void }> = ({
         valueSerde,
       });
       if (!keepContents) {
-        setValue('key', '');
-        setValue('content', '');
+        setValue('key', defaultValues.key || '');
+        setValue('content', defaultValues.content || '');
         closeSidebar();
       }
     } catch (e) {
diff --git a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/utils.ts b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/utils.ts
index 6f98c5916d3..c8161b0c823 100644
--- a/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/utils.ts
+++ b/kafka-ui-react-app/src/components/Topics/Topic/SendMessage/utils.ts
@@ -13,21 +13,21 @@ jsf.option('fillProperties', false);
 jsf.option('alwaysFakeOptionals', true);
 jsf.option('failOnInvalidFormat', false);
 
-const generateValueFromSchema = (preffered?: SerdeDescription) => {
-  if (!preffered?.schema) {
+const generateValueFromSchema = (preferred?: SerdeDescription) => {
+  if (!preferred?.schema) {
     return undefined;
   }
-  const parsedSchema = JSON.parse(preffered.schema);
+  const parsedSchema = JSON.parse(preferred.schema);
   const value = jsf.generate(parsedSchema);
   return JSON.stringify(value);
 };
 
-export const getPrefferedDescription = (serdes: SerdeDescription[]) =>
+export const getPreferredDescription = (serdes: SerdeDescription[]) =>
   serdes.find((s) => s.preferred);
 
 export const getDefaultValues = (serdes: TopicSerdeSuggestion) => {
-  const keySerde = getPrefferedDescription(serdes.key || []);
-  const valueSerde = getPrefferedDescription(serdes.value || []);
+  const keySerde = getPreferredDescription(serdes.key || []);
+  const valueSerde = getPreferredDescription(serdes.value || []);
 
   return {
     key: generateValueFromSchema(keySerde),
@@ -65,15 +65,15 @@ export const validateBySchema = (
     return errors;
   }
 
-  let parcedSchema;
+  let parsedSchema;
   let parsedValue;
 
   try {
-    parcedSchema = JSON.parse(schema);
+    parsedSchema = JSON.parse(schema);
   } catch (e) {
     return [`Error in parsing the "${type}" field schema`];
   }
-  if (parcedSchema.type === 'string') {
+  if (parsedSchema.type === 'string') {
     return [];
   }
   try {
@@ -84,7 +84,7 @@ export const validateBySchema = (
   try {
     const ajv = new Ajv();
     addFormats(ajv);
-    const validate = ajv.compile(parcedSchema);
+    const validate = ajv.compile(parsedSchema);
     validate(parsedValue);
     if (validate.errors) {
       errors = validate.errors.map(


Test patch: