-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CB-4436 update session only in touchSession #2377
Merged
alexander-skoblikov
merged 50 commits into
devel
from
CB-4346-session-doesnt-expire-after-30-min
Feb 23, 2024
Merged
Changes from 35 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
2ad767b
CB-4436 update session only in touchSession
alexander-skoblikov ba7ef88
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
a005e24
CB-4346 adds session touch for user actions
18d7576
CB-4346 adds core-activity package
69a8576
CB-4346 fix: mobx version core-activity package
203f756
CB-4346 ClientActivityService cleanup
1b83462
CB-4346 ClientActivityService cleanup [2]
7128689
CB-4346 fix: client activity function contexts bind
0ebffcb
CB-4346 useClientActivity cleanup
38a74e7
CB-4346 removed unneeded deps
0b4ed1e
CB-4346 session warning dialog props renaming
74d3fd1
CB-4364 adds client activity service setsActivity method
855fa61
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
4c87772
CB-4346 activity timers refactor
e830159
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
1eef3f9
CB-4346 adds min time for session expire setting
1d50f04
CB-4346 adds update client activity each 300ms
e27de12
CB-4346 touchSession logic moved to SessionExpiredService
0450ac5
СB-4346 session expire service uses session resource to touchSession
721a843
CB-4346 code cleanup
9137803
CB-4346 removed unused activity package from plugin session expiration
adba2d5
CB-4346 SessionExpireService - removed cycle dependency
06a98e7
CB-4346 code cleanup
cc8aa30
CB-4346 update session state if it is invalid
e58962d
CB-4346 removed arrow function from useClientActivity
9ad7025
Revert "CB-4346 SessionExpireService - removed cycle dependency"
dacd1de
CB-4346 touchSession logic moved from SessionExpiredService to Sessio…
d38bc06
CB-4346 chore: core-activity -> core-client-activity renaming
527cb27
CB-4346 chore: vars renaming
535ff87
CB-4346 refactor: removed force from sessionResource.touchSession()
51b3887
CB-4346 adds SessionTouchService
afa80c6
CB-4346 chore: SESSION_EXPIRE_MIN_TIME const new name
ad5367f
CB-4346 sessionTouchService license
7061cdb
CB-4346 uses SessionTouchService as Dependency
6dca65a
CB-4346 pr fixes
79c3700
CB-4346 adds core-localization to plugin-session-expiration
f124f5d
CB-4346 adds core coreClientActivityManifest to unit tests
01a403e
CB-4346 updates ts references
edc7593
CB-4436 new update session gql api
alexander-skoblikov b98ac74
CB-4346 adds updateSession API call
a823244
CB-4346 code cleanup sessionResource
93a1926
CB-4346 do not send state event for not authorized session
alexander-skoblikov ce827fe
CB-4346 chore: update session info with event
Wroud 4c990f3
CB-4346 adds update activity on touch (tablets, phones support)
9f1b2aa
CB-4346 add debug log
alexander-skoblikov f9919a1
grouping
2b8fac5
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
19e498f
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
EvgeniaBzzz 4069d98
CB-4346 force update session on create
alexander-skoblikov 81c0879
Merge branch 'devel' into CB-4346-session-doesnt-expire-after-30-min
EvgeniaBzzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { useEffect } from 'react'; | ||
|
||
import { ClientActivityService } from '@cloudbeaver/core-client-activity'; | ||
import { useService } from '@cloudbeaver/core-di'; | ||
import { throttle } from '@cloudbeaver/core-utils'; | ||
|
||
const UPDATE_THROTTLE = 300; | ||
|
||
export function useClientActivity() { | ||
const clientActivityService = useService(ClientActivityService); | ||
|
||
const updateActivity = throttle(function updateActivity() { | ||
clientActivityService.updateActivity(); | ||
}, UPDATE_THROTTLE); | ||
|
||
function subscribeEvents() { | ||
document.addEventListener('mousemove', updateActivity); | ||
document.addEventListener('click', updateActivity); | ||
document.addEventListener('keydown', updateActivity); | ||
document.addEventListener('scroll', updateActivity); | ||
} | ||
|
||
function unsubscribeEvents() { | ||
document.removeEventListener('mousemove', updateActivity); | ||
document.removeEventListener('click', updateActivity); | ||
document.removeEventListener('keydown', updateActivity); | ||
document.removeEventListener('scroll', updateActivity); | ||
} | ||
|
||
useEffect(() => { | ||
subscribeEvents(); | ||
|
||
return () => { | ||
unsubscribeEvents(); | ||
}; | ||
}, []); | ||
Check warning on line 43 in webapp/packages/core-app/src/useClientActivity.ts Jenkins-CI-integration / CheckStyle TypeScript Reportwebapp/packages/core-app/src/useClientActivity.ts#L43
|
||
} |
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,21 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/lib | ||
|
||
# misc | ||
.DS_Store | ||
.env* | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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,28 @@ | ||
{ | ||
"name": "@cloudbeaver/core-client-activity", | ||
"sideEffects": [ | ||
"src/**/*.css", | ||
"src/**/*.scss", | ||
"public/**/*" | ||
], | ||
"version": "0.1.0", | ||
"description": "", | ||
"license": "Apache-2.0", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc -b", | ||
"lint": "eslint ./src/ --ext .ts,.tsx", | ||
"lint-fix": "eslint ./src/ --ext .ts,.tsx --fix", | ||
"validate-dependencies": "core-cli-validate-dependencies", | ||
"update-ts-references": "rimraf --glob dist && typescript-resolve-references" | ||
}, | ||
"dependencies": { | ||
"@cloudbeaver/core-di": "~0.1.0", | ||
"@cloudbeaver/core-executor": "~0.1.0", | ||
"mobx": "^6.12.0" | ||
}, | ||
"peerDependencies": {}, | ||
"devDependencies": { | ||
"typescript": "^5.3.2" | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
webapp/packages/core-client-activity/src/ClientActivityService.ts
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,58 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { makeObservable, observable } from 'mobx'; | ||
|
||
import { injectable } from '@cloudbeaver/core-di'; | ||
import { Executor, IExecutor } from '@cloudbeaver/core-executor'; | ||
|
||
const INACTIVE_PERIOD_TIME = 1000 * 60; | ||
|
||
@injectable() | ||
export class ClientActivityService { | ||
private timer: ReturnType<typeof setTimeout> | null; | ||
public isActive: boolean; | ||
public onActiveStateChange: IExecutor<boolean>; | ||
|
||
constructor() { | ||
this.setActivity = this.setActivity.bind(this); | ||
this.updateActivity = this.updateActivity.bind(this); | ||
this.resetActivity = this.resetActivity.bind(this); | ||
|
||
this.timer = null; | ||
this.isActive = false; | ||
this.onActiveStateChange = new Executor(); | ||
|
||
makeObservable(this, { | ||
isActive: observable, | ||
}); | ||
} | ||
|
||
private setActivity(value: boolean) { | ||
this.isActive = value; | ||
this.onActiveStateChange.execute(value); | ||
} | ||
|
||
resetActivity() { | ||
this.setActivity(false); | ||
|
||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
this.timer = null; | ||
} | ||
} | ||
|
||
updateActivity() { | ||
this.setActivity(true); | ||
|
||
if (this.timer) { | ||
clearTimeout(this.timer); | ||
} | ||
|
||
this.timer = setTimeout(this.resetActivity, INACTIVE_PERIOD_TIME); | ||
} | ||
} |
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,2 @@ | ||
export * from './ClientActivityService'; | ||
export * from './manifest'; |
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,18 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import type { PluginManifest } from '@cloudbeaver/core-di'; | ||
|
||
import { ClientActivityService } from './ClientActivityService'; | ||
|
||
export const coreClientActivityManifest: PluginManifest = { | ||
info: { | ||
name: 'Core Client Activity', | ||
}, | ||
|
||
providers: [ClientActivityService], | ||
}; |
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,28 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo" | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../core-di/tsconfig.json" | ||
}, | ||
{ | ||
"path": "../core-executor/tsconfig.json" | ||
} | ||
], | ||
"include": [ | ||
"__custom_mocks__/**/*", | ||
"src/**/*", | ||
"src/**/*.json", | ||
"src/**/*.css", | ||
"src/**/*.scss" | ||
], | ||
"exclude": [ | ||
"**/node_modules", | ||
"lib/**/*", | ||
"dist/**/*" | ||
] | ||
} |
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,43 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2024 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { ClientActivityService } from '@cloudbeaver/core-client-activity'; | ||
import { Dependency, injectable } from '@cloudbeaver/core-di'; | ||
|
||
import { SessionResource } from './SessionResource'; | ||
|
||
export const SESSION_TOUCH_TIME_PERIOD = 1000 * 60; | ||
|
||
@injectable() | ||
export class SessionActivityService extends Dependency { | ||
private touchSessionTimer: ReturnType<typeof setTimeout> | null = null; | ||
|
||
constructor(private readonly clientActivityService: ClientActivityService, private readonly sessionResource: SessionResource) { | ||
super(); | ||
this.notifyClientActivity = this.notifyClientActivity.bind(this); | ||
this.clientActivityService.onActiveStateChange.addHandler(this.notifyClientActivity); | ||
} | ||
|
||
private async notifyClientActivity() { | ||
if (this.touchSessionTimer || !this.clientActivityService.isActive) { | ||
return; | ||
} | ||
|
||
try { | ||
await this.sessionResource.touchSession(); | ||
} catch (e) { | ||
console.error('Session touch error', e); | ||
} | ||
|
||
this.touchSessionTimer = setTimeout(() => { | ||
if (this.touchSessionTimer) { | ||
clearTimeout(this.touchSessionTimer); | ||
this.touchSessionTimer = null; | ||
} | ||
}, SESSION_TOUCH_TIME_PERIOD); | ||
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep naming for constants also (notifyClientActivity) |
||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is forbidden to import
notificationService
intocore-root
, so I logged it with this