Skip to content

Commit

Permalink
Merge pull request #96 from stefanak-michal/92-remember-tabs-setting
Browse files Browse the repository at this point in the history
added option in settings to disable remembering open tabs
  • Loading branch information
stefanak-michal authored May 31, 2024
2 parents f4a6925 + 6497f2a commit ab41bf1
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 20 deletions.
Binary file modified e2e/neo4j-read/index.spec.ts-snapshots/Dark-mode-Load-page-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/neo4j-read/index.spec.ts-snapshots/Dark-mode-Load-page-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions e2e/neo4j-read/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ test.describe('Settings', { tag: '@neo4j-read' }, () => {
await checkActiveTab(page, '*');
});

test('Remember open tabs', async ({ page }) => {
await changeSettingAndClose(page, 'Remember open tabs');
// open some tab
await switchToTab(page, 'Start');
await containerLocator(page).getByRole('button', { name: '*' }).first().click();
await checkActiveTab(page, '*');
// click on log out button should stay at login page
await page.getByRole('button', { name: 'Log out' }).click();
await expect(page.locator('form#login')).toHaveCount(1);
// login again
await page.getByLabel('URL').fill(process.env.DB_HOSTNAME || 'bolt://localhost:7687');
await page.getByLabel('Username').fill(process.env.DB_USERNAME || '');
await page.getByLabel('Password').fill(process.env.DB_PASSWORD || '');
await page.getByRole('button', { name: 'Login' }).click();
await expect(page.getByLabel('main navigation')).toHaveCount(1);
// check amount of open tabs
await expect(page.locator('.tabs li')).toHaveCount(1);
});

test.describe('Change resolution', () => {
test.use({ viewport: { width: 1280, height: 800 } });

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class App extends React.Component<object, IAppState> {
};

componentDidMount() {
if (this.state.darkMode) document.documentElement.className = 'theme-dark';
document.documentElement.className = this.state.darkMode ? 'theme-dark' : 'theme-light';
}

handleLogin = () => {
Expand All @@ -42,7 +42,7 @@ class App extends React.Component<object, IAppState> {
},
() => {
setSetting('darkMode', this.state.darkMode);
document.documentElement.className = this.state.darkMode ? 'theme-dark' : '';
document.documentElement.className = this.state.darkMode ? 'theme-dark' : 'theme-light';
}
);
};
Expand Down
24 changes: 13 additions & 11 deletions src/Logged.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Logged extends React.Component<ILoggedProps, ILoggedState> {
constructor(props) {
super(props);

if (!settings().rememberOpenTabs) localStorage.removeItem('tabs');
const tabs = localStorage.getItem('tabs');
if (tabs) {
const parsed = JSON.parse(tabs);
Expand Down Expand Up @@ -182,7 +183,7 @@ class Logged extends React.Component<ILoggedProps, ILoggedState> {
contents: state.contents,
activeTab: active || !state.activeTab ? id : state.activeTab,
};
localStorage.setItem('tabs', JSON.stringify(obj));
if (settings().rememberOpenTabs) localStorage.setItem('tabs', JSON.stringify(obj));
return obj;
});

Expand Down Expand Up @@ -212,7 +213,7 @@ class Logged extends React.Component<ILoggedProps, ILoggedState> {
contents: state.contents.filter(content => id !== content.id),
activeTab: active,
};
localStorage.setItem('tabs', JSON.stringify(obj));
if (settings().rememberOpenTabs) localStorage.setItem('tabs', JSON.stringify(obj));
return obj;
});
},
Expand All @@ -224,7 +225,7 @@ class Logged extends React.Component<ILoggedProps, ILoggedState> {
contents: state.contents.filter(content => content.id === 'Start'),
activeTab: 'Start',
};
localStorage.setItem('tabs', JSON.stringify(obj));
if (settings().rememberOpenTabs) localStorage.setItem('tabs', JSON.stringify(obj));
return obj;
});
},
Expand All @@ -240,14 +241,15 @@ class Logged extends React.Component<ILoggedProps, ILoggedState> {
},
setActive: (id: string) => {
this.setState(state => {
localStorage.setItem(
'tabs',
JSON.stringify({
tabs: state.tabs,
contents: state.contents,
activeTab: id,
})
);
if (settings().rememberOpenTabs)
localStorage.setItem(
'tabs',
JSON.stringify({
tabs: state.tabs,
contents: state.contents,
activeTab: id,
})
);
return {
activeTab: id,
};
Expand Down
2 changes: 1 addition & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Db {
};

query = (stmt: string, params: object = {}, db: string = undefined): Promise<QueryResult> => {
mixpanel.track('Executed query');
if (typeof process === 'undefined') mixpanel.track('Executed query');
return new Promise((resolve, reject) => {
this._driver
.executeQuery(stmt, params, { database: db })
Expand Down
14 changes: 8 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import * as ReactDOM from 'react-dom/client';
import App from './App';
import mixpanel from 'mixpanel-browser';

mixpanel.init('b79f8e7c618e117cb8648076ffde5154', {
api_host: 'https://api-eu.mixpanel.com',
track_pageview: true,
persistence: 'localStorage',
secure_cookie: true,
});
if (typeof process === 'undefined') {
mixpanel.init('b79f8e7c618e117cb8648076ffde5154', {
api_host: 'https://api-eu.mixpanel.com',
track_pageview: true,
persistence: 'localStorage',
secure_cookie: true,
});
}

const root = ReactDOM.createRoot(document.getElementById('root') as Element);
root.render(
Expand Down
11 changes: 11 additions & 0 deletions src/layout/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ class Settings extends React.Component<{ handleClose: () => void }, ISettingsSta
)}
</ThemeSwitchContext.Consumer>
</div>
<div className='mb-3'>
<Checkbox
name='rememberOpenTabs'
onChange={this.handleChange}
label='Remember open tabs'
checked={this.state.settings.rememberOpenTabs}
color='is-link'
help='After successful login app will try open remembered tabs.'
/>
</div>
<div className='field'>
<label className='label'>Method when printing out temporal values</label>
<div className='control'>
Expand Down Expand Up @@ -120,6 +130,7 @@ export function settings(): ISettings {
temporalValueToStringFunction: 'toString',
darkMode: window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches,
confirmCloseUnsavedChanges: true,
rememberOpenTabs: true,
...(localStorage.getItem('settings') ? JSON.parse(localStorage.getItem('settings')) : {}),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ISettings {
temporalValueToStringFunction: string;
darkMode: boolean;
confirmCloseUnsavedChanges: boolean;
rememberOpenTabs: boolean;
}

export interface IStashManager {
Expand Down

0 comments on commit ab41bf1

Please sign in to comment.