From 9202641929779e10798c133edfc949e036a526f4 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Wed, 19 Feb 2025 11:43:42 -0800 Subject: [PATCH] fix(weave): smallref produces correct link for op versions --- .../Home/Browse2/CellValue.tsx | 10 ++++-- weave-js/src/react.tsx | 31 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse2/CellValue.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse2/CellValue.tsx index 08da145f6c66..93ce655d7323 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse2/CellValue.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse2/CellValue.tsx @@ -1,7 +1,7 @@ import {Box} from '@mui/material'; import React from 'react'; -import {parseRef} from '../../../../react'; +import {parseRef, parseWeaveRef} from '../../../../react'; import {isArtifactRef, isWeaveRef} from '../Browse3/filters/common'; import {ValueViewNumber} from '../Browse3/pages/CallPage/ValueViewNumber'; import { @@ -27,7 +27,13 @@ export const CellValue = ({value}: CellValueProps) => { if (value === null) { return null; } - if (isWeaveRef(value) || isArtifactRef(value)) { + if (isWeaveRef(value)) { + const parsed = parseWeaveRef(value); + if (parsed.weaveKind === 'op') { + return ; + } + return ; + } else if (isArtifactRef(value)) { return ; } if (typeof value === 'boolean') { diff --git a/weave-js/src/react.tsx b/weave-js/src/react.tsx index e69dc5a6de77..14721412e143 100644 --- a/weave-js/src/react.tsx +++ b/weave-js/src/react.tsx @@ -550,6 +550,21 @@ const RE_WEAVE_CALL_REF_PATHNAME = new RegExp( '$', // End of the string ].join('') ); +const RE_WEAVE_OP_VERSION_REF_PATHNAME = new RegExp( + [ + '^', // Start of the string + PATTERN_ENTITY, + '/', + PATTERN_PROJECT, + '/op/', + '([a-zA-Z0-9-_/. ]{1,128})', // Op name + ':', + '([*]|[a-zA-Z0-9]+)', // Op version, allowing '*' for any version + '/?', // Ref extra portion is optional + PATTERN_REF_EXTRA, // Optional ref extra + '$', // End of the string + ].join('') +); export const parseRefMaybe = (s: string): ObjectRef | null => { try { @@ -611,7 +626,7 @@ export const parseRef = (ref: string): ObjectRef => { throw new Error(`Unknown protocol: ${url.protocol}`); }; -const parseWeaveRef = (ref: string): WeaveObjectRef => { +export const parseWeaveRef = (ref: string): WeaveObjectRef => { const trimmed = ref.slice(WEAVE_REF_PREFIX.length); const tableMatch = trimmed.match(RE_WEAVE_TABLE_REF_PATHNAME); if (tableMatch !== null) { @@ -639,6 +654,20 @@ const parseWeaveRef = (ref: string): WeaveObjectRef => { artifactRefExtra: '', }; } + const opVersionMatch = trimmed.match(RE_WEAVE_OP_VERSION_REF_PATHNAME); + if (opVersionMatch !== null) { + const [entityName, projectName, opName, opVersion] = + opVersionMatch.slice(1); + return { + scheme: 'weave', + entityName, + projectName, + weaveKind: 'op' as WeaveKind, + artifactName: opName, + artifactVersion: opVersion, + artifactRefExtra: '', + }; + } const match = trimmed.match(RE_WEAVE_OBJECT_REF_PATHNAME); if (match === null) { throw new Error('Invalid weave ref uri: ' + ref);