Browse Source

Spinner fixed (#1964)

* Spinner fixed

* Tests refactored
Kirill Morozov 3 years ago
parent
commit
20300f327d

+ 0 - 3
kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Filters/Filters.tsx

@@ -229,7 +229,6 @@ const Filters: React.FC<FiltersProps> = ({
 
 
   const handleSSECancel = () => {
   const handleSSECancel = () => {
     if (!source.current) return;
     if (!source.current) return;
-
     setIsFetching(false);
     setIsFetching(false);
     source.current.close();
     source.current.close();
   };
   };
@@ -304,7 +303,6 @@ const Filters: React.FC<FiltersProps> = ({
       sse.onmessage = ({ data }) => {
       sse.onmessage = ({ data }) => {
         const { type, message, phase, consuming }: TopicMessageEvent =
         const { type, message, phase, consuming }: TopicMessageEvent =
           JSON.parse(data);
           JSON.parse(data);
-
         switch (type) {
         switch (type) {
           case TopicMessageEventTypeEnum.MESSAGE:
           case TopicMessageEventTypeEnum.MESSAGE:
             if (message) {
             if (message) {
@@ -317,7 +315,6 @@ const Filters: React.FC<FiltersProps> = ({
           case TopicMessageEventTypeEnum.PHASE:
           case TopicMessageEventTypeEnum.PHASE:
             if (phase?.name) {
             if (phase?.name) {
               updatePhase(phase.name);
               updatePhase(phase.name);
-              setIsFetching(false);
             }
             }
             break;
             break;
           case TopicMessageEventTypeEnum.CONSUMING:
           case TopicMessageEventTypeEnum.CONSUMING:

+ 1 - 1
kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/MessagesTable.tsx

@@ -96,7 +96,7 @@ const MessagesTable: React.FC = () => {
               message={message}
               message={message}
             />
             />
           ))}
           ))}
-          {(isFetching || isLive) && !messages.length && (
+          {isFetching && isLive && !messages.length && (
             <tr>
             <tr>
               <td colSpan={10}>
               <td colSpan={10}>
                 <PageLoader />
                 <PageLoader />

+ 5 - 3
kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/__test__/MessagesTable.spec.tsx

@@ -31,6 +31,7 @@ describe('MessagesTable', () => {
     params: URLSearchParams = searchParams,
     params: URLSearchParams = searchParams,
     ctx: ContextProps = contextValue,
     ctx: ContextProps = contextValue,
     messages: TopicMessage[] = [],
     messages: TopicMessage[] = [],
+    isFetching?: boolean,
     customHistory?: MemoryHistory
     customHistory?: MemoryHistory
   ) => {
   ) => {
     const history =
     const history =
@@ -51,7 +52,7 @@ describe('MessagesTable', () => {
             meta: {
             meta: {
               ...topicMessagesMetaPayload,
               ...topicMessagesMetaPayload,
             },
             },
-            isFetching: false,
+            isFetching: !!isFetching,
           },
           },
         },
         },
       }
       }
@@ -86,7 +87,7 @@ describe('MessagesTable', () => {
     });
     });
 
 
     it('should check the display of the loader element', () => {
     it('should check the display of the loader element', () => {
-      setUpComponent(searchParams, { ...contextValue, isLive: true });
+      setUpComponent(searchParams, { ...contextValue, isLive: true }, [], true);
       expect(screen.getByRole('progressbar')).toBeInTheDocument();
       expect(screen.getByRole('progressbar')).toBeInTheDocument();
     });
     });
 
 
@@ -98,7 +99,7 @@ describe('MessagesTable', () => {
       });
       });
       jest.spyOn(mockedHistory, 'push');
       jest.spyOn(mockedHistory, 'push');
 
 
-      setUpComponent(customSearchParam, contextValue, [], mockedHistory);
+      setUpComponent(customSearchParam, contextValue, [], false, mockedHistory);
 
 
       userEvent.click(screen.getByRole('button', { name: 'Next' }));
       userEvent.click(screen.getByRole('button', { name: 'Next' }));
       expect(mockedHistory.push).toHaveBeenCalledWith({
       expect(mockedHistory.push).toHaveBeenCalledWith({
@@ -120,6 +121,7 @@ describe('MessagesTable', () => {
         customSearchParam,
         customSearchParam,
         { ...contextValue, searchParams: customSearchParam },
         { ...contextValue, searchParams: customSearchParam },
         [],
         [],
+        false,
         mockedHistory
         mockedHistory
       );
       );