Skip to content

Commit

Permalink
added status hande after redirect from sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
pavyarov authored and pavyarov committed Apr 29, 2020
1 parent 9b9c3f7 commit c9701ea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/content-script/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { MemoryRouter, Route } from 'react-router-dom';
import { MemoryRouter, Route, Redirect } from 'react-router-dom';
import { DraggableEventHandler } from 'react-draggable';
import { Panel, PanelSpread, Icons } from '@drill4j/ui-kit';
import { browser } from 'webextension-polyfill-ts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Switch, Route, useHistory } from 'react-router-dom';
import { browser } from 'webextension-polyfill-ts';
import {
Switch, Route, useHistory,
} from 'react-router-dom';

import { useAgentConfig, useAgentInfo } from '../../../hooks';

Expand All @@ -10,18 +11,17 @@ import { FinishRecording } from './finish-recording';
import { UnavailablePage } from '../unavailable-page';

export const ManualTestingPage = () => {
const { push } = useHistory();
const { push, location: { pathname } } = useHistory();
const config = useAgentConfig();
const { status = '' } = useAgentInfo(config?.drillAdminUrl, config?.drillAgentId) || {};

React.useEffect(() => {
if (status === 'BUSY' || status === 'OFFLINE') {
if ((status === 'BUSY' || status === 'OFFLINE') && pathname === '/manual-testing') {
push('/unavailable-page');
return;
} else if (pathname !== '/unavailable-page' && pathname !== '/test-to-code') {
config?.isActive ? push('/manual-testing/in-progress') : push('/manual-testing');
}

config?.isActive ? push('/manual-testing/in-progress') : push('/manual-testing');
}, [config, status]);
}, [config, status, pathname]);

return (
<Switch>
Expand Down
9 changes: 1 addition & 8 deletions src/content-script/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { Icons, Panel } from '@drill4j/ui-kit';
import { browser } from 'webextension-polyfill-ts';

import { Plugin } from '../../types/plugin';
import { useLocalStorage } from '../../hooks';
import { useDispatcher } from '../hooks';
import { AgentConfig } from '../../types/agent-config';

import styles from './sidebar.module.scss';

Expand All @@ -24,7 +22,6 @@ const mock = [{ name: 'Test', id: 'manual-testing' }, { name: 'TestToCodeMapping
export const Sidebar = sidebar(({ className, plugins = mock }: Props) => {
const { push, location: { pathname } } = useHistory();
const dispatcher = useDispatcher();
const { [window.location.host]: config } = useLocalStorage<AgentConfig>(window.location.host) || {};

return (
<div className={className}>
Expand All @@ -40,11 +37,7 @@ export const Sidebar = sidebar(({ className, plugins = mock }: Props) => {
onClick={() => {
dispatcher({ type: 'SET_EXPANDED', payload: true });
browser.storage.local.set({ expanded: true });
if (id === 'manual-testing' && config.isActive) {
push(`/${id}/in-progress`);
} else {
push(`/${id}`);
}
push(`/${id}`);
}}
active={pathname.slice(1).startsWith(id)}
>
Expand Down

0 comments on commit c9701ea

Please sign in to comment.