Косметические улучшения

This commit is contained in:
Александр Сироткин 2022-01-12 23:58:14 +05:00
parent b2a8189ed8
commit e80f56ef57
9 changed files with 22914 additions and 78 deletions

22891
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
import React from 'react' import React from 'react'
import { Menu } from 'antd' import { Menu, MenuItemProps } from 'antd'
import { Role, Permission, hasPermission, isInRole } from '../../utils/permissions' import { Role, Permission, hasPermission, isInRole } from '../../utils/permissions'
type PrivateMenuItemProps = { type PrivateMenuItemProps = MenuItemProps & {
roles?: Role[] | Role roles?: Role[] | Role
permission?: Permission permission?: Permission
[props: string]: any
} }
export const PrivateMenuItem: React.FC<PrivateMenuItemProps> = ({ roles, permission, mixing, ...props }) => export const PrivateMenuItem: React.FC<PrivateMenuItemProps> = ({ roles, permission, ...props }) =>
hasPermission(permission) && isInRole(roles) ? <Menu.Item {...props}/> : null hasPermission(permission) && isInRole(roles) ? <Menu.Item {...props}/> : null
export default PrivateMenuItem

View File

@ -1,26 +1,30 @@
import React from 'react' import { FC, ReactNode } from 'react'
import { StaticContext } from 'react-router' import { Location } from 'history'
import { Route, Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, Route, RouteProps } from 'react-router-dom'
import { Role, Permission, hasPermission, isInRole } from '../../utils/permissions' import { Role, Permission, hasPermission, isInRole } from '../../utils/permissions'
import { getUserToken } from '../../utils/storage' import { getUserToken } from '../../utils/storage'
type PrivateRouteProps = { export type PrivateRouteProps = RouteProps & {
roles: Role[] | Role roles: Role[] | Role
permission?: Permission permission?: Permission
component?: React.ComponentType<any> | React.ComponentType<RouteComponentProps<any, StaticContext, unknown>> children?: ReactNode
children?: React.ReactNode redirect?: (location?: Location<unknown>) => ReactNode
[other: string]: any
} }
export const PrivateRoute: React.FC<PrivateRouteProps> = ({ permission, roles, component, children, ...other }) => { export const defaultRedirect = (location?: Location<unknown>) => (
<Redirect to={{ pathname: '/login', state: { from: location } }} />
)
export const PrivateRoute: FC<PrivateRouteProps> = ({ permission, roles, component, children, redirect = defaultRedirect, ...other }) => {
const available = getUserToken() && (hasPermission(permission) && isInRole(roles)) const available = getUserToken() && (hasPermission(permission) && isInRole(roles))
return ( return (
<Route {...other} <Route {...other}
component={available ? component : undefined} component={available ? component : undefined}
render={({ location }) => available ? children : ( render={({ location }) => available ? children : redirect(location)}
<Redirect to={{ pathname: '/login', state: { from: location } }} />
)}
/> />
) )
} }
export default PrivateRoute

View File

@ -15,7 +15,7 @@ import { min1 } from '../../utils/validationRules'
import { coordsFixed } from './DepositController' import { coordsFixed } from './DepositController'
export default function ClusterController() { export const ClusterController = () => {
const [deposits, setDeposits] = useState([]) const [deposits, setDeposits] = useState([])
const [clusters, setClusters] = useState([]) const [clusters, setClusters] = useState([])
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
@ -78,3 +78,5 @@ export default function ClusterController() {
</LoaderPortal> </LoaderPortal>
) )
} }
export default ClusterController

View File

@ -54,6 +54,7 @@ export const PermissionController = () => {
size={'small'} size={'small'}
columns={columns} columns={columns}
dataSource={permissions} dataSource={permissions}
pagination={{ showSizeChanger: true }}
onRowAdd={makeActionHandler('insert', handlerProps)} onRowAdd={makeActionHandler('insert', handlerProps)}
onRowEdit={makeActionHandler('put', handlerProps)} onRowEdit={makeActionHandler('put', handlerProps)}
onRowDelete={makeActionHandler('delete', handlerProps)} onRowDelete={makeActionHandler('delete', handlerProps)}

View File

@ -1,4 +1,4 @@
import { useEffect, useState } from 'react' import { memo, useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
@ -18,11 +18,11 @@ const columns = [
] ]
const pagination = { const pagination = {
pageSize: 16, defaultPageSize: 16,
showSizeChanger: true, showSizeChanger: true,
} }
export const VisitLog = () => { export const VisitLog = memo(() => {
const [logData, setLogData] = useState([]) const [logData, setLogData] = useState([])
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
@ -48,6 +48,6 @@ export const VisitLog = () => {
/> />
</LoaderPortal> </LoaderPortal>
) )
} })
export default VisitLog export default VisitLog

View File

