Merge branch 'MSP-3106_add_aplications_page' into 'main'
Resolve MSP-3106 "Add aplications page" Closes MSP-3106 See merge request isp/isp-admin-ui!20
This commit is contained in:
commit
7a0137e3f7
19 files changed
+977
-19
No files matched your search
@@ -1,3 +1,5 @@
|
||||
## 0.9.0
|
||||
-Добавлена страница приложений
|
||||
## 0.8.1
|
||||
- Перенос UserMenu в список главного меню в Layout
|
||||
## 0.8.0
|
||||
|
||||
Generated
+5
-7
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"name": "isp-admin-ui",
|
||||
"version": "0.8.0",
|
||||
"version": "0.8.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "isp-admin-ui",
|
||||
"version": "0.8.0",
|
||||
"version": "0.8.1",
|
||||
"dependencies": {
|
||||
"@reduxjs/toolkit": "^2.2.3",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"axios": "^1.6.8",
|
||||
"isp-ui-kit": "https://github.com/txix-open/isp-ui-kit",
|
||||
"isp-ui-kit": "github:txix-open/isp-ui-kit",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
@@ -7055,8 +7055,8 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/isp-ui-kit": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#508a5bd9cb4efac0e9389ad2f9f8c60683d1712e",
|
||||
"version": "0.3.4",
|
||||
"resolved": "git+ssh://git@github.com/txix-open/isp-ui-kit.git#ee517a533f9e4934d08bf6d70cdfda31198cba4c",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@codemirror/lang-javascript": "^6.2.1",
|
||||
@@ -7430,7 +7430,6 @@
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
@@ -7810,7 +7809,6 @@
|
||||
"version": "15.8.1",
|
||||
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",
|
||||
"integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.4.0",
|
||||
"object-assign": "^4.1.1",
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "isp-admin-ui",
|
||||
"private": true,
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
@@ -17,7 +17,7 @@
|
||||
"@reduxjs/toolkit": "^2.2.3",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"axios": "^1.6.8",
|
||||
"isp-ui-kit": "https://github.com/txix-open/isp-ui-kit",
|
||||
"isp-ui-kit": "github:txix-open/isp-ui-kit",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-hook-form": "^7.51.2",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.applications-content {
|
||||
padding: $basic-padding *2 $basic-padding;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
&__add-btn {
|
||||
max-width: 240px;
|
||||
margin-left: auto;
|
||||
margin-bottom: $basic-margin * 2;
|
||||
}
|
||||
&__update-btn {
|
||||
margin-right: $basic-margin;
|
||||
}
|
||||
&__addToken-btn {
|
||||
display: flex;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
import {
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
PlusSquareOutlined
|
||||
} from '@ant-design/icons'
|
||||
import { Button, message, Spin, Table } from 'antd'
|
||||
import { ColumnsType } from 'antd/es/table'
|
||||
import { FormComponents } from 'isp-ui-kit'
|
||||
import { EmptyData } from 'isp-ui-kit/dist/Layout'
|
||||
import { FC, 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 {
|
||||
ApplicationAppType,
|
||||
ApplicationsServiceType,
|
||||
ApplicationTokenType,
|
||||
NewApplicationAppType,
|
||||
NewApplicationTokenType,
|
||||
UpdateApplicationAppType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import applicationsApi from '@services/applicationsService.ts'
|
||||
import tokensApi from '@services/tokensService.ts'
|
||||
|
||||
import './applications-content.scss'
|
||||
|
||||
const { FormInput, FormSelect } = FormComponents
|
||||
|
||||
interface ApplicationsContentPropTypes {
|
||||
id: number
|
||||
}
|
||||
|
||||
const ApplicationsContent: FC<ApplicationsContentPropTypes> = (id) => {
|
||||
const { data: applications, isLoading: isLoadingApplicationsContent = [] } =
|
||||
applicationsApi.useGetApplicationsByServiceIdQuery(id)
|
||||
|
||||
const [createApplicationService] =
|
||||
applicationsApi.useCreateApplicationServiceMutation()
|
||||
const [updateApplication] =
|
||||
applicationsApi.useUpdateApplicationsServiceMutation()
|
||||
const [removeApplicationsService] =
|
||||
applicationsApi.useRemoveApplicationsServiceMutation()
|
||||
const [createToken] = tokensApi.useCreateTokenMutation()
|
||||
const [showApplicationsModal, setShowApplicationsModal] = useState({
|
||||
addModal: false,
|
||||
updateModal: false,
|
||||
addToken: false
|
||||
})
|
||||
const [currentApplicationsApp, setCurrentApplicationsApp] =
|
||||
useState<ApplicationAppType>()
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
control: controlApplicationApp,
|
||||
reset
|
||||
} = useForm<ApplicationAppType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const { handleSubmit: handleSubmitTokens, control: controlTokens } =
|
||||
useForm<ApplicationTokenType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
const handleShowUpdateModalApplicationApp = (data: ApplicationAppType) => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: true
|
||||
})
|
||||
setCurrentApplicationsApp(data)
|
||||
}
|
||||
const handleShowCreateModalApplicationApp = () => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: true
|
||||
})
|
||||
}
|
||||
const handleShowAddModalToken = (data: ApplicationAppType) => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addToken: true
|
||||
})
|
||||
setCurrentApplicationsApp(data)
|
||||
}
|
||||
|
||||
const handleUpdateApplicationApp = (data: UpdateApplicationAppType) => {
|
||||
if (currentApplicationsApp) {
|
||||
const updateApplications: UpdateApplicationAppType = {
|
||||
id: currentApplicationsApp.id,
|
||||
name: data.name,
|
||||
description: data.description
|
||||
? data.description
|
||||
: currentApplicationsApp.description,
|
||||
serviceId: id.id,
|
||||
type: 'SYSTEM'
|
||||
}
|
||||
updateApplication({ ...currentApplicationsApp, ...updateApplications })
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
reset()
|
||||
message.info('Элемент сохранен')
|
||||
})
|
||||
.catch(() => message.error('Ошибка обновления элемента'))
|
||||
}
|
||||
}
|
||||
|
||||
const handleCreateApplicationApp = (data: NewApplicationAppType) => {
|
||||
const newApplicationApp: NewApplicationAppType = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
serviceId: id.id,
|
||||
type: 'SYSTEM'
|
||||
}
|
||||
|
||||
createApplicationService(newApplicationApp)
|
||||
.unwrap()
|
||||
.then(message.info('Элемент сохранен'))
|
||||
.catch((e) => message.error(e))
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
})
|
||||
reset()
|
||||
}
|
||||
const handleRemoveApplicationApp = (id: number) =>
|
||||
removeApplicationsService([id])
|
||||
.then(() => {
|
||||
message.info('Элемент удален')
|
||||
})
|
||||
.catch(message.error('Ошибка добавления элемента'))
|
||||
|
||||
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 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) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
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}
|
||||
/>
|
||||
|
||||
<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>
|
||||
)
|
||||
}
|
||||
|
||||
export default ApplicationsContent
|
||||
@@ -4,13 +4,13 @@ import { useRole } from '@hooks/useRole.tsx'
|
||||
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
const AdminPermission = ({ children }: PropsWithChildren) => {
|
||||
const CanEdit = ({ children }: PropsWithChildren) => {
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
if (hasPermission(PermissionKeysType.read)) {
|
||||
if (hasPermission(PermissionKeysType.write)) {
|
||||
return <>{children}</>
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export default AdminPermission
|
||||
export default CanEdit
|
||||
@@ -1,7 +1,8 @@
|
||||
import {
|
||||
LockOutlined,
|
||||
LogoutOutlined,
|
||||
ProfileOutlined
|
||||
ProfileOutlined,
|
||||
AppstoreAddOutlined
|
||||
} from '@ant-design/icons'
|
||||
import { ConfigProvider, Layout, Menu, Spin } from 'antd'
|
||||
import { useContext, useEffect, useState } from 'react'
|
||||
@@ -81,6 +82,12 @@ const LayoutComponent = () => {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Группа приложений',
|
||||
key: 'applications',
|
||||
className: hideItem([PermissionKeysType.read]),
|
||||
icon: <AppstoreAddOutlined />
|
||||
},
|
||||
{
|
||||
label: 'Доступы приложений',
|
||||
key: 'appAccess',
|
||||
@@ -169,6 +176,9 @@ const LayoutComponent = () => {
|
||||
case MenuItemKeysType.roles:
|
||||
navigate(routePaths.roles)
|
||||
break
|
||||
case MenuItemKeysType.applications:
|
||||
navigate(routePaths.applications)
|
||||
break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ export enum MenuItemKeysType {
|
||||
appAccess = 'appAccess',
|
||||
roles = 'roles',
|
||||
logout = 'logout',
|
||||
profile = 'profile'
|
||||
profile = 'profile',
|
||||
applications = 'applications',
|
||||
}
|
||||
|
||||
interface MenuItem {
|
||||
@@ -42,6 +43,10 @@ export const menuKeys: Record<MenuItemKeysType, MenuItem> = {
|
||||
[MenuItemKeysType.profile]: {
|
||||
key: MenuItemKeysType.profile,
|
||||
parent: ['']
|
||||
},
|
||||
[MenuItemKeysType.applications]: {
|
||||
key: MenuItemKeysType.applications,
|
||||
parent: ['']
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,20 @@ type PathKeys =
|
||||
| 'setList'
|
||||
| 'setOne'
|
||||
| 'getAllRoutes'
|
||||
| 'createUpdateService'
|
||||
| 'deleteService'
|
||||
| 'getAllService'
|
||||
| 'getServiceById'
|
||||
| 'getServicesByDomainId'
|
||||
| 'createUpdateApplication'
|
||||
| 'deleteApplication'
|
||||
| 'getApplicationById'
|
||||
| 'getAllApplications'
|
||||
| 'getApplicationsByServiceId'
|
||||
| 'createToken'
|
||||
| 'getTokensByAppId'
|
||||
| 'revokeTokens'
|
||||
| 'revokeTokensForApp'
|
||||
|
||||
export const apiPaths: Record<PathKeys, string> = {
|
||||
baseUrl: '/api/kkd-configuration-service',
|
||||
@@ -62,9 +76,25 @@ export const apiPaths: Record<PathKeys, string> = {
|
||||
setLogEvents: '/log/set_events',
|
||||
// ======= APPLICATIONS ======
|
||||
getSystemTree: '/application/get_system_tree',
|
||||
getAllApplications: '/application/get_applications',
|
||||
createUpdateApplication: '/application/create_update_application',
|
||||
getApplicationsByServiceId: '/application/get_applications_by_service_id',
|
||||
deleteApplication: '/application/delete_applications',
|
||||
getApplicationById: '/application/get_application_by_id',
|
||||
// ======= ACCESS_LIST ======
|
||||
getById: '/access_list/get_by_id',
|
||||
setList: '/access_list/set_list',
|
||||
setOne: '/access_list/set_one',
|
||||
getAllRoutes: '/routing/get_routes'
|
||||
getAllRoutes: '/routing/get_routes',
|
||||
// ======= SERVICE ======
|
||||
getServiceById: '/service/get_service_by_id',
|
||||
getAllService: '/service/get_service',
|
||||
deleteService: '/service/delete_service',
|
||||
createUpdateService: '/service/create_update_service',
|
||||
getServicesByDomainId: '/service/get_services_by_domain_id',
|
||||
// ======= TOKENS ======
|
||||
createToken: '/token/create_token',
|
||||
getTokensByAppId: '/token/get_tokens_by_app_id',
|
||||
revokeTokens: '/token/revoke_tokens',
|
||||
revokeTokensForApp: '/token/revoke_tokens_for_app'
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
@import "src/constants/style/styleConst";
|
||||
|
||||
.applications-page {
|
||||
height: 100vh;
|
||||
.three-columns {
|
||||
display: flex;
|
||||
background: #fff;
|
||||
box-shadow: inset -1px 0px 0px $border-color;
|
||||
|
||||
height: 100%;
|
||||
|
||||
.column__header {
|
||||
padding: $basic-padding * 2 $basic-padding;
|
||||
|
||||
svg {
|
||||
fill: $blue-color;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper {
|
||||
.ant-input-prefix {
|
||||
margin-left: auto;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
z-index: 10;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input-affix-wrapper-focused {
|
||||
.ant-input-prefix {
|
||||
.anticon-search {
|
||||
svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-list-items {
|
||||
.column__items__item {
|
||||
.ant-list-item-meta-title {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
font-weight: 400;
|
||||
color: $text-color-gray;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: $blue-light !important;
|
||||
|
||||
.ant-list-item-meta-title {
|
||||
color: $text-color-blue;
|
||||
}
|
||||
|
||||
svg {
|
||||
path {
|
||||
fill: $text-color-blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
export interface ApplicationsGroupType {
|
||||
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 interface ApplicationsServiceType {
|
||||
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 UpdateApplicationAppType = Omit<ApplicationAppType, 'createdAt' | 'updatedAt'>
|
||||
export type NewApplicationAppType = Omit<ApplicationAppType, 'id' | 'createdAt' | 'updatedAt'>
|
||||
|
||||
export interface ApplicationTokenType {
|
||||
appId: number,
|
||||
createdAt: string,
|
||||
expireTimeMs: number,
|
||||
token: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import { message, Spin } from 'antd'
|
||||
import { Layout, FormComponents } from 'isp-ui-kit'
|
||||
import { ColumnItem } from 'isp-ui-kit/dist/Layout/Column/column.type'
|
||||
import { useEffect, 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 ListItem from '@widgets/ListItem'
|
||||
import Modal from '@widgets/Modal'
|
||||
|
||||
import ApplicationsContent from '@components/ApplicationsContent'
|
||||
|
||||
import {
|
||||
NewApplicationsGroupType,
|
||||
ApplicationsGroupType,
|
||||
UpdateApplicationsGroupType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { setSearchValue, setSelectedItemId } from '@utils/columnLayoutUtils.ts'
|
||||
import { filterFirstColumnItems } from '@utils/firstColumnUtils.ts'
|
||||
|
||||
import useRole from '@hooks/useRole.tsx'
|
||||
|
||||
import applicationsGroupApi from '@services/applicationsGroupService.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
import { PermissionKeysType } from '@type/roles.type.ts'
|
||||
|
||||
import './applications-page.scss'
|
||||
|
||||
const { Column, ContentColumn, EmptyData } = Layout
|
||||
const { FormInput } = FormComponents
|
||||
|
||||
const ApplicationsPage = () => {
|
||||
const navigate = useNavigate()
|
||||
const { id: selectedItemId = '' } = useParams()
|
||||
const [searchParams, setSearchParams] = useSearchParams('')
|
||||
const { hasPermission } = useRole()
|
||||
|
||||
const {
|
||||
data: applicationsGroup = [],
|
||||
isError: isErrorApplicationsGroup,
|
||||
isLoading: isLoadingApplicationsGroup
|
||||
} = applicationsGroupApi.useGetApplicationsGroupByDomainIdQuery({ id: 2 })
|
||||
|
||||
const [createApplicationsGroup] =
|
||||
applicationsGroupApi.useCreateApplicationsGroupMutation()
|
||||
const [updateApplicationsGroup] =
|
||||
applicationsGroupApi.useUpdateApplicationsGroupMutation()
|
||||
|
||||
const [deleteApplicationsGroup] =
|
||||
applicationsGroupApi.useRemoveApplicationsGroupMutation()
|
||||
|
||||
const isPageAvailable = hasPermission(PermissionKeysType.read)
|
||||
const hasRevokePermission = hasPermission(PermissionKeysType.write)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPageAvailable) {
|
||||
navigate(routePaths.home)
|
||||
}
|
||||
}, [isPageAvailable])
|
||||
|
||||
const [showApplicationsModal, setShowApplicationsModal] = useState({
|
||||
addModal: false,
|
||||
updateModal: false
|
||||
})
|
||||
const searchValue = searchParams.get('search') || ''
|
||||
const { handleSubmit, control, reset } = useForm<ApplicationsGroupType>({
|
||||
mode: 'onChange'
|
||||
})
|
||||
|
||||
if (isErrorApplicationsGroup) {
|
||||
return <EmptyData />
|
||||
}
|
||||
|
||||
if (isLoadingApplicationsGroup) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
const renderColumnItems = (item: ColumnItem<any>) => <ListItem item={item} />
|
||||
|
||||
const addApplicationModal = () => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: true
|
||||
})
|
||||
}
|
||||
|
||||
const updateApplicationModal = () => {
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: true
|
||||
})
|
||||
}
|
||||
|
||||
const handleAddApplicationGroup = (data: any) => {
|
||||
const newService: NewApplicationsGroupType = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
domainId: 2
|
||||
}
|
||||
createApplicationsGroup(newService)
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
})
|
||||
reset()
|
||||
message.info('Сервис успешно создан')
|
||||
}
|
||||
|
||||
const handleUpdateApplicationsGroup = (data: NewApplicationsGroupType) => {
|
||||
const updateService: UpdateApplicationsGroupType = {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
domainId: 2,
|
||||
id: Number(selectedItemId)
|
||||
}
|
||||
|
||||
updateApplicationsGroup(updateService)
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
|
||||
reset()
|
||||
message.info('Сервис успешно отредактирован')
|
||||
}
|
||||
|
||||
const renderMainContent = () => {
|
||||
if (!selectedItemId) {
|
||||
return <EmptyData />
|
||||
}
|
||||
return <ApplicationsContent id={Number(selectedItemId)} />
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="applications-page ">
|
||||
<div className="applications-page__wrap three-columns">
|
||||
<Column
|
||||
onUpdateItem={updateApplicationModal}
|
||||
showUpdateBtn={!!selectedItemId}
|
||||
onAddItem={addApplicationModal}
|
||||
onRemoveItem={() => deleteApplicationsGroup([Number(selectedItemId)])}
|
||||
items={filterFirstColumnItems(
|
||||
applicationsGroup as unknown as ColumnItem<ApplicationsGroupType>[],
|
||||
searchValue
|
||||
)}
|
||||
renderItems={renderColumnItems}
|
||||
searchValue={searchValue}
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={(itemId) => {
|
||||
setSelectedItemId(
|
||||
`${routePaths.applications}`,
|
||||
itemId,
|
||||
searchValue,
|
||||
navigate
|
||||
)
|
||||
}}
|
||||
onChangeSearchValue={(value) =>
|
||||
setSearchValue(value, setSearchParams)
|
||||
}
|
||||
/>
|
||||
|
||||
<ContentColumn>{renderMainContent()}</ContentColumn>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmit(handleAddApplicationGroup)}
|
||||
title="Добавить"
|
||||
open={showApplicationsModal.addModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
addModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={control}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput control={control} label="Описание" name="description" />
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
onOk={handleSubmit(handleUpdateApplicationsGroup)}
|
||||
title="Редактировать"
|
||||
open={showApplicationsModal.updateModal}
|
||||
footer={{ onCanselText: 'Отмена', onOkText: 'Сохранить' }}
|
||||
onClose={() =>
|
||||
setShowApplicationsModal({
|
||||
...showApplicationsModal,
|
||||
updateModal: false
|
||||
})
|
||||
}
|
||||
>
|
||||
<form>
|
||||
<FormInput
|
||||
control={control}
|
||||
name="name"
|
||||
label="Наименование"
|
||||
rules={{ required: ValidationRules.required }}
|
||||
/>
|
||||
<FormInput control={control} label="Описание" name="description" />
|
||||
</form>
|
||||
</Modal>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
export default ApplicationsPage
|
||||
@@ -18,6 +18,7 @@ const UserEditor = lazy(() => import('src/pages/UserEditor'))
|
||||
const SessionsPage = lazy(() => import('@pages/SessionsPage'))
|
||||
const SecurityLogPage = lazy(() => import('@pages/SecurityLogPage'))
|
||||
const AppAccessPage = lazy(() => import('@pages/AppAccessPage'))
|
||||
const ApplicationsPage = lazy(() => import('@pages/ApplicationsPage'))
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
@@ -73,6 +74,23 @@ const Routers = () => {
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.applications}
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
path=":id"
|
||||
element={
|
||||
<Suspense fallback={<Spin />}>
|
||||
<ApplicationsPage />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path={routePaths.sessions}
|
||||
element={
|
||||
|
||||
@@ -9,6 +9,7 @@ type RoutePaths =
|
||||
| 'securityLog'
|
||||
| 'roles'
|
||||
| 'appAccess'
|
||||
| 'applications'
|
||||
|
||||
export const routePaths: Record<RoutePaths, string> = {
|
||||
home: '/',
|
||||
@@ -20,5 +21,6 @@ export const routePaths: Record<RoutePaths, string> = {
|
||||
sessions: '/sessions',
|
||||
securityLog: '/securityLog',
|
||||
roles: '/roles',
|
||||
appAccess: '/appAccess'
|
||||
appAccess: '/appAccess',
|
||||
applications: '/applications'
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import { AppApiResponseType, DomainType } from '@type/app.type.ts'
|
||||
const appApi = createApi({
|
||||
reducerPath: 'appService',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['SystemTreeApps'],
|
||||
tagTypes: ['SystemTreeApps' , 'Application'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getSystemTree: builder.query<AppApiResponseType, void>({
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import {
|
||||
ApplicationsGroupType,
|
||||
NewApplicationsGroupType,
|
||||
UpdateApplicationsGroupType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
const applicationsGroupApi = createApi({
|
||||
reducerPath: 'applicationsGroupApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['ApplicationsGroup'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
getApplicationsGroupByDomainId: builder.query<
|
||||
ApplicationsGroupType,
|
||||
{ id: number }
|
||||
>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getServicesByDomainId,
|
||||
data: id
|
||||
}),
|
||||
providesTags: () => ['ApplicationsGroup']
|
||||
}),
|
||||
|
||||
getApplicationsGroupByServiceId: builder.query<
|
||||
ApplicationsGroupType[],
|
||||
{ id: number }
|
||||
>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getServiceById,
|
||||
data: id
|
||||
}),
|
||||
providesTags: () => ['ApplicationsGroup']
|
||||
}),
|
||||
|
||||
getAllApplicationsGroup: builder.query<
|
||||
ApplicationsGroupType[],
|
||||
{ id: string }
|
||||
>({
|
||||
query: () => ({ url: apiPaths.getAllService }),
|
||||
providesTags: () => ['ApplicationsGroup']
|
||||
}),
|
||||
|
||||
createApplicationsGroup: builder.mutation<
|
||||
ApplicationsGroupType,
|
||||
NewApplicationsGroupType
|
||||
>({
|
||||
query: (newApplicationsGroup) => ({
|
||||
url: apiPaths.createUpdateService,
|
||||
data: newApplicationsGroup
|
||||
}),
|
||||
invalidatesTags: ['ApplicationsGroup']
|
||||
}),
|
||||
|
||||
updateApplicationsGroup: builder.mutation<
|
||||
void,
|
||||
UpdateApplicationsGroupType
|
||||
>({
|
||||
query: (updateApplicationsGroup) => ({
|
||||
url: apiPaths.createUpdateService,
|
||||
data: updateApplicationsGroup
|
||||
}),
|
||||
invalidatesTags: ['ApplicationsGroup']
|
||||
}),
|
||||
|
||||
removeApplicationsGroup: builder.mutation<void, number[]>({
|
||||
query: ([id]) => ({
|
||||
url: apiPaths.deleteService,
|
||||
data: [id]
|
||||
}),
|
||||
invalidatesTags: ['ApplicationsGroup']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default applicationsGroupApi
|
||||
@@ -0,0 +1,70 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import {
|
||||
ApplicationAppType,
|
||||
ApplicationsServiceType, NewApplicationAppType,
|
||||
UpdateApplicationAppType
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
const applicationsApi = createApi({
|
||||
reducerPath: 'applicationsApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['Applications'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
|
||||
getAllApplicationsService: builder.query<
|
||||
ApplicationsServiceType[],
|
||||
{ id: string }
|
||||
>({
|
||||
query: () => ({ url: apiPaths.getAllApplications }),
|
||||
providesTags: () => ['Applications']
|
||||
}),
|
||||
|
||||
createApplicationService: builder.mutation<
|
||||
ApplicationAppType,
|
||||
NewApplicationAppType
|
||||
>({
|
||||
query: ( NewApplicationsService) => ({
|
||||
url: apiPaths.createUpdateApplication,
|
||||
data: NewApplicationsService
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
}),
|
||||
|
||||
getApplicationsServiceById: builder.query<ApplicationsServiceType, { id : number}>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getApplicationById,
|
||||
data: id
|
||||
}),
|
||||
}),
|
||||
|
||||
getApplicationsByServiceId: builder.query<ApplicationsServiceType[], { id : number}>({
|
||||
query: (id) => ({
|
||||
url: apiPaths.getApplicationsByServiceId,
|
||||
data: id
|
||||
}),
|
||||
}),
|
||||
|
||||
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]
|
||||
}),
|
||||
invalidatesTags: ['Applications']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export default applicationsApi
|
||||
@@ -0,0 +1,30 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react'
|
||||
import { apiPaths } from '@constants/api/apiPaths.ts'
|
||||
|
||||
import {
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType,
|
||||
} from '@pages/ApplicationsPage/applications.type.ts'
|
||||
|
||||
import { axiosBaseQuery } from '@utils/apiUtils.ts'
|
||||
|
||||
const tokensApi = createApi({
|
||||
reducerPath: 'tokensApi',
|
||||
refetchOnFocus: true,
|
||||
tagTypes: ['Tokens'],
|
||||
baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseSystemUrl }),
|
||||
endpoints: (builder) => ({
|
||||
createToken: builder.mutation<
|
||||
ApplicationTokenType,
|
||||
NewApplicationTokenType
|
||||
>({
|
||||
query: ( NewApplicationTokenType) => ({
|
||||
url: apiPaths.createToken,
|
||||
data: NewApplicationTokenType
|
||||
}),
|
||||
invalidatesTags: ['Tokens']
|
||||
}),
|
||||
})
|
||||
})
|
||||
|
||||
export default tokensApi
|
||||
@@ -12,6 +12,8 @@ import userServiceApi from '@services/userService.ts'
|
||||
import routeApi from '@services/routeService.ts'
|
||||
|
||||
import profileReducer from './redusers/ProfileSlice.ts'
|
||||
import applicationsGroupApi from '@services/applicationsGroupService.ts'
|
||||
import applicationsApi from '@services/applicationsService.ts'
|
||||
|
||||
export interface ContextProps {
|
||||
setTheme: Dispatch<
|
||||
@@ -31,7 +33,9 @@ const rootReducer = combineReducers({
|
||||
[securityLogServiceApi.reducerPath]: securityLogServiceApi.reducer,
|
||||
[appApi.reducerPath]: appApi.reducer,
|
||||
[accessListApi.reducerPath]: accessListApi.reducer,
|
||||
[routeApi.reducerPath]: routeApi.reducer
|
||||
[routeApi.reducerPath]: routeApi.reducer,
|
||||
[applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer,
|
||||
[applicationsApi.reducerPath]: applicationsApi.reducer,
|
||||
})
|
||||
|
||||
export const setupStore = () =>
|
||||
@@ -46,7 +50,9 @@ export const setupStore = () =>
|
||||
accessListApi.middleware,
|
||||
routeApi.middleware,
|
||||
userServiceApi.middleware,
|
||||
sessionServiceApi.middleware
|
||||
sessionServiceApi.middleware,
|
||||
applicationsGroupApi.middleware,
|
||||
applicationsApi.middleware
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user