forked from ddrilling/asb_cloud_front
Добавлен метод окрытия селектора скважин в LayoutPropsContext
This commit is contained in:
parent
a01d0fb095
commit
b3954c1091
@ -55,6 +55,8 @@ const _LayoutPortal = memo(() => {
|
||||
|
||||
const setLayoutProps = useCallback((props: LayoutPortalProps) => setProps({ ...defaultProps, ...props}), [])
|
||||
|
||||
const layoutPropsValue = useMemo(() => ({ setLayoutProps, openWellTreeSelector: () => setWellsTreeOpen(true) }), [setLayoutProps])
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof showSelector === 'boolean')
|
||||
setWellsTreeOpen(showSelector)
|
||||
@ -123,7 +125,7 @@ const _LayoutPortal = memo(() => {
|
||||
{topRightBlock}
|
||||
</div>
|
||||
)}
|
||||
<LayoutPropsContext.Provider value={setLayoutProps}>
|
||||
<LayoutPropsContext.Provider value={layoutPropsValue}>
|
||||
<Suspense fallback={fallback ?? <SuspenseFallback style={{ minHeight: '100%' }} />}>
|
||||
<Outlet />
|
||||
</Suspense>
|
||||
|
@ -2,22 +2,30 @@ import { createContext, useContext, useEffect } from 'react'
|
||||
|
||||
import { LayoutPortalProps } from '@components/LayoutPortal'
|
||||
|
||||
export type LayoutPropsContext = {
|
||||
setLayoutProps: (props: LayoutPortalProps) => void
|
||||
openWellTreeSelector: () => void
|
||||
}
|
||||
|
||||
/** Контекст метода редактирования параметров заголовка и меню */
|
||||
export const LayoutPropsContext = createContext<(props: LayoutPortalProps) => void>(() => {})
|
||||
export const LayoutPropsContext = createContext<LayoutPropsContext>({
|
||||
setLayoutProps: () => {},
|
||||
openWellTreeSelector: () => {},
|
||||
})
|
||||
|
||||
/**
|
||||
* Получить метод задания параметров заголовка и меню
|
||||
*
|
||||
* @returns Получить метод задания параметров заголовка и меню
|
||||
*/
|
||||
export const useLayoutProps = (props?: LayoutPortalProps) => {
|
||||
const setLayoutProps = useContext(LayoutPropsContext)
|
||||
export const useLayoutProps = (props?: LayoutPortalProps): LayoutPropsContext => {
|
||||
const { setLayoutProps, ...other } = useContext(LayoutPropsContext)
|
||||
|
||||
useEffect(() => {
|
||||
if (props) setLayoutProps(props)
|
||||
}, [setLayoutProps, props])
|
||||
|
||||
return setLayoutProps
|
||||
return { setLayoutProps, ...other }
|
||||
}
|
||||
|
||||
/** Контекст для блока справа от крошек на страницах скважин и админки */
|
||||
|
@ -16,7 +16,7 @@ const breadcrumb = makeMenuBreadcrumbItemsRender(menuItems, /^\/deposit\/[^\/#?]
|
||||
const Deposit = memo(() => {
|
||||
const { '*': param } = useParams()
|
||||
|
||||
const setLayoutProps = useLayoutProps()
|
||||
const { setLayoutProps } = useLayoutProps()
|
||||
const deposits = useDepositList()
|
||||
|
||||
const root = useRootPath()
|
||||
|
@ -50,7 +50,7 @@ const Well = memo(() => {
|
||||
const root = useRootPath()
|
||||
const rootPath = useMemo(() => `${root}/well/${idWell}`, [root, idWell])
|
||||
|
||||
const setLayoutProps = useLayoutProps()
|
||||
const { setLayoutProps } = useLayoutProps()
|
||||
|
||||
const updateWell = useCallback((data) => invokeWebApiWrapperAsync(
|
||||
async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user