From ebe3a50fbed18979fe7075bbd9228c04a7a7cd55 Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 5 Dec 2022 21:07:17 +0500 Subject: [PATCH] =?UTF-8?q?WellTreeSelector=20=D0=B4=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=BD=20=D0=B4=D0=BB=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BD=D0=B5=D1=86?= =?UTF-8?q?=D0=B8=D1=84=D1=80=D0=BE=D0=B2=D1=8B=D0=BC=D0=B8=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8=20=D0=B2=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=81=D1=82=D0=B0=D1=85=20=D1=81=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/selectors/WellTreeSelector.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/selectors/WellTreeSelector.tsx b/src/components/selectors/WellTreeSelector.tsx index ceb1b1f..a5b8962 100755 --- a/src/components/selectors/WellTreeSelector.tsx +++ b/src/components/selectors/WellTreeSelector.tsx @@ -12,12 +12,19 @@ import { ReactComponent as ClusterIcon } from '@images/ClusterIcon.svg' import '@styles/wellTreeSelect.css' +/** + * Для поиска в URL текущего раздела по шаблону `/{type}/{id}` + * + * Если найдено совпадение может вернуть 1 или 2 группы соответственно + */ +const URL_REGEX = /^\/([^\/?#]+)(?:\/([^\/?#]+))?/ + export const getWellState = (idState?: number): WellIconState => idState === 1 ? 'active' : 'unknown' export const checkIsWellOnline = (lastTelemetryDate: unknown): boolean => isRawDate(lastTelemetryDate) && (Date.now() - +new Date(lastTelemetryDate) < 600_000) const getKeyByUrl = (url?: string): [Key | null, string | null] => { - const result = url?.match(/^\/([^\/]+)\/([^\/?]+)/) // pattern "/:type/:id" + const result = url?.match(URL_REGEX) // pattern "/:type/:id" if (!result) return [null, null] return [result[0], result[1]] } @@ -137,8 +144,8 @@ export const WellTreeSelector = memo(({ expand, current, }, [wellsTree]) const onSelect = useCallback((value: Key[]): void => { - const newRoot = /\/(\w+)\/\d+/.exec(String(value)) - const oldRoot = /\/(\w+)(?:\/\d+)?/.exec(location.pathname) + const newRoot = URL_REGEX.exec(String(value)) + const oldRoot = URL_REGEX.exec(location.pathname) if (!newRoot || !oldRoot) return let newPath = newRoot[0]