diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af2902..ef6ab92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.10.1 +- В index.html добавлен config.js +- Добавлены динамические стили для админок ## 0.10.0 - - Добавлена страница 'Модули' ## 0.9.0 diff --git a/index.html b/index.html index 11c6825..e6b7b28 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,9 @@ - + + Панель администратора +
diff --git a/package.json b/package.json index a74eb1a..cfe918c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.10.0", + "version": "0.10.1", "type": "module", "scripts": { "start": "vite", diff --git a/public/config.js b/public/config.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Connections/connections.scss b/src/components/Connections/connections.scss index f9484c8..67f6a98 100644 --- a/src/components/Connections/connections.scss +++ b/src/components/Connections/connections.scss @@ -7,7 +7,7 @@ &__wrap-table { overflow-x: scroll; - height: calc(100vh - 30px); + height: calc(100vh - 100px); } } diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 41f8b12..b32fc0e 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -13,6 +13,7 @@ import { localStorageKeys } from '@constants/localStorageKeys.ts' import DefaultUser from '@components/Icons/DefaultUser.tsx' import { MenuItemKeysType, + MenuItemLabelsType, MenuItemType, menuKeys } from '@components/Layout/layout.type.ts' @@ -23,13 +24,15 @@ import { useAppDispatch, useAppSelector } from '@hooks/redux.ts' import useLogout from '@hooks/useLogout.tsx' import useRole from '@hooks/useRole.tsx' -import { fetchProfile } from '@stores/redusers/ActionCreators.ts' +import { fetchProfile, fetchUI } from '@stores/redusers/ActionCreators.ts' import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts' import { routePaths } from '@routes/routePaths.ts' import { PermissionKeysType } from '@type/roles.type.ts' +import Header from 'src/widgets/Header' + import './layout.scss' const { Content, Sider } = Layout @@ -39,6 +42,7 @@ const LayoutComponent = () => { const [selectedMenuKeys, setSelectedMenuKeys] = useState( [] ) + const [title, setTitle] = useState('') const [openKeys, setOpenKeys] = useState([]) const dispatch = useAppDispatch() const { @@ -143,6 +147,7 @@ const LayoutComponent = () => { useEffect(() => { if (userToken) { dispatch(fetchProfile()) + dispatch(fetchUI()) } }, []) @@ -152,6 +157,7 @@ const LayoutComponent = () => { const menuItem = menuKeys[menuKey] if (menuItem) { + setTitle(MenuItemLabelsType[menuItem.key]) setSelectedMenuKeys([menuItem.key]) setOpenKeys(menuItem.parent) } @@ -197,37 +203,40 @@ const LayoutComponent = () => { } return ( - - {status === StateProfileStatus.pending ? ( - - ) : ( - <> - setCollapsed(value)} - > - setOpenKeys(keys)} - openKeys={openKeys} - selectedKeys={selectedMenuKeys} - onClick={handlerOnClickMenu} +
+
+ + {status === StateProfileStatus.pending ? ( + + ) : ( + <> + - - - - - - - - )} - + collapsible + collapsed={collapsed} + onCollapse={(value) => setCollapsed(value)} + > + setOpenKeys(keys)} + openKeys={openKeys} + selectedKeys={selectedMenuKeys} + onClick={handlerOnClickMenu} + theme="light" + mode="inline" + items={menuItems} + /> + + + + + + + + )} + +
) } diff --git a/src/components/Layout/layout.scss b/src/components/Layout/layout.scss index f1254b7..06a9eda 100644 --- a/src/components/Layout/layout.scss +++ b/src/components/Layout/layout.scss @@ -1,7 +1,7 @@ @import 'src/constants/style/styleConst'; .layout { - min-height: 100vh !important; + min-height: calc(100vh - 65px) !important; position: relative; .hide-item { diff --git a/src/components/Layout/layout.type.ts b/src/components/Layout/layout.type.ts index 493d35e..860ba52 100644 --- a/src/components/Layout/layout.type.ts +++ b/src/components/Layout/layout.type.ts @@ -9,7 +9,18 @@ export enum MenuItemKeysType { logout = 'logout', profile = 'profile', modules = 'modules', - applications = 'applications', + applications = 'applications' +} +export enum MenuItemLabelsType { + users = 'Пользователи', + sessions = 'Пользовательские сессии', + securityLog = 'Просмотр журналов ИБ', + appAccess = 'Доступы приложений', + roles = 'Роли', + profile = 'Профиль', + modules = 'Модули', + applications = 'Группа приложений', + logout = 'Выход', } interface MenuItem { diff --git a/src/components/app.scss b/src/components/app.scss index 6095f4b..d26913c 100644 --- a/src/components/app.scss +++ b/src/components/app.scss @@ -9,7 +9,6 @@ .app{ overflow: hidden; height: 100vh; - padding: 0 $basic-padding; min-height: 0; min-width: 500px; } diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index 1d66e55..17155ac 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -44,6 +44,7 @@ type PathKeys = | 'getTokensByAppId' | 'revokeTokens' | 'revokeTokensForApp' + | 'getUI' export const apiPaths: Record = { baseUrl: '/api/kkd-configuration-service', @@ -61,6 +62,7 @@ export const apiPaths: Record = { logout: '/api/admin/auth/logout', // ======= PROFILE ====== getProfile: '/api/admin/user/get_profile', + getUI: '/api/admin/user/get_design', // ======= USERS ====== getUsers: '/get_users', createUser: '/create_user', @@ -99,7 +101,7 @@ export const apiPaths: Record = { getServicesByDomainId: '/service/get_services_by_domain_id', // ======= TOKENS ====== createToken: '/token/create_token', - getTokensByAppId: '/token/get_tokens_by_app_id', + getTokensByAppId: '/token/get_tokens_by_app_id', revokeTokens: '/token/revoke_tokens', revokeTokensForApp: '/token/revoke_tokens_for_app' } diff --git a/src/pages/ApplicationsPage/applications-page.scss b/src/pages/ApplicationsPage/applications-page.scss index d8ace88..fdb1875 100644 --- a/src/pages/ApplicationsPage/applications-page.scss +++ b/src/pages/ApplicationsPage/applications-page.scss @@ -1,7 +1,7 @@ @import "src/constants/style/styleConst"; .applications-page { - height: 100vh; + height: 100%; .three-columns { display: flex; background: #fff; diff --git a/src/pages/ApplicationsPage/index.tsx b/src/pages/ApplicationsPage/index.tsx index 81f983f..c20cd17 100644 --- a/src/pages/ApplicationsPage/index.tsx +++ b/src/pages/ApplicationsPage/index.tsx @@ -55,7 +55,6 @@ const ApplicationsPage = () => { applicationsGroupApi.useRemoveApplicationsGroupMutation() const isPageAvailable = hasPermission(PermissionKeysType.read) - const hasRevokePermission = hasPermission(PermissionKeysType.write) useEffect(() => { if (!isPageAvailable) { diff --git a/src/pages/ModulesPage/modules-page.scss b/src/pages/ModulesPage/modules-page.scss index d24b813..2555b1f 100644 --- a/src/pages/ModulesPage/modules-page.scss +++ b/src/pages/ModulesPage/modules-page.scss @@ -5,6 +5,7 @@ &__tabs { overflow-x: scroll; + width: 100%; } .ant-list-item { diff --git a/src/pages/ProfilePage/profile-page.type.ts b/src/pages/ProfilePage/profile-page.type.ts index 03aff61..8bb4565 100644 --- a/src/pages/ProfilePage/profile-page.type.ts +++ b/src/pages/ProfilePage/profile-page.type.ts @@ -15,3 +15,14 @@ export type ProfileType = { status: StateProfileStatus error: string } + +export type UIDataType = { + name: string + primaryColor: string +} + +export type UIType = { + ui: UIDataType + status: StateProfileStatus + error: string +} diff --git a/src/stores/index.tsx b/src/stores/index.tsx index a2f01c1..349e06a 100644 --- a/src/stores/index.tsx +++ b/src/stores/index.tsx @@ -5,6 +5,8 @@ import { createContext, Dispatch, SetStateAction } from 'react' import accessListApi from '@services/accessListService.ts' import appApi from '@services/appService.ts' +import applicationsGroupApi from '@services/applicationsGroupService.ts' +import applicationsApi from '@services/applicationsService.ts' import modulesServiceApi from '@services/modulesService.ts' import roleApi from '@services/roleService.ts' import routeApi from '@services/routeService.ts' @@ -13,8 +15,7 @@ import sessionServiceApi from '@services/sessionService.ts' import userServiceApi from '@services/userService.ts' import profileReducer from './redusers/ProfileSlice.ts' -import applicationsGroupApi from '@services/applicationsGroupService.ts' -import applicationsApi from '@services/applicationsService.ts' +import UIReducer from './redusers/UISlice.ts' export interface ContextProps { setTheme: Dispatch< @@ -28,6 +29,7 @@ export const Context = createContext({ const rootReducer = combineReducers({ profileReducer, + UIReducer, [roleApi.reducerPath]: roleApi.reducer, [userServiceApi.reducerPath]: userServiceApi.reducer, [sessionServiceApi.reducerPath]: sessionServiceApi.reducer, @@ -37,7 +39,7 @@ const rootReducer = combineReducers({ [routeApi.reducerPath]: routeApi.reducer, [modulesServiceApi.reducerPath]: modulesServiceApi.reducer, [applicationsGroupApi.reducerPath]: applicationsGroupApi.reducer, - [applicationsApi.reducerPath]: applicationsApi.reducer, + [applicationsApi.reducerPath]: applicationsApi.reducer }) export const setupStore = () => diff --git a/src/stores/redusers/ActionCreators.ts b/src/stores/redusers/ActionCreators.ts index 8b249aa..e2547cf 100644 --- a/src/stores/redusers/ActionCreators.ts +++ b/src/stores/redusers/ActionCreators.ts @@ -2,11 +2,15 @@ import { createAsyncThunk } from '@reduxjs/toolkit' import { apiPaths } from '@constants/api/apiPaths.ts' -import { ProfileDataType } from '@pages/ProfilePage/profile-page.type.ts' +import { + ProfileDataType, + UIDataType +} from '@pages/ProfilePage/profile-page.type.ts' + +import { initUI } from '@utils/UIUtiles.tsx' import { apiService } from '@services/apiService.ts' - export const fetchProfile = createAsyncThunk( 'profile/fetchProfile', async (_, { rejectWithValue }) => { @@ -20,3 +24,15 @@ export const fetchProfile = createAsyncThunk( } } ) +export const fetchUI = createAsyncThunk( + 'ui/fetchUI', + async (_, { rejectWithValue }) => { + try { + const response = await apiService.post(apiPaths.getUI) + initUI(response.data) + return response.data + } catch (error) { + return rejectWithValue(error) + } + } +) diff --git a/src/stores/redusers/UISlice.ts b/src/stores/redusers/UISlice.ts new file mode 100644 index 0000000..196594c --- /dev/null +++ b/src/stores/redusers/UISlice.ts @@ -0,0 +1,49 @@ +import { + ActionReducerMapBuilder, + createSlice, + PayloadAction +} from '@reduxjs/toolkit' + +import { UIDataType, UIType } from '@pages/ProfilePage/profile-page.type.ts' + +import { StateProfileStatus } from '@stores/redusers/ProfileSlice.ts' + +import { fetchUI } from './ActionCreators.ts' + +export const initialState: UIType = { + ui: { + name: '', + primaryColor: '' + }, + status: StateProfileStatus.notInit, + error: '' +} + +export const UISlice = createSlice({ + name: 'ui', + initialState, + reducers: { + clearUI(state) { + state.ui = initialState.ui + } + }, + extraReducers: (builder: ActionReducerMapBuilder) => { + builder + .addCase( + fetchUI.fulfilled, + (state, action: PayloadAction) => { + state.status = StateProfileStatus.resolved + state.ui = { ...action.payload } + } + ) + .addCase(fetchUI.pending, (state) => { + state.status = StateProfileStatus.pending + }) + .addCase(fetchUI.rejected, (state, action: any) => { + state.status = StateProfileStatus.rejected + state.error = action.payload + }) + } +}) + +export default UISlice.reducer diff --git a/src/utils/UIUtiles.tsx b/src/utils/UIUtiles.tsx new file mode 100644 index 0000000..317ab96 --- /dev/null +++ b/src/utils/UIUtiles.tsx @@ -0,0 +1,26 @@ +import { UIDataType } from '@pages/ProfilePage/profile-page.type.ts' + +const drawSVG = (color: string) => + `` + +export const createSVG = (color: string) => { + const svgString = drawSVG(color) + return btoa(svgString) // base64 +} + +export const initSVG = (color: string) => { + const favicon = document.createElement('link') + favicon.id = 'favicon' + favicon.rel = 'shortcut icon' + favicon.type = 'image/x-icon' + favicon.href = `data:image/svg+xml;base64,${createSVG(color)}` + return favicon +} + +export const initUI = (ui: UIDataType) => { + let favicon = document.getElementById('favicon') + favicon = initSVG(ui.primaryColor) + const titles = document.getElementsByTagName('title') + document.head.insertBefore(favicon, titles[0]) + document.title = `${ui.name} — MSP` +} diff --git a/src/widgets/AccessListTree/access-list-tree.scss b/src/widgets/AccessListTree/access-list-tree.scss index 144b8b7..5a9d07f 100644 --- a/src/widgets/AccessListTree/access-list-tree.scss +++ b/src/widgets/AccessListTree/access-list-tree.scss @@ -1,5 +1,5 @@ .access-list-tree{ overflow-y: scroll; - height: calc(100vh - 130px); + height: calc(100vh - 250px); } diff --git a/src/widgets/Header/header.scss b/src/widgets/Header/header.scss new file mode 100644 index 0000000..4413b11 --- /dev/null +++ b/src/widgets/Header/header.scss @@ -0,0 +1,9 @@ +.header { + display: flex; + align-items: center; + padding: 0 28px; + width: 100%; + height: 65px; + justify-content: space-between; + box-sizing: border-box; +} \ No newline at end of file diff --git a/src/widgets/Header/header.type.ts b/src/widgets/Header/header.type.ts new file mode 100644 index 0000000..d366380 --- /dev/null +++ b/src/widgets/Header/header.type.ts @@ -0,0 +1,3 @@ +export interface HeaderPropsType { + title: string +} \ No newline at end of file diff --git a/src/widgets/Header/index.tsx b/src/widgets/Header/index.tsx new file mode 100644 index 0000000..ad988a6 --- /dev/null +++ b/src/widgets/Header/index.tsx @@ -0,0 +1,45 @@ +import { HomeOutlined } from '@ant-design/icons' +import { Breadcrumb } from 'antd' + +import { HeaderPropsType } from '@widgets/Header/header.type.ts' + +import { useAppSelector } from '@hooks/redux.ts' + +import './header.scss' + +const Header = ({ title }: HeaderPropsType) => { + const { + ui: { name, primaryColor } + } = useAppSelector((state) => state.UIReducer) + + return ( +
+
+ + + Главная + + ) + }, + { + title: {title} + } + ]} + /> +
+ {name} +
+ ) +} + +export default Header diff --git a/src/widgets/SelectedAccessMethod/selected-access-method.scss b/src/widgets/SelectedAccessMethod/selected-access-method.scss index ccc62b0..fdd14ec 100644 --- a/src/widgets/SelectedAccessMethod/selected-access-method.scss +++ b/src/widgets/SelectedAccessMethod/selected-access-method.scss @@ -8,6 +8,6 @@ border: 1px dashed $grey; overflow-y: scroll; - height: calc(100vh - 130px); + height: calc(100vh - 160px); }