Skip to content

Commit

Permalink
fix(weave): smallref produces correct link for op versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsherma committed Feb 19, 2025
1 parent dac92d0 commit 9202641
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -27,7 +27,13 @@ export const CellValue = ({value}: CellValueProps) => {
if (value === null) {
return <ValueViewPrimitive>null</ValueViewPrimitive>;
}
if (isWeaveRef(value) || isArtifactRef(value)) {
if (isWeaveRef(value)) {
const parsed = parseWeaveRef(value);
if (parsed.weaveKind === 'op') {
return <SmallRef objRef={parsed} wfTable="OpVersion" />;
}
return <SmallRef objRef={parsed} />;
} else if (isArtifactRef(value)) {
return <SmallRef objRef={parseRef(value)} />;
}
if (typeof value === 'boolean') {
Expand Down
31 changes: 30 additions & 1 deletion weave-js/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9202641

Please sign in to comment.