-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#726: added option to turn off header editor
- Loading branch information
1 parent
a6c3aa7
commit 8e773a2
Showing
29 changed files
with
215 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
frontend/static/__tests__/dtale/menu/HideHeaderEditor-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { act, fireEvent, render } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { Store } from 'redux'; | ||
|
||
import HideHeaderEditor from '../../../dtale/menu/HideHeaderEditor'; | ||
import * as serverState from '../../../dtale/serverStateManagement'; | ||
import reduxUtils from '../../redux-test-utils'; | ||
import { buildInnerHTML } from '../../test-utils'; | ||
|
||
describe('HideHeaderEditor tests', () => { | ||
let result: Element; | ||
let store: Store; | ||
let updateSettingsSpy: jest.SpyInstance; | ||
|
||
const setupOption = async (settings = ''): Promise<void> => { | ||
store = reduxUtils.createDtaleStore(); | ||
buildInnerHTML({ settings }, store); | ||
result = await act(() => { | ||
return render( | ||
<Provider store={store}> | ||
<HideHeaderEditor />, | ||
</Provider>, | ||
{ | ||
container: document.getElementById('content') ?? undefined, | ||
}, | ||
).container; | ||
}); | ||
}; | ||
|
||
beforeEach(() => { | ||
updateSettingsSpy = jest.spyOn(serverState, 'updateSettings'); | ||
updateSettingsSpy.mockImplementation(() => undefined); | ||
}); | ||
|
||
afterEach(jest.resetAllMocks); | ||
|
||
afterAll(jest.restoreAllMocks); | ||
|
||
it('renders successfully with defaults', async () => { | ||
await setupOption(); | ||
expect(result.getElementsByClassName('ico-check-box-outline-blank')).toHaveLength(1); | ||
}); | ||
|
||
it('renders successfully with specified value', async () => { | ||
await setupOption('{"hide_header_editor":"True"}'); | ||
expect(result.getElementsByClassName('ico-check-box')).toHaveLength(1); | ||
}); | ||
|
||
it('handles changes to checkbox', async () => { | ||
await setupOption(); | ||
await act(async () => { | ||
await fireEvent.click(result.getElementsByClassName('ico-check-box-outline-blank')[0]); | ||
}); | ||
expect(updateSettingsSpy).toBeCalledTimes(1); | ||
expect(store.getState().settings).toEqual(expect.objectContaining({ hide_header_editor: true })); | ||
await act(async () => { | ||
await fireEvent.click(result.getElementsByClassName('ico-check-box')[0]); | ||
}); | ||
expect(updateSettingsSpy).toBeCalledTimes(2); | ||
expect(updateSettingsSpy.mock.calls[1][0]).toEqual({ | ||
hide_header_editor: false, | ||
}); | ||
expect(store.getState().settings).toEqual(expect.objectContaining({ hide_header_editor: false })); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import { withTranslation, WithTranslation } from 'react-i18next'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { AnyAction } from 'redux'; | ||
|
||
import { ActionType } from '../../redux/actions/AppActions'; | ||
import * as settingsActions from '../../redux/actions/settings'; | ||
import { AppState } from '../../redux/state/AppState'; | ||
import * as serverState from '../serverStateManagement'; | ||
|
||
import { MenuItem } from './MenuItem'; | ||
|
||
const HideHeaderEditor: React.FC<WithTranslation> = ({ t }) => { | ||
const { dataId, hideHeaderEditor } = useSelector((state: AppState) => ({ | ||
dataId: state.dataId, | ||
hideHeaderEditor: state.settings?.hide_header_editor ?? state.hideHeaderEditor, | ||
})); | ||
const dispatch = useDispatch(); | ||
|
||
const setHideHeaderEditor = async (): Promise<void> => { | ||
const updates = { hide_header_editor: !hideHeaderEditor }; | ||
await serverState.updateSettings(updates, dataId); | ||
dispatch(settingsActions.updateSettings(updates) as any as AnyAction); | ||
dispatch({ type: ActionType.UPDATE_HIDE_HEADER_EDITOR, value: !hideHeaderEditor }); | ||
dispatch({ type: ActionType.HIDE_RIBBON_MENU }); | ||
}; | ||
|
||
return ( | ||
<MenuItem | ||
className="hoverable" | ||
description={t('menu_description:hide_header_editor')} | ||
onClick={setHideHeaderEditor} | ||
> | ||
<span className="toggler-action"> | ||
<button className="btn btn-plain"> | ||
<i className={`ico-check-box${hideHeaderEditor ? '' : '-outline-blank'}`} style={{ marginTop: '-.25em' }} /> | ||
<span className="font-weight-bold" style={{ fontSize: '95%' }}> | ||
{t('Hide Header Editor', { ns: 'menu' })} | ||
</span> | ||
</button> | ||
</span> | ||
</MenuItem> | ||
); | ||
}; | ||
|
||
export default withTranslation(['menu', 'menu_description'])(HideHeaderEditor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.