MSP-3107 create SelectedAccessMethod
This commit is contained in:
1 parent
f5e0251286
commit
41d2735bb7
3 files changed
+81
No files matched your search
@@ -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