Skip to content

Commit

Permalink
Merge branch 'devel' into CB-4896-migrate-to-jetty-12
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-anton-t authored Sep 16, 2024
2 parents bf22c80 + 6e575d3 commit c022488
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,17 @@
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import { useState } from 'react';

import { Container, Loader, s, TableItemExpandProps, useS } from '@cloudbeaver/core-blocks';
import { IServiceProvider, useService } from '@cloudbeaver/core-di';
import { FormMode } from '@cloudbeaver/core-ui';

import { AdministrationUserForm } from '../UserForm/AdministrationUserForm';
import { AdministrationUserFormService } from '../UserForm/AdministrationUserFormService';
import { AdministrationUserFormState } from '../UserForm/AdministrationUserFormState';
import { useAdministrationUserFormState } from './useAdministrationUserFormState';
import style from './UserEdit.module.css';

export const UserEdit = observer<TableItemExpandProps<string>>(function UserEdit({ item, onClose }) {
const styles = useS(style);
const administrationUserFormService = useService(AdministrationUserFormService);
const serviceProvider = useService(IServiceProvider);
const [state] = useState(() => {
const state = new AdministrationUserFormState(serviceProvider, administrationUserFormService, {
userId: item,
});
state.setMode(FormMode.Edit);
return state;
});
const state = useAdministrationUserFormState(item, state => state.setMode(FormMode.Edit));

return (
<Container className={s(styles, { box: true })} parent vertical>
Expand Down
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;
}

0 comments on commit c022488

Please sign in to comment.