-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* CB-5478 adds useAdministrationUserFormState with flexible id field * CB-5478 simplifies logic fork form state hooks --------- Co-authored-by: mr-anton-t <[email protected]>
- Loading branch information
1 parent
d2b6734
commit 6e575d3
Showing
2 changed files
with
30 additions
and
13 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
28 changes: 28 additions & 0 deletions
28
...tion-administration/src/Administration/Users/UsersTable/useAdministrationUserFormState.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,28 @@ | ||
/* | ||
* 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 { useRef } from 'react'; | ||
|
||
import { IServiceProvider, useService } from '@cloudbeaver/core-di'; | ||
|
||
import { AdministrationUserFormService } from '../UserForm/AdministrationUserFormService'; | ||
import { AdministrationUserFormState } from '../UserForm/AdministrationUserFormState'; | ||
|
||
export function useAdministrationUserFormState(id: string | null, configure?: (state: AdministrationUserFormState) => any) { | ||
const service = useService(AdministrationUserFormService); | ||
const serviceProvider = useService(IServiceProvider); | ||
const ref = useRef<null | AdministrationUserFormState>(null); | ||
|
||
if (ref.current?.id !== id) { | ||
ref.current = new AdministrationUserFormState(serviceProvider, service, { | ||
userId: id, | ||
}); | ||
configure?.(ref.current); | ||
} | ||
|
||
return ref.current; | ||
} |