@ -24,14 +24,17 @@ export const documentCategories = [
const getUserCategories = () => documentCategories.filter(cat => isInRole(cat.roles)) const getUserCategories = () => documentCategories.filter(cat => isInRole(cat.roles))
export const makeMenuItems = (root, cats) => { export const makeMenuItems = (root, cats) => (cats ?? getUserCategories()).map(category => (
const categories = cats ?? getUserCategories() <PrivateMenuItem
return categories.map(category => ( key={`${category.key}`}
<PrivateMenuItem className={'ant-menu-item'} key={`${category.key}`} icon={<FolderOutlined/>}> className={'ant-menu-item'}
<Link to={{ pathname: `${root}/${category.key}` }}>{category.title}</Link> icon={<FolderOutlined/>}
</PrivateMenuItem> permission={category.permission}
)) roles={category.roles}
} >
<Link to={{ pathname: `${root}/${category.key}` }}>{category.title}</Link>
</PrivateMenuItem>
))
export const MenuDocuments = memo(({ idWell }) => { export const MenuDocuments = memo(({ idWell }) => {
const { category } = useParams() const { category } = useParams()

View File

@ -1,5 +1,5 @@
import {Layout, Menu} from "antd"; import {Layout, Menu} from "antd";
import {Switch, Link, Route, useParams} from "react-router-dom"; import {Switch, Link, Route, useParams, Redirect} from "react-router-dom";
import { FolderOutlined } from "@ant-design/icons"; import { FolderOutlined } from "@ant-design/icons";
import TelemetryAnalysisOperationsSummary from "./TelemetryAnalysisOperationsSummary"; import TelemetryAnalysisOperationsSummary from "./TelemetryAnalysisOperationsSummary";
import TelemetryAnalysisOperationsToInterval from "./TelemetryAnalysisOperationsToInterval"; import TelemetryAnalysisOperationsToInterval from "./TelemetryAnalysisOperationsToInterval";
@ -14,25 +14,25 @@ export default function TelemetryAnalysis({idWell}) {
return (<> return (<>
<Menu <Menu
mode="horizontal" mode={'horizontal'}
selectable={true} selectable={true}
className="well_menu" className={'well_menu'}
selectedKeys={[tab]}> selectedKeys={[tab]}>
<Menu.Item key="depthToDay" icon={<FolderOutlined />}> <Menu.Item key={'depthToDay'} icon={<FolderOutlined />}>
<Link to={`${rootPath}/depthToDay`}>Глубина-день</Link> <Link to={`${rootPath}/depthToDay`}>Глубина-день</Link>
</Menu.Item> </Menu.Item>
<Menu.Item key="depthToInterval" icon={<FolderOutlined />}> <Menu.Item key={'depthToInterval'} icon={<FolderOutlined />}>
<Link to={`${rootPath}/depthToInterval`}>Глубина-интервал</Link> <Link to={`${rootPath}/depthToInterval`}>Глубина-интервал</Link>
</Menu.Item> </Menu.Item>
<Menu.Item key="operationsSummary" icon={<FolderOutlined />}> <Menu.Item key={'operationsSummary'} icon={<FolderOutlined />}>
<Link to={`${rootPath}/operationsSummary`}>Все операции</Link> <Link to={`${rootPath}/operationsSummary`}>Все операции</Link>
</Menu.Item> </Menu.Item>
<Menu.Item key="operationsToInterval" icon={<FolderOutlined />}> <Menu.Item key={'operationsToInterval'} icon={<FolderOutlined />}>
<Link to={`${rootPath}/operationsToInterval`}>Операции-интервал</Link> <Link to={`${rootPath}/operationsToInterval`}>Операции-интервал</Link>
</Menu.Item> </Menu.Item>
</Menu> </Menu>
<Layout> <Layout>
<Content className="site-layout-background"> <Content className={'site-layout-background'}>
<Switch> <Switch>
<Route path={`${rootPath}/depthToDay`}> <Route path={`${rootPath}/depthToDay`}>
<TelemetryAnalysisDepthToDay idWell={idWell}/> <TelemetryAnalysisDepthToDay idWell={idWell}/>
@ -46,6 +46,9 @@ export default function TelemetryAnalysis({idWell}) {
<Route path={`${rootPath}/operationsToInterval`}> <Route path={`${rootPath}/operationsToInterval`}>
<TelemetryAnalysisOperationsToInterval idWell={idWell}/> <TelemetryAnalysisOperationsToInterval idWell={idWell}/>
</Route> </Route>
<Route path={`/`}>
<Redirect to={`${rootPath}/depthToDay`} />
</Route>
</Switch> </Switch>
</Content> </Content>
</Layout> </Layout>

View File

@ -1,12 +1,13 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from 'react'
import { import {
EditableTable,
makeNumericMinMax, makeNumericMinMax,
makeNumericStartEnd makeNumericStartEnd,
} from '../../components/Table' } from '../../components/Table'
import LoaderPortal from '../../components/LoaderPortal' import LoaderPortal from '../../components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '../../components/factory' import { invokeWebApiWrapperAsync } from '../../components/factory'
import { EditableTable } from '../../components/Table'
import { DrillFlowChartService } from '../../services/api' import { DrillFlowChartService } from '../../services/api'
import { arrayOrDefault } from '../../utils'
const columns = [ const columns = [
makeNumericStartEnd('Глубина, м', 'depth'), makeNumericStartEnd('Глубина, м', 'depth'),
@ -17,14 +18,14 @@ const columns = [
makeNumericMinMax('Расход, л/с', 'flow') makeNumericMinMax('Расход, л/с', 'flow')
] ]
export const DrillProcessFlow = ({idWell}) => { export const DrillProcessFlow = ({ idWell }) => {
const [flows, setFlows] = useState([]) const [flows, setFlows] = useState([])
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const updateFlows = () => invokeWebApiWrapperAsync( const updateFlows = () => invokeWebApiWrapperAsync(
async () => { async () => {
const flows = await DrillFlowChartService.get(idWell) const flows = await DrillFlowChartService.get(idWell)
setFlows(Array.isArray(flows) ? flows : []) setFlows(arrayOrDefault(flows))
}, },
setShowLoader, setShowLoader,
'Не удалось загрузить режимно-технологическую карту скважины' 'Не удалось загрузить режимно-технологическую карту скважины'