Добавлен метод окрытия селектора скважин в LayoutPropsContext

This commit is contained in:
goodmice 2022-12-26 17:57:56 +05:00
parent a01d0fb095
commit b3954c1091
No known key found for this signature in database
GPG Key ID: EA4AA16454AC96C8
4 changed files with 17 additions and 7 deletions

View File

@ -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>

View File

@ -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 }
}
/** Контекст для блока справа от крошек на страницах скважин и админки */

View File

@ -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()

View File

@ -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 () => {