Skip to content

Commit

Permalink
standard --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
runely committed May 25, 2022
1 parent e87faef commit 62e7ca4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 55 deletions.
12 changes: 6 additions & 6 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';
import { render, screen } from '@testing-library/react'
import App from './App'

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
render(<App />)
const linkElement = screen.getByText(/learn react/i)
expect(linkElement).toBeInTheDocument()
})
43 changes: 20 additions & 23 deletions src/components/ConfirmationDialog/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import { Button, Dialog, DialogActions, DialogBody, DialogTitle } from "@vtfk/components";
import { useCallback, useEffect, useRef } from "react";


export default function ConfirmationDialog({ open, title, children, okBtnText, okBtnDisabled, cancelBtnText, onClickOk, onClickCancel, onDismiss, ...props }) {
import { Button, Dialog, DialogActions, DialogBody, DialogTitle } from '@vtfk/components'
import { useCallback, useEffect, useRef } from 'react'

export default function ConfirmationDialog ({ open, title, children, okBtnText, okBtnDisabled, cancelBtnText, onClickOk, onClickCancel, onDismiss, ...props }) {
const handleOkClick = useCallback(() => {
if(onClickOk && typeof onClickOk === 'function') onClickOk();
if (onClickOk && typeof onClickOk === 'function') onClickOk()
}, [onClickOk])

const listenForEnter = useCallback((e) => {
try {
e.preventDefault();
e.stopPropagation();
e.preventDefault()
e.stopPropagation()
} catch {}

if(e.key === 'Enter') {
handleOkClick();
return;

if (e.key === 'Enter') {
handleOkClick()
}
},[handleOkClick])
}, [handleOkClick])

function handleCancelClick() {
if(onClickCancel && typeof onClickCancel === 'function') onClickCancel();
function handleCancelClick () {
if (onClickCancel && typeof onClickCancel === 'function') onClickCancel()
}

const dialogRef = useRef(undefined);
const dialogRef = useRef(undefined)

useEffect(() => {
if(open) {
dialogRef.current.focus();
document.removeEventListener('keydown', listenForEnter);
if (open) {
dialogRef.current.focus()
document.removeEventListener('keydown', listenForEnter)
document.addEventListener('keydown', listenForEnter)
} else {
document.removeEventListener('keydown', listenForEnter)
Expand All @@ -41,17 +38,17 @@ export default function ConfirmationDialog({ open, title, children, okBtnText, o
// eslint-disable-next-line
}, [listenForEnter])

return(
return (
<>
<div ref={dialogRef}>
<Dialog isOpen={open} onDismiss={() => { if (onDismiss && typeof onDismiss === 'function') onDismiss() }} {...props}>
{ title && <DialogTitle>{title}</DialogTitle>}
{title && <DialogTitle>{title}</DialogTitle>}
<DialogBody>
{children}
</DialogBody>
<DialogActions>
<Button disabled={okBtnDisabled} size="small" onClick={() => handleOkClick()}>{ okBtnText || 'Ok' }</Button>
<Button size="small" onClick={() => handleCancelClick()}>{ cancelBtnText || 'Lukk' }</Button>
<Button disabled={okBtnDisabled} size='small' onClick={() => handleOkClick()}>{okBtnText || 'Ok'}</Button>
<Button size='small' onClick={() => handleCancelClick()}>{cancelBtnText || 'Lukk'}</Button>
</DialogActions>
</Dialog>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAPI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function useAPI (defaultDatabase, defaultQueue = [], defaultItems
'X-API-KEY': API.TOKEN
}
}

const url = `${API.URL}/${database}?$top=${top}`
const { data } = await axios.get(url, options)
setQueue(data.data)
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import React from 'react'
import ReactDOM from 'react-dom'
import { BaseStyle } from '@vtfk/components'
import App from './App';
import App from './App'

import './assets/scss/base-styles.scss'

Expand All @@ -12,4 +12,4 @@ ReactDOM.render(
</BaseStyle>
</React.StrictMode>,
document.getElementById('root')
);
)
38 changes: 23 additions & 15 deletions src/pages/Queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function Queue () {
const getTitle = type => {
if (item.e18 === false) return `Can only ${type} a task handled by E18`
if (type === 'retry') return item.status !== 'failed' ? `Can't retry a ${item.status} task` : 'Retry'
if (type === 'suspend') return ['completed', 'retired'].includes(item.status) ? `Can't suspend a ${item.status} task` : item.status === 'suspended' ? 'Unsuspend': 'Suspend'
if (type === 'suspend') return ['completed', 'retired'].includes(item.status) ? `Can't suspend a ${item.status} task` : item.status === 'suspended' ? 'Unsuspend' : 'Suspend'
if (type === 'retire') return ['completed', 'retired'].includes(item.status) ? `Can't retire a ${item.status} task` : 'Retire'
return `OI 😱 (${type})`
}
Expand All @@ -39,23 +39,27 @@ export function Queue () {
icon='retry'
disabled={['completed', 'waiting', 'suspended', 'retired', 'running'].includes(item.status) || item.e18 === false}
onClick={() => setConfirmationItem({ action: 'retry', item, index, message: 'Status changed to retry' })}
title={getTitle('retry')} />
title={getTitle('retry')}
/>
<IconButton
icon={item.status === 'suspended' ? 'play' : 'pause'}
disabled={['completed', 'retired'].includes(item.status) || item.e18 === false}
onClick={() => setConfirmationItem({ action: item.status === 'suspended' ? 'unsuspended' : 'suspended', item, index, message: `Status changed to ${item.status === 'suspended' ? 'waiting' : 'suspended'}` })}
title={getTitle('suspend')} />
title={getTitle('suspend')}
/>
<IconButton
icon='close'
disabled={['completed', 'retired'].includes(item.status) || item.e18 === false}
onClick={() => setConfirmationItem({ action: 'retire', item, index, message: 'Status changed to retire' })}
title={getTitle('retire')} />
title={getTitle('retire')}
/>
{
view &&
<IconButton
icon='activity'
onClick={() => setDialogItemIndex(index)}
title='View' />
title='View'
/>
}
</div>
)
Expand Down Expand Up @@ -92,7 +96,7 @@ export function Queue () {
label: 'Created',
onClick: () => handleSortClick(['createdTimestamp']),
itemTooltip: 'createdAt',
itemRender: (value, item, header, index) => <div>{relativeDateFormat({ toDate: new Date(item.createdAt || item.createdTimestamp), locale: 'no', options: { } })}</div>
itemRender: (value, item, header, index) => <div>{relativeDateFormat({ toDate: new Date(item.createdAt || item.createdTimestamp), locale: 'no', options: { } })}</div>
},
{
label: 'Modified',
Expand Down Expand Up @@ -175,7 +179,7 @@ export function Queue () {
}

function handleStatsClick (item) {
let _types = [ ...types ]
let _types = [...types]

if (!mulitpleTypes) {
if (types.length === 1 && types[0] === item) {
Expand Down Expand Up @@ -216,7 +220,7 @@ export function Queue () {

return (
<DefaultLayout>

<div className='queue-stats'>
<StatisticsGroup className='stats-group'>
<StatisticsCard className={`${types.includes('completed') ? 'card-type-active' : ''}`} title='completed' onClick={() => handleStatsClick('completed')} value={completed} loading={loading} />
Expand All @@ -240,8 +244,9 @@ export function Queue () {
onPressEscape={() => setDialogItemIndex(-1)}
showCloseButton
height='80%'
width='50%'>
{
width='50%'
>
{
dialogItemIndex > -1 &&
<>
<DialogTitle isShowCloseButton style={{ color: `${getDialogTitleColor()}`, borderBottom: '1px solid black', paddingBottom: '10px' }}>
Expand Down Expand Up @@ -288,7 +293,7 @@ export function Queue () {
return (
<li key={index}><strong>{comment.user}</strong>: <i>{comment.message}</i></li>
)
})
})
}
</ul>
}
Expand All @@ -307,7 +312,8 @@ export function Queue () {
disabled={dialogItemIndex === 0}
icon='arrowLeft'
onClick={() => { setDialogItemIndex(dialogItemIndex - 1); console.log('Heyhey', dialogItemIndex - 1) }}
title='Forrige' />
title='Forrige'
/>
</div>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flex: 1 }}>
{
Expand All @@ -319,7 +325,8 @@ export function Queue () {
disabled={dialogItemIndex === (queueItems.length - 1)}
icon='arrowRight'
onClick={() => { setDialogItemIndex(dialogItemIndex + 1); console.log('Heyhey', dialogItemIndex + 1) }}
title='Neste' />
title='Neste'
/>
</div>
</div>
<div style={{ display: 'flex', flexDirection: 'row', width: '100%', justifyContent: 'center', height: '1.5em', paddingTop: '0.5em' }}>
Expand All @@ -328,7 +335,7 @@ export function Queue () {
</DialogActions>
</>
}
</Dialog>
</Dialog>
</div>

{
Expand All @@ -355,7 +362,8 @@ export function Queue () {
placeholder='Message / Reason'
rows={5}
onChange={e => { console.log(e.target.value); setConfirmationItem({ ...confirmationItem, message: e.target.value }) }}
value={confirmationItem.message} />
value={confirmationItem.message}
/>
</div>
</ConfirmationDialog>
}
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Statistics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const labelsMock = [
'Mars',
'April',
'Mai',
'Juni',
'Juni'
]

const options = {
Expand Down Expand Up @@ -160,28 +160,28 @@ export function Statistics () {
}
</div>
<div className='statistics'>
{
{
loading
? <div><h5>Tasks</h5><Skeleton height='400' width='800' /></div>
: <Bar options={options} data={tasksData} />
}
</div>
<div className='statistics'>
{
{
loading
? <Skeleton height='400' width='800' />
: <Line options={options} data={barDataMock} />
}
</div>
<div className='statistics'>
{
{
loading
? <Skeleton height='400' width='800' />
: <Doughnut data={doughnutData} />
}
</div>
<div className='statistics'>
{
{
loading
? <Skeleton height='400' width='800' />
: <Pie data={doughnutData} />
Expand Down
2 changes: 1 addition & 1 deletion src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import '@testing-library/jest-dom'

0 comments on commit 62e7ca4

Please sign in to comment.