MSP-3106 refactor applications page
This commit is contained in:
1 parent
aa6853211b
commit
67ee8aec3a
16 files changed
+1068
-527
No files matched your search
@@ -1,9 +1,11 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.applications-content {
|
||||
padding: $basic-padding *2 $basic-padding;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
.column-content {
|
||||
margin-left: $basic-margin;
|
||||
}
|
||||
&__add-btn {
|
||||
max-width: 240px;
|
||||
margin-left: auto;
|
||||
@@ -16,4 +18,10 @@
|
||||
display: flex;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.link-btn {
|
||||
color: $blue-color;
|
||||
&:hover {
|
||||
color: $text-color-blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,66 @@
|
||||
import {
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
PlusSquareOutlined
|
||||
} from '@ant-design/icons'
|
||||
import {Button, message, Spin, Table} from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { LinkOutlined } from '@ant-design/icons'
|
||||
import { List, message, Spin, Tooltip } from 'antd'
|
||||
import { FormComponents, Layout } from 'isp-ui-kit'
|
||||
import { FC, useState } from 'react'
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
import { Dispatch, FC, SetStateAction, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
|
||||
import Modal from '@widgets/Modal'
|
||||
|
||||
import CanEdit from '@components/CanEdit'
|
||||
import TokenContent from '@components/TokenContent'
|
||||
|
||||
import {
|
||||
ApplicationAppType,
|
||||
ApplicationsServiceType,
|
||||
ApplicationTokenType,
|
||||
NewApplicationAppType,
|
||||
NewApplicationTokenType,
|
||||
UpdateApplicationAppType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { setSearchValue, setSelectedItemId } from '@utils/columnLayoutUtils.ts'
|
||||
import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts'
|
||||
|
||||
import applicationsApi from '@services/applicationsService.ts'
|
||||
import tokensApi from '@services/tokensService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import './applications-content.scss'
|
||||
|
||||
const { FormInput, FormSelect } = FormComponents
|
||||
const { EmptyData } = Layout
|
||||
const { FormInput } = FormComponents
|
||||
const { EmptyData, Column, ContentColumn } = Layout
|
||||
|
||||
interface ApplicationsContentPropTypes {
|
||||
id: number
|
||||
selectedItemId: number
|
||||
currentApplicationsApp: number
|
||||
setCurrentApplicationsApp: Dispatch<SetStateAction<number>>
|
||||
}
|
||||
|
||||
const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
|
||||
const ApplicationsContent: FC<ApplicationsContentPropTypes> = ({
|
||||
selectedItemId,
|
||||
currentApplicationsApp,
|
||||
setCurrentApplicationsApp
|
||||
}) => {
|
||||
const { data: applications, isLoading: isLoadingApplicationsContent = [] } =
|
||||
applicationsApi.useGetApplicationsByServiceIdQuery(id)
|
||||
applicationsApi.useGetApplicationsByServiceIdQuery({
|
||||
id: selectedItemId
|
||||
})
|
||||
|
||||
const [createApplicationService] =
|
||||
applicationsApi.useCreateApplicationServiceMutation()
|
||||
applicationsApi.useCreateApplicationServiceMutation()
|
||||
const [updateApplication] =
|
||||
applicationsApi.useUpdateApplicationsServiceMutation()
|
||||
applicationsApi.useUpdateApplicationsServiceMutation()
|
||||
const [removeApplicationsService] =
|
||||
applicationsApi.useRemoveApplicationsServiceMutation()
|
||||
const [createToken] = tokensApi.useCreateTokenMutation()
|
||||
applicationsApi.useRemoveApplicationsServiceMutation()
|
||||
const [showApplicationsModal, setShowApplicationsModal] = useState({
|
||||
addModal: false,
|
||||
updateModal: false,
|
||||
addToken: false
|
||||
updateModal: false
|
||||
})
|
||||
const [currentApplicationsApp, setCurrentApplicationsApp] =
|
||||
useState<ApplicationAppType>()
|
||||
const [searchParams, setSearchParams] = useSearchParams('')
|
||||
const searchAppValue = searchParams.get('appSearch') || ''
|
||||
const navigate = useNavigate()
|
||||
const { appId } = useParams()
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
@@ -62,55 +69,53 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
|
||||
} = useForm<ApplicationAppType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const { handleSubmit: handleSubmitTokens, control: controlTokens } =
|
||||
useForm<ApplicationTokenType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const handleShowUpdateModalApplicationApp = (data: ApplicationAppType) => {
|
||||
const updateApplicationModal = () => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: true
|
||||
})
|
||||
setCurrentApplicationsApp(data)
|
||||
}
|
||||
const handleShowCreateModalApplicationApp = () => {
|
||||
const addApplicationModal = () => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: true
|
||||
})
|
||||
}
|
||||
const handleShowAddModalToken = (data: ApplicationAppType) => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addToken: true
|
||||
})
|
||||
setCurrentApplicationsApp(data)
|
||||
const renderTokenContent = () => {
|
||||
if (!currentApplicationsApp) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
return (
|
||||
<TokenContent key={currentApplicationsApp} id={currentApplicationsApp} />
|
||||
)
|
||||
}
|
||||
|
||||
const handleUpdateApplicationApp = (data: UpdateApplicationAppType) => {
|
||||
if (currentApplicationsApp) {
|
||||
const currentElement = applications?.filter(
|
||||
(el) => el.app.id === Number(appId)
|
||||
)[0].app
|
||||
if (currentElement) {
|
||||
const updateApplications: UpdateApplicationAppType = {
|
||||
id: currentApplicationsApp.id,
|
||||
id: currentElement.id,
|
||||
name: data.name,
|
||||
description: data.description
|
||||
? data.description
|
||||
: currentApplicationsApp.description,
|
||||
serviceId: id.id,
|
||||
? data.description
|
||||
: currentElement.description,
|
||||
serviceId: selectedItemId,
|
||||
type: 'SYSTEM'
|
||||
}
|
||||
updateApplication({ ...currentApplicationsApp, ...updateApplications })
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
reset()
|
||||
message.info('Элемент сохранен')
|
||||
updateApplication({ ...currentElement, ...updateApplications })
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
.catch(() => message.error('Ошибка обновления элемента'))
|
||||
reset()
|
||||
message.info('Элемент сохранен')
|
||||
})
|
||||
.catch(() => message.error('Ошибка обновления элемента'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,14 +123,14 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
|
||||
const newApplicationApp: NewApplicationAppType = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
serviceId: id.id,
|
||||
serviceId: selectedItemId,
|
||||
type: 'SYSTEM'
|
||||
}
|
||||
|
||||
createApplicationService(newApplicationApp)
|
||||
.unwrap()
|
||||
.then(message.info('Элемент сохранен'))
|
||||
.catch((e) => message.error(e))
|
||||
.unwrap()
|
||||
.then(message.info('Элемент сохранен'))
|
||||
.catch((e) => message.error(e))
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
@@ -133,227 +138,128 @@ const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
|
||||
reset()
|
||||
}
|
||||
const handleRemoveApplicationApp = (id: number) =>
|
||||
removeApplicationsService([id])
|
||||
.then(() => {
|
||||
message.info('Элемент удален')
|
||||
})
|
||||
.catch(message.error('Ошибка добавления элемента'))
|
||||
removeApplicationsService([id])
|
||||
.unwrap()
|
||||
.then(() => message.success('Элемент удален'))
|
||||
.catch(() => message.info('Ошибка удаления элемента'))
|
||||
|
||||
const handleCreateToken = (data: NewApplicationTokenType) => {
|
||||
if (currentApplicationsApp) {
|
||||
const newToken: NewApplicationTokenType = {
|
||||
expireTimeMs: data.expireTimeMs,
|
||||
appId: currentApplicationsApp.id
|
||||
}
|
||||
|
||||
createToken(newToken)
|
||||
.then(() => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addToken: false
|
||||
})
|
||||
reset()
|
||||
message.info('Элемент добавлен')
|
||||
})
|
||||
.catch(() => {
|
||||
message.error('Ошибка добавления элемента')
|
||||
})
|
||||
}
|
||||
const renderColumnItems = (item: ColumnItem<any>) => {
|
||||
return (
|
||||
<List.Item>
|
||||
<Tooltip mouseEnterDelay={1} title={item.name}>
|
||||
<List.Item.Meta title={item.name} />
|
||||
<div
|
||||
className="link-btn"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
navigate(`/appAccess/${item.id}`)
|
||||
}}
|
||||
>
|
||||
<LinkOutlined />
|
||||
</div>
|
||||
</Tooltip>
|
||||
</List.Item>
|
||||
)
|
||||
}
|
||||
|
||||
const columns: ColumnsType<ApplicationsServiceType> = [
|
||||
{
|
||||
title: 'id',
|
||||
dataIndex: ['app', 'id'],
|
||||
key: 'id'
|
||||
},
|
||||
{
|
||||
title: 'Наименование',
|
||||
dataIndex: ['app', 'name'],
|
||||
key: 'name'
|
||||
},
|
||||
{
|
||||
title: 'Описание',
|
||||
dataIndex: ['app', 'description'],
|
||||
key: 'description'
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: ['app', 'type'],
|
||||
key: 'Type'
|
||||
},
|
||||
{
|
||||
title: 'Количество токенов',
|
||||
dataIndex: 'tokens',
|
||||
key: 'tokensAmount',
|
||||
render: (value) => {
|
||||
return value.length
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Действия',
|
||||
dataIndex: 'app',
|
||||
key: 'actions',
|
||||
render: (record) => {
|
||||
return (
|
||||
<CanEdit>
|
||||
<Button
|
||||
danger
|
||||
className="applications-content__update-btn"
|
||||
onClick={() => {
|
||||
handleShowUpdateModalApplicationApp(record)
|
||||
}}
|
||||
icon={<EditOutlined />}
|
||||
/>
|
||||
<Button
|
||||
onClick={() => handleRemoveApplicationApp(record.id)}
|
||||
icon={<DeleteOutlined />}
|
||||
/>
|
||||
</CanEdit>
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const tokensOptions = [
|
||||
{
|
||||
value: -1,
|
||||
label: 'Бессрочно'
|
||||
},
|
||||
{
|
||||
value: 3600000,
|
||||
label: 'Один час'
|
||||
},
|
||||
{
|
||||
value: 86400000,
|
||||
label: 'Один день'
|
||||
},
|
||||
{
|
||||
value: 2592000000,
|
||||
label: '30 дней'
|
||||
},
|
||||
{
|
||||
value: 31536000000,
|
||||
label: 'Один год'
|
||||
}
|
||||
]
|
||||
|
||||
if (!id) {
|
||||
if (!selectedItemId) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
if (isLoadingApplicationsContent) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
if (selectedItemId)
|
||||
if (isLoadingApplicationsContent) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="applications-content">
|
||||
<CanEdit>
|
||||
<Button
|
||||
className="applications-content__add-btn"
|
||||
type="primary"
|
||||
onClick={handleShowCreateModalApplicationApp}
|
||||
>
|
||||
Добавить
|
||||
</Button>
|
||||
</CanEdit>
|
||||
<Table
|
||||
expandable={{
|
||||
expandedRowRender: (record) => (
|
||||
<CanEdit>
|
||||
<Button
|
||||
className="applications-content__addToken-btn"
|
||||
onClick={() => handleShowAddModalToken(record.app)}
|
||||
>
|
||||
<PlusSquareOutlined /> Добавить токен
|
||||
</Button>
|
||||
</CanEdit>
|
||||
)
|
||||
}}
|
||||
className="appliactions-content__table"
|
||||
rowKey={(record) => record.app.id}
|
||||
pagination={false}
|
||||
dataSource={applications}
|
||||
columns={columns}
|
||||
/>
|
||||
<section className="applications-content">
|
||||
<Column
|
||||
title="Приложения"
|
||||
onUpdateItem={updateApplicationModal}
|
||||
showUpdateBtn={!!appId}
|
||||
onAddItem={addApplicationModal}
|
||||
onRemoveItem={() => handleRemoveApplicationApp(Number(appId))}
|
||||
items={filterFirstColumnItems(
|
||||
applications?.map((el) => {
|
||||
return el.app
|
||||
}) as unknown as ColumnItem<ApplicationsServiceType>[],
|
||||
searchAppValue
|
||||
)}
|
||||
renderItems={renderColumnItems}
|
||||
searchValue={searchAppValue}
|
||||
selectedItemId={currentApplicationsApp.toString()}
|
||||
setSelectedItemId={(itemId: string) => {
|
||||
setCurrentApplicationsApp(Number(itemId))
|
||||
setSelectedItemId(
|
||||
`${routePaths.applicationsGroup}/${selectedItemId}/${routePaths.application}`,
|
||||
itemId.toString(),
|
||||
searchAppValue,
|
||||
navigate
|
||||
)
|
||||
}}
|
||||
onChangeSearchValue={(value: string) => {
|
||||
setSearchValue(
|
||||
value.trim().toLowerCase(),
|
||||
setSearchParams,
|
||||
'appSearch'
|
||||
)
|
||||
}}
|
||||
/>
|
||||
<ContentColumn>{renderTokenContent()}</ContentColumn>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmit(handleUpdateApplicationApp)}
|
||||
title="Редактировать"
|
||||
open={showApplicationsModal.updateModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
label="Описание"
|
||||
name="description"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
<Modal
|
||||
onOk={handleSubmit(handleUpdateApplicationApp)}
|
||||
title="Редактировать"
|
||||
open={showApplicationsModal.updateModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
label="Описание"
|
||||
name="description"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmit(handleCreateApplicationApp)}
|
||||
title="Добавить"
|
||||
open={showApplicationsModal.addModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
label="Описание"
|
||||
name="description"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmitTokens(handleCreateToken)}
|
||||
title="Добавить"
|
||||
open={showApplicationsModal.addToken}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addToken: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormSelect
|
||||
options={tokensOptions}
|
||||
name="expireTimeMs"
|
||||
control={controlTokens}
|
||||
label="Время действия"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
</section>
|
||||
<Modal
|
||||
onOk={handleSubmit(handleCreateApplicationApp)}
|
||||
title="Добавить"
|
||||
open={showApplicationsModal.addModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput
|
||||
control={controlApplicationApp}
|
||||
label="Описание"
|
||||
name="description"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ const { Content, Sider } = Layout
|
||||
const LayoutComponent = () => {
|
||||
const [collapsed, setCollapsed] = useState<boolean>(false)
|
||||
const [selectedMenuKeys, setSelectedMenuKeys] = useState<MenuItemKeysType[]>(
|
||||
[]
|
||||
[]
|
||||
)
|
||||
const [title, setTitle] = useState('')
|
||||
const [openKeys, setOpenKeys] = useState<string[]>([])
|
||||
@@ -88,7 +88,7 @@ const LayoutComponent = () => {
|
||||
},
|
||||
{
|
||||
label: 'Группа приложений',
|
||||
key: 'applications',
|
||||
key: 'applications_group',
|
||||
className: hideItem([PermissionKeysType.read]),
|
||||
icon: <AppstoreAddOutlined />
|
||||
},
|
||||
@@ -137,9 +137,9 @@ const LayoutComponent = () => {
|
||||
useEffect(() => {
|
||||
ConfigProvider.config({
|
||||
holderRender: (children) => (
|
||||
<ConfigProvider prefixCls="static" theme={theme}>
|
||||
{children}
|
||||
</ConfigProvider>
|
||||
<ConfigProvider prefixCls="static" theme={theme}>
|
||||
{children}
|
||||
</ConfigProvider>
|
||||
)
|
||||
})
|
||||
}, [theme])
|
||||
@@ -191,8 +191,8 @@ const LayoutComponent = () => {
|
||||
case MenuItemKeysType.modules:
|
||||
navigate(routePaths.modules)
|
||||
break
|
||||
case MenuItemKeysType.applications:
|
||||
navigate(routePaths.applications)
|
||||
case MenuItemKeysType.applicationsGroup:
|
||||
navigate(routePaths.applicationsGroup)
|
||||
break
|
||||
default:
|
||||
}
|
||||
@@ -203,40 +203,40 @@ const LayoutComponent = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<section>
|
||||
<Header title={title} />
|
||||
<Layout className="layout" data-cy="homePage">
|
||||
{status === StateProfileStatus.pending ? (
|
||||
<Spin size="large" />
|
||||
) : (
|
||||
<>
|
||||
<Sider
|
||||
width="250px"
|
||||
data-cy="aside"
|
||||
theme="light"
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
onCollapse={(value) => setCollapsed(value)}
|
||||
>
|
||||
<Menu
|
||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||
openKeys={openKeys}
|
||||
selectedKeys={selectedMenuKeys}
|
||||
onClick={handlerOnClickMenu}
|
||||
theme="light"
|
||||
mode="inline"
|
||||
items={menuItems}
|
||||
/>
|
||||
</Sider>
|
||||
<Layout className="site-layout">
|
||||
<Content className="site-layout__content">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</>
|
||||
)}
|
||||
</Layout>
|
||||
</section>
|
||||
<section>
|
||||
<Header title={title} />
|
||||
<Layout className="layout" data-cy="homePage">
|
||||
{status === StateProfileStatus.pending ? (
|
||||
<Spin size="large" />
|
||||
) : (
|
||||
<>
|
||||
<Sider
|
||||
width="250px"
|
||||
data-cy="aside"
|
||||
theme="light"
|
||||
collapsible
|
||||
collapsed={collapsed}
|
||||
onCollapse={(value) => setCollapsed(value)}
|
||||
>
|
||||
<Menu
|
||||
onOpenChange={(keys) => setOpenKeys(keys)}
|
||||
openKeys={openKeys}
|
||||
selectedKeys={selectedMenuKeys}
|
||||
onClick={handlerOnClickMenu}
|
||||
theme="light"
|
||||
mode="inline"
|
||||
items={menuItems}
|
||||
/>
|
||||
</Sider>
|
||||
<Layout className="site-layout">
|
||||
<Content className="site-layout__content">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</>
|
||||
)}
|
||||
</Layout>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export enum MenuItemKeysType {
|
||||
logout = 'logout',
|
||||
profile = 'profile',
|
||||
modules = 'modules',
|
||||
applications = 'applications'
|
||||
applicationsGroup = 'applications_group'
|
||||
}
|
||||
export enum MenuItemLabelsType {
|
||||
users = 'Пользователи',
|
||||
@@ -19,14 +19,15 @@ export enum MenuItemLabelsType {
|
||||
roles = 'Роли',
|
||||
profile = 'Профиль',
|
||||
modules = 'Модули',
|
||||
applications = 'Группа приложений',
|
||||
logout = 'Выход',
|
||||
applications_group = 'Группа приложений'
|
||||
}
|
||||
|
||||
interface MenuItem {
|
||||
key: MenuItemKeysType
|
||||
parent: string[]
|
||||
}
|
||||
|
||||
export const menuKeys: Record<MenuItemKeysType, MenuItem> = {
|
||||
[MenuItemKeysType.users]: {
|
||||
key: MenuItemKeysType.users,
|
||||
@@ -60,8 +61,8 @@ export const menuKeys: Record<MenuItemKeysType, MenuItem> = {
|
||||
key: MenuItemKeysType.modules,
|
||||
parent: []
|
||||
},
|
||||
[MenuItemKeysType.applications]: {
|
||||
key: MenuItemKeysType.applications,
|
||||
[MenuItemKeysType.applicationsGroup]: {
|
||||
key: MenuItemKeysType.applicationsGroup,
|
||||
parent: ['']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
import { CopyOutlined, DeleteOutlined } from '@ant-design/icons'
|
||||
import { Button, message, Popconfirm, Spin, Table } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import ClipboardJS from 'clipboard'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/ru'
|
||||
import duration from 'dayjs/plugin/duration'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { Layout, FormComponents } from 'isp-ui-kit'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
|
||||
import { ValidationRules } from '@constants/form/validationRules.ts'
|
||||
|
||||
import Modal from '@widgets/Modal'
|
||||
|
||||
// import CanEdit from '@components/CanEdit'
|
||||
import {
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import tokensApi from '@services/tokensService.ts'
|
||||
|
||||
import './tokens.scss'
|
||||
import CanEdit from '@components/CanEdit'
|
||||
|
||||
const { FormSelect } = FormComponents
|
||||
const { EmptyData } = Layout
|
||||
|
||||
interface TokenPropTypes {
|
||||
id: number
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-named-as-default-member
|
||||
dayjs.locale('ru')
|
||||
dayjs.extend(duration)
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
const TokenContent = ({ id }: TokenPropTypes) => {
|
||||
const [showApplicationsModal, setShowApplicationsModal] = useState(false)
|
||||
const {
|
||||
handleSubmit: handleSubmitTokens,
|
||||
control: controlTokens,
|
||||
reset
|
||||
} = useForm<ApplicationTokenType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const { data, isLoading } = tokensApi.useGetTokensByAppIdQuery({ id })
|
||||
const [createToken] = tokensApi.useCreateTokenMutation()
|
||||
const [revokeToken] = tokensApi.useRevokeTokensMutation()
|
||||
|
||||
useEffect(() => {
|
||||
const clipboard = new ClipboardJS('.copy-btn')
|
||||
clipboard.on('success', () => {
|
||||
message.success('Токен скопирован в буфер обмена')
|
||||
})
|
||||
clipboard.on('error', () => {
|
||||
message.error('Ошибка копирования')
|
||||
})
|
||||
|
||||
return () => {
|
||||
clipboard.destroy()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleCreateToken = (data: any) => {
|
||||
if (id) {
|
||||
const newToken: NewApplicationTokenType = {
|
||||
expireTimeMs: data.expireTime,
|
||||
appId: Number(id)
|
||||
}
|
||||
|
||||
createToken(newToken)
|
||||
.then(() => {
|
||||
setShowApplicationsModal(false)
|
||||
reset()
|
||||
message.info('Элемент добавлен')
|
||||
})
|
||||
.catch(() => {
|
||||
message.error('Ошибка добавления элемента')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function shortenString(longString: string) {
|
||||
if (longString.length <= 6) {
|
||||
return <span>{longString}</span>
|
||||
} else {
|
||||
return (
|
||||
<span>
|
||||
{longString.slice(0, 3)}...{longString.slice(-3)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRevokeToken = (elem: ApplicationTokenType) => {
|
||||
const currentRemoveToken = {
|
||||
appId: id,
|
||||
tokens: [elem.token]
|
||||
}
|
||||
|
||||
revokeToken(currentRemoveToken)
|
||||
.unwrap()
|
||||
.then(() => message.success('Элемент удален'))
|
||||
.catch(() => message.info('Ошибка удаления элемента'))
|
||||
}
|
||||
|
||||
const columns: ColumnsType<ApplicationTokenType> = [
|
||||
{
|
||||
title: 'Токен',
|
||||
dataIndex: 'token',
|
||||
key: 'token',
|
||||
render: (record) => <div>{shortenString(record)}</div>
|
||||
},
|
||||
{
|
||||
title: 'Дата/Время выпуска',
|
||||
dataIndex: 'createdAt',
|
||||
key: 'createdAt',
|
||||
render: (record) => {
|
||||
const FULL_DATE_FORMAT = 'DD-MM-YYYY/HH:mm'
|
||||
const formatTime = dayjs(record.createdAt).format(FULL_DATE_FORMAT)
|
||||
return <div>{formatTime}</div>
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Срок действия',
|
||||
dataIndex: 'expireTime',
|
||||
key: 'expireTime',
|
||||
render: (value) => {
|
||||
const time = dayjs.duration(value).humanize()
|
||||
if (value > 0) {
|
||||
return <div>{time}</div>
|
||||
}
|
||||
return <div>Отсутствует</div>
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Истекает',
|
||||
dataIndex: 'expireTime',
|
||||
key: 'expireTime',
|
||||
render: (value, record) => {
|
||||
const FULL_DATE_FORMAT = 'DD-MM-YYYY, HH:mm'
|
||||
const formatTime = dayjs(record.createdAt)
|
||||
.add(record.expireTime)
|
||||
.format(FULL_DATE_FORMAT)
|
||||
|
||||
return value > 0 ? <span>{formatTime}</span> : <span> Никогда </span>
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Скопировать',
|
||||
dataIndex: 'token',
|
||||
key: 'copyToken',
|
||||
align: 'center',
|
||||
render: (record) => {
|
||||
return (
|
||||
<Button className="copy-btn" data-clipboard-text={record}>
|
||||
<CopyOutlined />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Отозвать',
|
||||
dataIndex: 'appId',
|
||||
key: 'recall',
|
||||
align: 'center',
|
||||
render: (_, record) => {
|
||||
return (
|
||||
<Popconfirm
|
||||
title="Закончить эту сессию?"
|
||||
onConfirm={() => handleRevokeToken(record)}
|
||||
>
|
||||
<Button danger>
|
||||
<DeleteOutlined />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const tokensOptions = [
|
||||
{
|
||||
value: -1,
|
||||
label: 'Бессрочно'
|
||||
},
|
||||
{
|
||||
value: 3600000,
|
||||
label: 'Один час'
|
||||
},
|
||||
{
|
||||
value: 86400000,
|
||||
label: 'Один день'
|
||||
},
|
||||
{
|
||||
value: 2592000000,
|
||||
label: '30 дней'
|
||||
},
|
||||
{
|
||||
value: 31536000000,
|
||||
label: 'Один год'
|
||||
}
|
||||
]
|
||||
if (!id) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
const handleShowAddModalToken = () => {
|
||||
setShowApplicationsModal(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="token-content">
|
||||
<CanEdit>
|
||||
<Button
|
||||
className="applications-content__add-btn"
|
||||
type="primary"
|
||||
onClick={handleShowAddModalToken}
|
||||
>
|
||||
Добавить токен
|
||||
</Button>
|
||||
</CanEdit>
|
||||
|
||||
<Table
|
||||
className="appliactions-tokent__table"
|
||||
rowKey={(record) => record.createdAt}
|
||||
pagination={false}
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmitTokens(handleCreateToken)}
|
||||
title="Добавить"
|
||||
open={showApplicationsModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() => setShowApplicationsModal(false)}
|
||||
>
|
||||
<form>
|
||||
<FormSelect
|
||||
options={tokensOptions}
|
||||
name="expireTime"
|
||||
control={controlTokens}
|
||||
label="Время действия"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default TokenContent
|
||||
@@ -0,0 +1,7 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
.token-content {
|
||||
padding: $basic-padding *2 $basic-padding;
|
||||
.copy-btn {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.applications-page {
|
||||
height: 100%;
|
||||
height: 100vh;
|
||||
.column-content {
|
||||
max-height: 100vh;
|
||||
}
|
||||
.three-columns {
|
||||
display: flex;
|
||||
background: #fff;
|
||||
|
||||
@@ -1,39 +1,57 @@
|
||||
export interface ApplicationsGroupType {
|
||||
createdAt: string,
|
||||
description: string,
|
||||
domainId: number,
|
||||
id: number,
|
||||
name: string,
|
||||
updatedAt: string
|
||||
createdAt: string
|
||||
description: string
|
||||
domainId: number
|
||||
id: number
|
||||
name: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export type NewApplicationsGroupType = Omit<ApplicationsGroupType, 'id' | 'createdAt' | 'updatedAt'>
|
||||
export type UpdateApplicationsGroupType = Omit<ApplicationsGroupType, 'createdAt' | 'updatedAt'>
|
||||
export type NewApplicationsGroupType = Omit<
|
||||
ApplicationsGroupType,
|
||||
'id' | 'createdAt' | 'updatedAt'
|
||||
>
|
||||
export type UpdateApplicationsGroupType = Omit<
|
||||
ApplicationsGroupType,
|
||||
'createdAt' | 'updatedAt'
|
||||
>
|
||||
|
||||
export interface ApplicationsServiceType {
|
||||
app:ApplicationAppType
|
||||
tokens: ApplicationTokenType[]
|
||||
app: ApplicationAppType
|
||||
tokens: ApplicationTokenType[]
|
||||
}
|
||||
|
||||
export type NewApplicationTokenType = Omit<ApplicationTokenType, 'createdAt' | 'token'>
|
||||
export interface ApplicationAppType {
|
||||
createdAt: string,
|
||||
description: string,
|
||||
id: number,
|
||||
name: string,
|
||||
serviceId: number,
|
||||
type: string,
|
||||
updatedAt: string
|
||||
export type NewApplicationTokenType = {
|
||||
appId: number
|
||||
expireTimeMs: number
|
||||
}
|
||||
|
||||
export interface ApplicationAppType {
|
||||
createdAt: string
|
||||
description: string
|
||||
id: number
|
||||
name: string
|
||||
serviceId: number
|
||||
type: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export type UpdateApplicationAppType = Omit<ApplicationAppType, 'createdAt' | 'updatedAt'>
|
||||
export type NewApplicationAppType = Omit<ApplicationAppType, 'id' | 'createdAt' | 'updatedAt'>
|
||||
export type UpdateApplicationAppType = Omit<
|
||||
ApplicationAppType,
|
||||
'createdAt' | 'updatedAt'
|
||||
>
|
||||
export type NewApplicationAppType = Omit<
|
||||
ApplicationAppType,
|
||||
'id' | 'createdAt' | 'updatedAt'
|
||||
>
|
||||
export type RevokeTokenType = {
|
||||
appId: number
|
||||
tokens: string[]
|
||||
}
|
||||
|
||||
export interface ApplicationTokenType {
|
||||
appId: number,
|
||||
createdAt: string,
|
||||
expireTimeMs: number,
|
||||
token: string
|
||||
appId: number
|
||||
createdAt: string
|
||||
expireTime: number
|
||||
token: string
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ const ApplicationsPage = () => {
|
||||
const { id: selectedItemId = '' } = useParams()
|
||||
const [searchParams, setSearchParams] = useSearchParams('')
|
||||
const { hasPermission } = useRole()
|
||||
const [currentApplicationsApp, setCurrentApplicationsApp] = useState(0)
|
||||
|
||||
const {
|
||||
data: applicationsGroup = [],
|
||||
@@ -55,6 +56,7 @@ const ApplicationsPage = () => {
|
||||
applicationsGroupApi.useRemoveApplicationsGroupMutation()
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
// const hasRevokePermission = hasPermission(PermissionKeysType.write)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
@@ -128,21 +130,36 @@ const ApplicationsPage = () => {
|
||||
message.info('Сервис успешно отредактирован')
|
||||
}
|
||||
|
||||
const handleRemoveApplicationsGtoup = () => {
|
||||
deleteApplicationsGroup([Number(selectedItemId)])
|
||||
.unwrap()
|
||||
.then(() => message.success('Элемент удален'))
|
||||
.catch(() => message.info('Ошибка удаления элемента'))
|
||||
}
|
||||
|
||||
const renderMainContent = () => {
|
||||
if (!selectedItemId) {
|
||||
return <EmptyData />
|
||||
}
|
||||
return <ApplicationsContent id={Number(selectedItemId)} />
|
||||
|
||||
return (
|
||||
<ApplicationsContent
|
||||
selectedItemId={Number(selectedItemId)}
|
||||
currentApplicationsApp={currentApplicationsApp}
|
||||
setCurrentApplicationsApp={setCurrentApplicationsApp}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="applications-page ">
|
||||
<main className="applications-page">
|
||||
<div className="applications-page__wrap three-columns">
|
||||
<Column
|
||||
title="Группа приложений"
|
||||
onUpdateItem={updateApplicationModal}
|
||||
showUpdateBtn={!!selectedItemId}
|
||||
onAddItem={addApplicationModal}
|
||||
onRemoveItem={() => deleteApplicationsGroup([Number(selectedItemId)])}
|
||||
onRemoveItem={handleRemoveApplicationsGtoup}
|
||||
items={filterFirstColumnItems(
|
||||
applicationsGroup as unknown as ColumnItem<ApplicationsGroupType>[],
|
||||
searchValue
|
||||
@@ -151,8 +168,9 @@ const ApplicationsPage = () => {
|
||||
searchValue={searchValue}
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={(itemId) => {
|
||||
setCurrentApplicationsApp(0)
|
||||
setSelectedItemId(
|
||||
`${routePaths.applications}`,
|
||||
`${routePaths.applicationsGroup}`,
|
||||
itemId,
|
||||
searchValue,
|
||||
navigate
|
||||
|
||||
+161
-142
@@ -23,156 +23,175 @@ const Connections = lazy(() => import('@components/Connections'))
|
||||
const ApplicationsPage = lazy(() => import('@pages/ApplicationsPage'))
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
<Routes>
|
||||
<Route element={<PrivateRoute />}>
|
||||
<Route path={routePaths.home} element={<Layout />}>
|
||||
<Route
|
||||
index
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<HomePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.profile}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ProfilePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.users}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<UsersPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.users}/:id`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<UserEditor />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.roles}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<RolesPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
return (
|
||||
<Routes>
|
||||
<Route element={<PrivateRoute />}>
|
||||
<Route path={routePaths.home} element={<Layout />}>
|
||||
<Route
|
||||
index
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<HomePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.profile}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ProfilePage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.users}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<UsersPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.users}/:id`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<UserEditor />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.roles}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<RolesPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<RolesPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.applicationsGroup}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path={routePaths.application}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":appId"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
<Route
|
||||
path={routePaths.sessions}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<SessionsPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.securityLog}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<SecurityLogPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.appAccess}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.modules}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ModulesPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route path=":id">
|
||||
<Route
|
||||
path="configurations"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<div>Configurations</div>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="connections"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<Connections />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<RolesPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.applications}
|
||||
path={routePaths.error}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
<ErrorPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.sessions}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<SessionsPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.securityLog}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<SecurityLogPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={`${routePaths.appAccess}`}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<AppAccessPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.modules}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ModulesPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route path=":id">
|
||||
<Route
|
||||
path="configurations"
|
||||
<Route
|
||||
path={routePaths.login}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<div>Configurations</div>
|
||||
</Suspense>
|
||||
<Suspense fallback={<Spin />}>
|
||||
<LoginPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="connections"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<Connections />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.error}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ErrorPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path={routePaths.login}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<LoginPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
)
|
||||
/>
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
|
||||
export default Routers
|
||||
@@ -9,8 +9,10 @@ type RoutePaths =
|
||||
| 'securityLog'
|
||||
| 'roles'
|
||||
| 'appAccess'
|
||||
| 'applicationsGroup'
|
||||
| 'configuration'
|
||||
| 'modules'
|
||||
| 'applications'
|
||||
| 'application'
|
||||
|
||||
export const routePaths: Record<RoutePaths, string> = {
|
||||
home: '/',
|
||||
@@ -23,6 +25,8 @@ export const routePaths: Record<RoutePaths, string> = {
|
||||
securityLog: '/securityLog',
|
||||
roles: '/roles',
|
||||
appAccess: '/appAccess',
|
||||
applicationsGroup: '/applications_group',
|
||||
configuration: '/configuration',
|
||||
modules: '/modules',
|
||||
applications: '/applications'
|
||||
application: 'application'
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import {
|
||||
ApplicationAppType,
|
||||
ApplicationsServiceType, NewApplicationAppType,
|
||||
ApplicationsServiceType,
|
||||
NewApplicationAppType,
|
||||
UpdateApplicationAppType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
@@ -15,56 +17,65 @@ const applicationsApi = createApi({
|
||||
tagTypes: ['Applications'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
|
||||
getAllApplicationsService: builder.query<
|
||||
ApplicationsServiceType[],
|
||||
{ id: string }
|
||||
ApplicationsServiceType[],
|
||||
{ id: string }
|
||||
>({
|
||||
query: () => ({ url: apiPaths.getAllApplications }),
|
||||
providesTags: () => ['Applications']
|
||||
}),
|
||||
|
||||
createApplicationService: builder.mutation<
|
||||
ApplicationAppType,
|
||||
NewApplicationAppType
|
||||
ApplicationAppType,
|
||||
NewApplicationAppType
|
||||
>({
|
||||
query: ( NewApplicationsService) => ({
|
||||
query: (NewApplicationsService) => ({
|
||||
url: apiPaths.createUpdateApplication,
|
||||
data: NewApplicationsService
|
||||
data: NewApplicationsService
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
}),
|
||||
|
||||
getApplicationsServiceById: builder.query<ApplicationsServiceType, { id : number}>({
|
||||
getApplicationsServiceById: builder.query<
|
||||
ApplicationsServiceType,
|
||||
{ id: number }
|
||||
>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getApplicationById,
|
||||
data: id
|
||||
}),
|
||||
providesTags: () => ['Applications']
|
||||
}),
|
||||
|
||||
getApplicationsByServiceId: builder.query<ApplicationsServiceType[], { id : number}>({
|
||||
getApplicationsByServiceId: builder.query<
|
||||
ApplicationsServiceType[],
|
||||
{ id: number }
|
||||
>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getApplicationsByServiceId,
|
||||
data: id
|
||||
}),
|
||||
providesTags: () => ['Applications']
|
||||
}),
|
||||
|
||||
updateApplicationsService: builder.mutation<void, UpdateApplicationAppType>({
|
||||
query: (updateApplications) => ({
|
||||
url: apiPaths.createUpdateApplication,
|
||||
data: updateApplications
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
}),
|
||||
updateApplicationsService: builder.mutation<void, UpdateApplicationAppType>(
|
||||
{
|
||||
query: (updateApplications) => ({
|
||||
url: apiPaths.createUpdateApplication,
|
||||
data: updateApplications
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
}
|
||||
),
|
||||
|
||||
removeApplicationsService: builder.mutation<void, number[]>({
|
||||
query: ([id]) => ({
|
||||
url: apiPaths.deleteApplication,
|
||||
data: [ id]
|
||||
data: [id]
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default applicationsApi
|
||||
export default applicationsApi
|
||||
@@ -1,9 +1,11 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import {
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType,
|
||||
RevokeTokenType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
@@ -15,16 +17,31 @@ const tokensApi = createApi({
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
createToken: builder.mutation<
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType
|
||||
>({
|
||||
query: ( NewApplicationTokenType) => ({
|
||||
query: (NewApplicationTokenType) => ({
|
||||
url: apiPaths.createToken,
|
||||
data: NewApplicationTokenType
|
||||
data: NewApplicationTokenType
|
||||
}),
|
||||
invalidatesTags: ['Tokens']
|
||||
}),
|
||||
|
||||
getTokensByAppId: builder.query<ApplicationTokenType[], { id: number }>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getTokensByAppId,
|
||||
data: id
|
||||
}),
|
||||
providesTags: ['Tokens']
|
||||
}),
|
||||
revokeTokens: builder.mutation<void, RevokeTokenType>({
|
||||
query: (el) => ({
|
||||
url: apiPaths.revokeTokens,
|
||||
data: el
|
||||
}),
|
||||
invalidatesTags: ['Tokens']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default tokensApi
|
||||
export default tokensApi
|
||||
@@ -12,6 +12,7 @@ import roleApi from '@services/roleService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
import securityLogServiceApi from '@services/securityLogService.ts'
|
||||
import sessionServiceApi from '@services/sessionService.ts'
|
||||
import tokensApi from '@services/tokensService.ts'
|
||||
import userServiceApi from '@services/userService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
@@ -39,7 +40,8 @@ const rootReducer = combineReducers({
|
||||
[routeApi.reducerPath]: routeApi.reducer,
|
||||
[modulesServiceApi.reducerPath]: modulesServiceApi.reducer,
|
||||
[applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer,
|
||||
[applicationsApi.reducerPath]: applicationsApi.reducer
|
||||
[applicationsApi.reducerPath]: applicationsApi.reducer,
|
||||
[tokensApi.reducerPath]: tokensApi.reducer
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
@@ -57,7 +59,8 @@ export const setupStore = () =>
|
||||
sessionServiceApi.middleware,
|
||||
modulesServiceApi.middleware,
|
||||
applicationsGroupApi.middleware,
|
||||
applicationsApi.middleware
|
||||
applicationsApi.middleware,
|
||||
tokensApi.middleware
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user