8000 fix: Unify version display for public and private designs by zihanKuang · Pull Request #1081 · layer5io/sistent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Unify version display for public and private designs #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/custom/CustomCatalog/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ const getValidSvgPaths = async (
return validSvgPaths;
};

// Parses the pattern file content (YAML) and returns the version field.
// If parsing fails or version is missing, returns the default version.
const getWorkingVersionFromPatternFile = (patternFileContent: string) => {
try {
const patternFile = jsyaml.load(patternFileContent);
return patternFile?.version || DEFAULT_DESIGN_VERSION;
} catch (e) {
console.error('Failed to parse pattern file to get version:', e);
return DEFAULT_DESIGN_VERSION;
}
};

interface HandleImageProps {
technologies: string[];
basePath?: string;
Expand All @@ -60,15 +72,18 @@ export const handleImage = async ({
};
export const DEFAULT_DESIGN_VERSION = '0.0.0';

// Returns the version of a design based on its visibility.
// - For 'published' designs, returns the stable published version.
// - For 'public' or 'private', returns the working version from the pattern file.
// - Defaults to the working version if visibility is unrecognized.
export const getVersion = (design: Pattern) => {
if (design.visibility === 'public') {
return design?.catalog_data?.published_version || DEFAULT_DESIGN_VERSION;
}
try {
const patternFile = jsyaml.load(design.pattern_file);
return patternFile?.version || DEFAULT_DESIGN_VERSION;
} catch (e) {
console.error(e);
return DEFAULT_DESIGN_VERSION;
switch (design.visibility) {
case 'published':
return design?.catalog_data?.published_version || DEFAULT_DESIGN_VERSION;
case 'public':
case 'private':
return getWorkingVersionFromPatternFile(design.pattern_file);
default:
return getWorkingVersionFromPatternFile(design.pattern_file);
}
};
0