nocobase/packages/core/client/src/user/CurrentUser.tsx
katherinehhh ba94dfaf6c
Feat/collection inherits (#1097)
* chore: test

* chore: inherited-collection class

* feat: collection inherit

* feat: collection inherit

* feat: inhertis sync runner

* test: get parents fields

* feat: collection inherit style promote

* feat: sync

* feat: sync alter table

* feat: pgOnly Test

* fix: child collection create api

* feat: replace parent field

* chore: reload parent fields

* test: reload collection test

* feat: details are displayed according to conditions

* fix: typo

* feat: inheritance map class

* chore: is parent node

* feat: display where child row created from

* fix: find with appends

* feat: add parent collection fields

* fix: create table

* feat: load fields for all children

* refactor: sync fields from parent

* test: has one field inhertis

* feat: replace child association target

* feat: should not replace child field when parent field update

* test: should update inherit field when parent field update

* feat: only the blocks directly inherited from the current data are displayed

* fix: inherit from multiple collections

* feat: only the blocks directly inherited from the current data are displayed

* fix: test

* feat: parent collection expend

* fix: test

* test: belongsToMany inherits

* test: belongsToMany inherits

* feat: block display

* feat: collection inherite

* feat: collection inherite

* feat: multiple inherits

* fix: sync runner

* feat: collection inherite

* feat: collecton inherits

* feat: cannot be modified after inheritance and saving

* feat: collection inherit for graph

* feat: collection inherits

* fix: drop inhertied field

* fix: should throw error when type conflit

* feat: output inherited fields

* feat: bulk update collection fields

* feat: collection fields

* feat: collection fields

* test: create relation with child table

* fix: test

* fix: test

* fix: test

* feat: style impove

* test: should not replace field with difference type

* feat: add text

* fix: throw error when replace field with difference type

* feat: overriding

* feat: kan bankanban group fields

* feat: calendar block fields

* feat: kan bankanban group fields

* fix: test

* feat: relationship fields

* feat: should delete child's field when parent field deleted

* feat: foreign key filter

* fix: build error & multiple inherit destory field

* fix: test

* chore: disable error

* feat: no recursive update associations (#1091)

* feat: update associations

* fix(collection-manager): should update uiSchema

* chore: flip if

* feat: mutile inherits

* feat: db dialect

* feat: inherits show by database

* chore: git hash into docker image

* fix: js gzip

* fix: dockerfile

* chore: error message

* feat: overriding

* feat: overriding

* feat: overriding

* feat: local

* feat: filter fields by interface

* fix: database logging env

* test: replace hasOne target

* feat: add view

* feat: local

* feat: enableInherits

* chore: error message

* feat: enableInherits

* feat: code optimization

* feat: code optimization

* feat: code optimization

Co-authored-by: chareice <chareice@live.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2022-11-17 12:49:13 +08:00

69 lines
2.2 KiB
TypeScript

import { Dropdown, Menu } from 'antd';
import React, { createContext, useState, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { useAPIClient, useCurrentUserContext } from '..';
import { useRequest } from '../api-client';
import { ChangePassword } from './ChangePassword';
import { EditProfile } from './EditProfile';
import { LanguageSettings } from './LanguageSettings';
import { SwitchRole } from './SwitchRole';
import {useCurrentAppInfo} from '../appInfo/CurrentAppInfoProvider'
const ApplicationVersion = () => {
const data=useCurrentAppInfo();
return (
<Menu.Item key="version" disabled>
Version {data?.data?.version}
</Menu.Item>
);
};
export const DropdownVisibleContext = createContext(null);
export const CurrentUser = () => {
const history = useHistory();
const api = useAPIClient();
const { t } = useTranslation();
const [visible, setVisible] = useState(false);
const { data } = useCurrentUserContext();
return (
<div style={{ display: 'inline-block', verticalAlign: 'top' }}>
<DropdownVisibleContext.Provider value={{ visible, setVisible }}>
<Dropdown
visible={visible}
onVisibleChange={(visible) => {
setVisible(visible);
}}
overlay={
<Menu>
<ApplicationVersion />
<Menu.Divider />
<EditProfile />
<ChangePassword />
<SwitchRole />
<LanguageSettings />
<Menu.Divider />
<Menu.Item
key="signout"
onClick={async () => {
await api.resource('users').signout();
api.auth.setToken(null);
history.push('/signin');
}}
>
{t('Sign out')}
</Menu.Item>
</Menu>
}
>
<span style={{ cursor: 'pointer', border: 0, padding: '16px', color: 'rgba(255, 255, 255, 0.65)' }}>
{data?.data?.nickname || data?.data?.email}
</span>
</Dropdown>
</DropdownVisibleContext.Provider>
</div>
);
};