2024-04-25 16:01:08: merge [main:7f9a52684105c7ff0a068812245c462ceb6d553e];
This commit is contained in:
1 parent
5a5f104174
commit
a31c44eb7b
121 files changed
+14802
-84
No files matched your search
@@ -0,0 +1,5 @@
|
||||
.access-list-tree{
|
||||
overflow-y: scroll;
|
||||
height: calc(100vh - 130px);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TreeProps } from 'antd'
|
||||
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
|
||||
|
||||
export interface AccessListTreePropsType {
|
||||
searchValue: string
|
||||
defaultAllRoutes: Record<string, EndpointType[]>
|
||||
methods: AccessListMethodType[]
|
||||
onCheck: TreeProps['onCheck']
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { WarningOutlined } from '@ant-design/icons'
|
||||
import { Tag, Tree, TreeProps } from 'antd'
|
||||
import { FC, memo, useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { AccessListTreePropsType } from '@widgets/AccessListTree/access-list-tree.type.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import { EndpointType } from '@type/accessList.type.ts'
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
import './access-list-tree.scss'
|
||||
|
||||
|
||||
const unknownMethodKey = 'неизвестные методы'
|
||||
|
||||
const AccessListTree: FC<AccessListTreePropsType> = ({
|
||||
searchValue,
|
||||
defaultAllRoutes,
|
||||
methods,
|
||||
onCheck = []
|
||||
}) => {
|
||||
const { hasPermission } = useRole()
|
||||
const [checkedKeys, setCheckedKeys] = useState<string[]>([])
|
||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([])
|
||||
|
||||
const createTreeData = (data: Record<string, EndpointType[]>) => {
|
||||
return Object.keys(data)
|
||||
.sort()
|
||||
.map((routeKey) => {
|
||||
if (routeKey === unknownMethodKey) {
|
||||
return {
|
||||
title: (
|
||||
<span className="unknown-label">
|
||||
{routeKey} <WarningOutlined />
|
||||
</span>
|
||||
),
|
||||
key: routeKey,
|
||||
children: data[routeKey].map((route) => createTreeNode(route, true))
|
||||
}
|
||||
}
|
||||
return {
|
||||
title: routeKey,
|
||||
key: routeKey,
|
||||
children: data[routeKey].map((route) => createTreeNode(route))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const createTreeNode = useCallback((obj: EndpointType, unknown = false) => {
|
||||
return {
|
||||
title: (
|
||||
<span className={`${unknown ? 'unknown-label' : ''}`}>
|
||||
{obj.path}
|
||||
{obj.inner ? (
|
||||
<Tag color="processing" bordered={false}>
|
||||
Внутренний
|
||||
</Tag>
|
||||
) : null}
|
||||
</span>
|
||||
),
|
||||
key: obj.path
|
||||
}
|
||||
}, [])
|
||||
|
||||
const filteredRoute = () => {
|
||||
if (!searchValue) {
|
||||
return defaultAllRoutes
|
||||
}
|
||||
const filteredRoute: Record<string, EndpointType[]> = {}
|
||||
Object.keys(defaultAllRoutes).forEach((groupName) => {
|
||||
const filterArray = defaultAllRoutes[groupName].filter(({ path }) =>
|
||||
path.toLowerCase().includes(searchValue)
|
||||
)
|
||||
if (filterArray.length) {
|
||||
filteredRoute[groupName] = filterArray
|
||||
}
|
||||
})
|
||||
return filteredRoute
|
||||
}
|
||||
|
||||
const treeData = createTreeData(filteredRoute())
|
||||
|
||||
const filteredCheckedKeys = () => {
|
||||
const isStringPresent = (string: string) => {
|
||||
for (const service of treeData) {
|
||||
for (const endpoint of service.children) {
|
||||
if (endpoint.key === string) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return checkedKeys.filter((string) => isStringPresent(string))
|
||||
}
|
||||
|
||||
const filteredKeys = filteredCheckedKeys()
|
||||
|
||||
useEffect(() => {
|
||||
const checkedKeys = new Set<string>()
|
||||
methods.forEach(({ method, value }) => {
|
||||
if (value) {
|
||||
checkedKeys.add(method)
|
||||
}
|
||||
})
|
||||
|
||||
const arrayCheckedKeys = Array.from(checkedKeys)
|
||||
setCheckedKeys(arrayCheckedKeys)
|
||||
}, [methods])
|
||||
|
||||
useEffect(() => {
|
||||
if (!searchValue) {
|
||||
setExpandedKeys([])
|
||||
return
|
||||
}
|
||||
const keys = Object.values(treeData).map((node) => node.key)
|
||||
setExpandedKeys(keys)
|
||||
}, [searchValue, defaultAllRoutes])
|
||||
|
||||
return (
|
||||
<div className="access-list-tree">
|
||||
<Tree
|
||||
className="app-access-content__main__tree"
|
||||
checkable={hasPermission(PermissionKeysType.write)}
|
||||
checkedKeys={filteredKeys}
|
||||
expandedKeys={expandedKeys}
|
||||
onExpand={(keys) => setExpandedKeys(keys as string[])}
|
||||
onCheck={onCheck as TreeProps['onCheck']}
|
||||
treeData={treeData}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default memo(AccessListTree)
|
||||
@@ -0,0 +1,8 @@
|
||||
@import "../../constants/style/styleConst";
|
||||
|
||||
.agreement-modal {
|
||||
&__description {
|
||||
display: inline-block;
|
||||
margin-bottom: $basic-margin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { ModalProps } from 'antd'
|
||||
|
||||
export type AgreementModalPropsType = ModalProps & {
|
||||
description: string
|
||||
showTextArea?: boolean
|
||||
onConfirm: (message: string) => void
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Input, Modal } from 'antd'
|
||||
import { ChangeEvent, useState } from 'react'
|
||||
|
||||
import { AgreementModalPropsType } from '@widgets/AgreementModal/agreement-modal.type.ts'
|
||||
|
||||
import './agreement-modal.scss'
|
||||
|
||||
const { TextArea } = Input
|
||||
|
||||
const AgreementModal = ({
|
||||
description,
|
||||
onConfirm,
|
||||
showTextArea = true,
|
||||
...rest
|
||||
}: AgreementModalPropsType) => {
|
||||
const [message, setMessage] = useState('')
|
||||
|
||||
const handleOnChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
setMessage(e.target.value)
|
||||
}
|
||||
|
||||
const handleOnOk = () => {
|
||||
onConfirm(message)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
okText="Отправить"
|
||||
className="agreement-modal"
|
||||
onOk={handleOnOk}
|
||||
{...rest}
|
||||
>
|
||||
<span
|
||||
data-cy="agreement-modal__description"
|
||||
className="agreement-modal__description"
|
||||
>
|
||||
{description}
|
||||
</span>
|
||||
{showTextArea && (
|
||||
<TextArea
|
||||
data-cy="agreement-modal__text-area"
|
||||
className="agreement-modal__text-area"
|
||||
value={message}
|
||||
onChange={handleOnChange}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default AgreementModal
|
||||
@@ -0,0 +1,17 @@
|
||||
import { List, Tooltip } from 'antd'
|
||||
import { FC } from 'react'
|
||||
|
||||
import { ListItemProps } from '@widgets/ListItem/list-item.type.ts'
|
||||
|
||||
|
||||
const ListItem: FC<ListItemProps> = ({ item }) => {
|
||||
return (
|
||||
<List.Item>
|
||||
<Tooltip mouseEnterDelay={1} title={item.name}>
|
||||
<List.Item.Meta title={item.name} />
|
||||
</Tooltip>
|
||||
</List.Item>
|
||||
)
|
||||
}
|
||||
|
||||
export default ListItem
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
|
||||
export interface ListItemProps {
|
||||
item: ColumnItem<any>
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { Button } from 'antd'
|
||||
import { useEffect } from 'react'
|
||||
import CloseBtn from 'src/ui/CloseBtn'
|
||||
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
|
||||
import './modal.scss'
|
||||
|
||||
|
||||
const Modal = ({
|
||||
open,
|
||||
onOk = () => {},
|
||||
footer,
|
||||
title,
|
||||
children,
|
||||
onClose = () => {}
|
||||
}: ModalPropsType) => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
onClose()
|
||||
document.body.classList.remove('modal-open')
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
document.addEventListener('keydown', handleKeyDown)
|
||||
|
||||
if (open) {
|
||||
document.body.classList.add('modal-open')
|
||||
}
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
if (!open) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="modal" onClick={closeModal}>
|
||||
<div className="modal__wrap" onClick={(event) => event.stopPropagation()}>
|
||||
<h1 className="modal__title">{title}</h1>
|
||||
<div className="modal__content">{children}</div>
|
||||
{footer && (
|
||||
<div className="modal__footer">
|
||||
<Button type="default" onClick={closeModal}>
|
||||
{footer.onCanselText}
|
||||
</Button>
|
||||
<Button type="primary" onClick={onOk}>
|
||||
{footer.onOkText}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<CloseBtn onClick={closeModal} ariaLabel="close" />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default Modal
|
||||
@@ -0,0 +1,64 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background-color: rgba(211, 211, 211, 0.8);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 100;
|
||||
&__wrap {
|
||||
min-width: 310px;
|
||||
min-height: 170px;
|
||||
max-height: 90vh;
|
||||
max-width: 90%;
|
||||
background: white;
|
||||
color: white;
|
||||
z-index: 10;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.04);
|
||||
position: relative;
|
||||
padding: $basic-padding * 1.5;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
&__header {
|
||||
height: 50px;
|
||||
background: white;
|
||||
overflow: hidden;
|
||||
border-top-left-radius: 16px;
|
||||
border-top-right-radius: 16px;
|
||||
}
|
||||
&__title {
|
||||
color: $grey;
|
||||
}
|
||||
&__content {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
color: #2c3e50;
|
||||
overflow: auto;
|
||||
}
|
||||
&__footer {
|
||||
display: flex;
|
||||
justify-content: end;
|
||||
margin-top: $basic-margin;
|
||||
button:first-child {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
body.modal-open {
|
||||
overflow: hidden;
|
||||
padding-right: 14px;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ReactNode } from 'react'
|
||||
|
||||
export interface ModalPropsType {
|
||||
open: boolean
|
||||
onOk?: () => void
|
||||
onClose?: () => void
|
||||
title: string
|
||||
children: ReactNode
|
||||
footer?: { onOkText: string; onCanselText: string }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Descriptions } from 'antd'
|
||||
import { FC } from 'react'
|
||||
|
||||
import { PermissionListProps } from './permisiion-list.type.ts'
|
||||
|
||||
import './permission-list.scss'
|
||||
|
||||
|
||||
const PermissionList: FC<PermissionListProps> = ({ permissions }) => {
|
||||
return (
|
||||
<Descriptions layout="vertical" className="permission-list">
|
||||
<Descriptions.Item
|
||||
label="Список разрешений"
|
||||
>
|
||||
<ul>
|
||||
{permissions.map((permission, index) => {
|
||||
return <li key={`${permission}-${index}`}>{permission}</li>
|
||||
})}
|
||||
</ul>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)
|
||||
}
|
||||
|
||||
export default PermissionList
|
||||
@@ -0,0 +1,3 @@
|
||||
export type PermissionListProps = {
|
||||
permissions:string[];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.permission-list {
|
||||
.ant-descriptions-item-label {
|
||||
font-size: $text-size-header2;
|
||||
}
|
||||
|
||||
ul, li {
|
||||
list-style-position: inside
|
||||
}
|
||||
|
||||
li {
|
||||
font-size: $text-size;
|
||||
margin-bottom: $basic-margin * 1.5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { FC } from 'react'
|
||||
|
||||
import { SelectedAccessMethodPropsType } from '@widgets/SelectedAccessMethod/selected-access-method.type.ts'
|
||||
|
||||
import { AccessListMethodType } from '@type/accessList.type.ts'
|
||||
|
||||
import './selected-access-method.scss'
|
||||
|
||||
|
||||
const SelectedAccessMethod: FC<SelectedAccessMethodPropsType> = ({
|
||||
unknownMethodKey,
|
||||
allRoutes,
|
||||
methods
|
||||
}) => {
|
||||
const checkIsUnknownMethod = (method: string) => {
|
||||
const routes = allRoutes[unknownMethodKey] || []
|
||||
return routes.find((route) => route.path === method)
|
||||
}
|
||||
|
||||
const renderMethodList = () => {
|
||||
const knownMethods: AccessListMethodType[] = []
|
||||
const unknownMethods: AccessListMethodType[] = []
|
||||
const sortAlphabetically = (a: AccessListMethodType, b: AccessListMethodType) =>
|
||||
a.method.localeCompare(b.method)
|
||||
methods.forEach((method) => {
|
||||
const isUnknown = checkIsUnknownMethod(method.method)
|
||||
if (isUnknown) {
|
||||
unknownMethods.push(method)
|
||||
} else {
|
||||
knownMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
const mergedMethods = [
|
||||
...knownMethods.sort(sortAlphabetically),
|
||||
...unknownMethods.sort(sortAlphabetically)
|
||||
]
|
||||
const allMethodsDisabled = mergedMethods.every((method) => !method.value)
|
||||
|
||||
if (allMethodsDisabled) {
|
||||
return <h3>Нет разрешенных методов</h3>
|
||||
}
|
||||
return mergedMethods.map((method) => {
|
||||
if (!method.value) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<span
|
||||
className={`${checkIsUnknownMethod(method.method) ? 'unknown-label' : ''}`}
|
||||
key={method.method}
|
||||
>
|
||||
{method.method}
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return <div className="selected-access-method">{renderMethodList()}</div>
|
||||
}
|
||||
|
||||
export default SelectedAccessMethod
|
||||
@@ -0,0 +1,13 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.selected-access-method {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: $basic-margin;
|
||||
padding: $basic-padding;
|
||||
border: 1px dashed $grey;
|
||||
|
||||
overflow-y: scroll;
|
||||
height: calc(100vh - 130px);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { AccessListMethodType, EndpointType } from '@type/accessList.type.ts'
|
||||
|
||||
export interface SelectedAccessMethodPropsType {
|
||||
unknownMethodKey: string
|
||||
methods: AccessListMethodType[]
|
||||
allRoutes: Record<string, EndpointType[]>
|
||||
}
|
||||
Reference in new issue
Block a user