Commit d8599b4b authored by Yadd's avatar Yadd
Browse files

Tidy JS files (#1570)

parent 18bc5dd1
Pipeline #12346 failed with stage
in 63 minutes and 9 seconds
......@@ -32,34 +32,34 @@ import { store, history } from './lib/storeInit'
import { ConnectedRouter } from 'connected-react-router';
function App() {
const routes = [<Route exact path="/" component={MenuPage} history={history} key="phome"/>];
const routes = [<Route exact path="/" component={MenuPage} history={history} key="phome" />];
Object.keys(apps).forEach(path => {
routes.push(<Route path={'/'+path} component={apps[path]} history={history} key={'p'+path}/>);
routes.push(<Route path={'/' + path} component={apps[path]} history={history} key={'p' + path} />);
})
return (
<div className="App">
<Provider store={store}>
{/* HTML headers */}
<Helmet
defaultTitle="LLNG Manager"
titleTemplate="LLNG Manager - %s"
>
<meta name="description" content="LLNG administration" />
</Helmet>
<Provider store={store}>
<ModalErr title="error" />
{/* HTML headers */}
<Helmet
defaultTitle="LLNG Manager"
titleTemplate="LLNG Manager - %s"
>
<meta name="description" content="LLNG administration" />
</Helmet>
<ConnectedRouter history={history}>
{/* General menu */}
<Nav/>
<ModalErr title="error" />
{/* Router */}
<Switch>
{routes}
</Switch>
</ConnectedRouter>
</Provider>
<ConnectedRouter history={history}>
{/* General menu */}
<Nav />
{/* Router */}
<Switch>
{routes}
</Switch>
</ConnectedRouter>
</Provider>
</div>
);
}
......
......@@ -13,20 +13,20 @@ import minimalTranslations from '../lib/language/minimalTranslations.json'
import MenuPage from '../apps/default';
const history = createMemoryHistory();
const init = function(state={}, action) {
switch(action.type) {
const init = function (state = {}, action) {
switch (action.type) {
case 'INIT':
return {...state, env: action.data};
return { ...state, env: action.data };
case 'SETLANG':
return {...state, lang: action.data};
return { ...state, lang: action.data };
case 'INSTALLLANG':
return {...state, tr: action.data};
return { ...state, tr: action.data };
case 'SETERROR':
return {...state, error: action.error};
return { ...state, error: action.error };
// Required
default:
return state;
......@@ -36,9 +36,9 @@ const init = function(state={}, action) {
const store = createStore(
combineReducers({
init,
router:connectRouter(history)
router: connectRouter(history)
}),
applyMiddleware(thunk,routerMiddleware(history))
applyMiddleware(thunk, routerMiddleware(history))
);
store.dispatch({
type: 'INIT',
......@@ -55,17 +55,17 @@ store.dispatch({
describe('Nav component with one route', () => {
const app = (
<div className="App">
<Provider store={store}>
<ConnectedRouter history={history}>
{/* General menu */}
<Nav/>
<Provider store={store}>
<ConnectedRouter history={history}>
{/* General menu */}
<Nav />
{/* Router */}
<Switch>
<Route exact path="/" component={MenuPage} history={history}/>
</Switch>
</ConnectedRouter>
</Provider>
{/* Router */}
<Switch>
<Route exact path="/" component={MenuPage} history={history} />
</Switch>
</ConnectedRouter>
</Provider>
</div>);
it('Should renders menu', () => {
const { getByText } = render(app);
......
......@@ -14,13 +14,13 @@ describe('Default app', () => {
// src/lib/__mocks__/lib/llngFetch.js replace {conf:"Configuration"}
// by {conf:"mock Configuration"}
it('Should download language', async () => {
const { findByText } = render(<App/>);
const { findByText } = render(<App />);
expect(await findByText('en Configuration')).toBeInTheDocument();
});
it('should be able to change language to fr', async () => {
const { getByAltText, findByText } = render(<App/>);
const fr=getByAltText('fr');
const { getByAltText, findByText } = render(<App />);
const fr = getByAltText('fr');
expect(fr).toBeInTheDocument();
fr.click();
expect(await findByText('fr Configuration')).toBeInTheDocument();
......
const menu = () => {
return (
<div>Choose an application</div>
)
return (
<div>Choose an application</div>
)
}
export default menu;
export default menu;
\ No newline at end of file
import React from 'react';
const DisplaySessions = ({subpath, query}) => {
const DisplaySessions = ({ subpath, query }) => {
return (<div>display sessions {subpath}, {JSON.stringify(query)}</div>);
};
......
......@@ -2,7 +2,7 @@ import React from 'react';
import { ConnectedRouter } from 'connected-react-router';
import { Helmet } from 'react-helmet';
import { Link, Switch, Route, withRouter } from 'react-router-dom';
import {connect} from 'react-redux';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
import { search } from './lib/schemes';
......@@ -12,28 +12,28 @@ const defaultSearch = Object.keys(search)[0];
const mapStateToProps = state => {
let tmp = state.router.location.search;
let query = {};
if(tmp) {
let arr = tmp.replace(/^\?/,'').split('&');
for( let i=0; i<arr.length; i++) {
if (tmp) {
let arr = tmp.replace(/^\?/, '').split('&');
for (let i = 0; i < arr.length; i++) {
var pair = arr[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
}
return {
tr: state.init.tr,
subpath: state.router.location.pathname.replace(/^\/sessions\//,''),
subpath: state.router.location.pathname.replace(/^\/sessions\//, ''),
query: query,
}
}
}
const Sessions = ({tr, query, subpath, history}) => {
const Sessions = ({ tr, query, subpath, history }) => {
const nav = [<Link to="/sessions">
<Button variant="contained" color="primary" key={defaultSearch}>{tr[defaultSearch]}</Button>
</Link>];
Object.keys(search).forEach(key => {
if(key !== defaultSearch) {
nav.push(<Link to={"/sessions/"+key} key={"link"+key} >
<Button variant="contained" color="primary" key={"b"+ key}>{tr[key]}</Button>
if (key !== defaultSearch) {
nav.push(<Link to={"/sessions/" + key} key={"link" + key} >
<Button variant="contained" color="primary" key={"b" + key}>{tr[key]}</Button>
</Link>)
}
})
......@@ -50,8 +50,8 @@ const Sessions = ({tr, query, subpath, history}) => {
{nav}
<ConnectedRouter history={history}>
<Switch>
<Route path="/sessions"><DisplaySessions subpath={defaultSearch} query={query} history={history}/></Route>
<Route path="/sessions/:type"><DisplaySessions subpath={subpath} query={query} history={history}/></Route>
<Route path="/sessions"><DisplaySessions subpath={defaultSearch} query={query} history={history} /></Route>
<Route path="/sessions/:type"><DisplaySessions subpath={subpath} query={query} history={history} /></Route>
</Switch>
</ConnectedRouter>
</div>
......
export const search = {
users: [
function(t, v) {
function (t, v) {
return "groupBy=substr(_whatToTrace,1)";
}, function(t, v) {
}, function (t, v) {
return "_whatToTrace=" + v + "*&groupBy=" + t;
}, function(t, v) {
}, function (t, v) {
return "_whatToTrace=" + v;
}
],
ipAddr: [
function(t, v) {
function (t, v) {
return "groupBy=net(" + t + ",16,1)";
}, function(t, v) {
}, function (t, v) {
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",32,2)";
}, function(t, v) {
}, function (t, v) {
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",48,3)";
}, function(t, v) {
}, function (t, v) {
if (!v.match(/:/)) {
v = v + '.';
}
return t + "=" + v + "*&groupBy=net(" + t + ",128,4)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "&groupBy=_whatToTrace";
}, function(t, v, q) {
}, function (t, v, q) {
return q.replace(/&groupBy.*$/, '') + ("&_whatToTrace=" + v);
}
],
_startTime: [
function(t, v) {
function (t, v) {
return "groupBy=substr(" + t + ",8)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "*&groupBy=substr(" + t + ",10)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "*&groupBy=substr(" + t + ",11)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "*&groupBy=substr(" + t + ",12)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "*&groupBy=_whatToTrace";
}, function(t, v, q) {
}, function (t, v, q) {
console.log(t);
console.log(v);
console.log(q);
......@@ -51,27 +51,27 @@ export const search = {
}
],
multiIp: [
function(t, v) {
function (t, v) {
return t;
}, function(t, v) {
}, function (t, v) {
return "_whatToTrace=" + v + "&groupBy=ipAddr";
}, function(t, v, q) {
}, function (t, v, q) {
return q.replace(/&groupBy.*$/, '') + ("&ipAddr=" + v);
}
],
_updateTime: [
function(t, v) {
function (t, v) {
return "groupBy=substr(" + t + ",1)";
}, function(t, v) {
}, function (t, v) {
return t + "=" + v + "*&groupBy=" + t;
}, function(t, v) {
}, function (t, v) {
return t + "=" + v;
}
]
};
export const overSearch = {
_whatToTrace: function(t, v, level, over) {
_whatToTrace: function (t, v, level, over) {
console.log('overScheme => level', level, 'over', over);
if (level === 1 && v.length > over) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (level + over + 1) + ")";
......@@ -79,7 +79,7 @@ export const overSearch = {
return null;
}
},
ipAddr: function(t, v, level, over) {
ipAddr: function (t, v, level, over) {
console.log('overScheme => level', level, 'over', over);
if (level > 0 && level < 4 && !v.match(/^\d+\.\d/) && over < 2) {
return t + "=" + v + "*&groupBy=net(" + t + "," + (16 * level + 4 * (over + 1)) + "," + (1 + level + over) + ")";
......@@ -87,7 +87,7 @@ export const overSearch = {
return null;
}
},
_startTime: function(t, v, level, over) {
_startTime: function (t, v, level, over) {
console.log('overScheme => level', level, 'over', over);
if (level > 3) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (10 + level + over) + ")";
......@@ -95,7 +95,7 @@ export const overSearch = {
return null;
}
},
_session_uid: function(t, v, level, over) {
_session_uid: function (t, v, level, over) {
console.log('overScheme => level', level, 'over', over);
if (level === 1 && v.length > over) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (level + over + 1) + ")";
......
......@@ -6,7 +6,7 @@ import { connect } from "react-redux";
import installLang from "../../lib/language/installLang";
const mapStateToProps = state => {
if(! state.init.env) return {};
if (!state.init.env) return {};
return {
staticPrefix: state.init.env.staticPrefix,
langs: state.init.env.availableLanguages || ['en'],
......@@ -26,18 +26,18 @@ const mapDispatchToProps = (dispatch) => {
* @param {after} after is the function to close menu if needed, required
* @returns component
*/
const RenderLangs = ({staticPrefix, langs, setLang, after}) => {
if(langs) {
const RenderLangs = ({ staticPrefix, langs, setLang, after }) => {
if (langs) {
let langArr = [];
let i=0;
let i = 0;
langs.forEach(lang => {
const sub = () => {
setLang(staticPrefix, lang);
after();
}
langArr.push(<span key={i++}><img src={staticPrefix+'logos/'+lang+'.png'} alt={lang} onClick={sub}/> </span>);
langArr.push(<span key={i++}><img src={staticPrefix + 'logos/' + lang + '.png'} alt={lang} onClick={sub} /> </span>);
});
return(<div>{langArr}</div>)
return (<div>{langArr}</div>)
}
else {
return [<div>coucoo</div>];
......
......@@ -4,68 +4,67 @@
* - RenderLeftMobileMenu for smartphones
*/
import { RenderMenu, RenderMobileMenu } from './_Menu';
import { RenderMenu, RenderMobileMenu } from './_Menu';
const RenderLeftMenu = ({
leftMenuId,
leftAnchorEl,
isLeftMenuOpen,
handleLeftMenuClose,
}) => {
let entries = [
{
action: () => {console.log('todo')},
content: "TODO",
},
{
action: () => {console.log('todo')},
content: "TODO2",
},
];
return (
<RenderMenu
menuId={leftMenuId}
anchorEl={leftAnchorEl}
isMenuOpen={isLeftMenuOpen}
handleMenuClose={handleLeftMenuClose}
align="left"
entries={entries}
/>
);
}
const RenderLeftMobileMenu = ({
mobileLeftMenuId,
mobileMoreLeftAnchorEl,
isMobileLeftMenuOpen,
handleMobileLeftMenuClose,
handleProfileLeftMenuOpen,
}) => {
let entries = [
{
action: () => {console.log('todo')},
content: "TODO mob",
},
{
action: () => {console.log('todo')},
content: "TODO mob2",
},
];
return (
<RenderMobileMenu
mobileMenuId={mobileLeftMenuId}
mobileMoreAnchorEl={mobileMoreLeftAnchorEl}
isMobileMenuOpen={isMobileLeftMenuOpen}
handleMobileMenuClose={handleMobileLeftMenuClose}
handleProfileLeftMenuOpen={handleProfileLeftMenuOpen}
align="left"
entries={entries}
/>
);
}
export {
RenderLeftMenu,
RenderLeftMobileMenu,
}
const RenderLeftMenu = ({
leftMenuId,
leftAnchorEl,
isLeftMenuOpen,
handleLeftMenuClose,
}) => {
let entries = [
{
action: () => { console.log('todo') },
content: "TODO",
},
{
action: () => { console.log('todo') },
content: "TODO2",
},
];
return (
<RenderMenu
menuId={leftMenuId}
anchorEl={leftAnchorEl}
isMenuOpen={isLeftMenuOpen}
handleMenuClose={handleLeftMenuClose}
align="left"
entries={entries}
/>
);
}
const RenderLeftMobileMenu = ({
mobileLeftMenuId,
mobileMoreLeftAnchorEl,
isMobileLeftMenuOpen,
handleMobileLeftMenuClose,
handleProfileLeftMenuOpen,
}) => {
let entries = [
{
action: () => { console.log('todo') },
content: "TODO mob",
},
{
action: () => { console.log('todo') },
content: "TODO mob2",
},
];
return (
<RenderMobileMenu
mobileMenuId={mobileLeftMenuId}
mobileMoreAnchorEl={mobileMoreLeftAnchorEl}
isMobileMenuOpen={isMobileLeftMenuOpen}
handleMobileMenuClose={handleMobileLeftMenuClose}
handleProfileLeftMenuOpen={handleProfileLeftMenuOpen}
align="left"
entries={entries}
/>
);
}
export {
RenderLeftMenu,
RenderLeftMobileMenu,
}
\ No newline at end of file
......@@ -9,30 +9,30 @@ import { RenderMenu, RenderMobileMenu } from './_Menu';
import Langs from './Langs';
const mapStateToProps = (state) => {
if(! state.init.env) return {};
if (!state.init.env) return {};
return {
tr: state.tr,
}
};
const LRenderRightMenu = ({
tr,
rightMenuId,
rightAnchorEl,
isRightMenuOpen,
handleRightMenuClose,
}) => {
tr,
rightMenuId,
rightAnchorEl,
isRightMenuOpen,
handleRightMenuClose,
}) => {
let entries = [
{
action: () => {console.log('todo')},
action: () => { console.log('todo') },
content: "TODO",
},
{
action: () => {console.log('todo')},
action: () => { console.log('todo') },
content: "TODO2",
},
{
action: () => {},
action: () => { },
content: Langs,
},
];
......@@ -50,20 +50,20 @@ const LRenderRightMenu = ({
}
const LRenderRightMobileMenu = ({
tr,
mobileRightMenuId,
mobileMoreRightAnchorEl,
isMobileRightMenuOpen,
handleMobileRightMenuClose,
handleProfileRightMenuOpen,
}) => {
tr,
mobileRightMenuId,
mobileMoreRightAnchorEl,
isMobileRightMenuOpen,
handleMobileRightMenuClose,
handleProfileRightMenuOpen,
}) => {
let entries = [
{
action: () => {console.log('todo')},
action: () => { console.log('todo') },
content: "TODO mob",
},
{
action: () => {console.log('todo')},
action: () => { console.log('todo') },
content: "TODO mob2",
},