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
fix(client): avatar url #2791
fix(client): avatar url #2791
Conversation
c89ab0e
to
04af804
Compare
You can access the deployment of this PR at https://renku-ci-ui-2791.dev.renku.ch |
04af804
to
defeab3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should probably be renamed to datasets.utils.ts
or similar.
interface DatasetImages { | ||
content_url: string; | ||
} | ||
export interface IDataset { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, interfaces should not use the I
prefix:
export interface IDataset { | |
export interface Dataset { |
* @param {Dataset} dataset | ||
*/ | ||
export function addMarqueeImageToDataset(gitUrl: string, dataset: IDataset) { | ||
const urlRoot = cleanGitUrl(gitUrl) + "/-/raw/master"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is incorrect here, we should not assume that the default branch for a git repository is called master
. The project data includes the name of the default branch, e.g.
const defaultBranch = useSelector<RootStateOrAny, string>(
(state) => state.stateModel.project.metadata.defaultBranch
);
const urlRoot = cleanGitUrl(gitUrl) + "/-/raw/master"; | |
const urlRoot = `${cleanGitUrl(gitUrl)}/-/raw/${defaultBranch}`; |
dataset.mediaContent = mediaUrl; | ||
return dataset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It usually is less bug-prone to avoid mutating arguments in function. Code here could return an updated object, e.g.
dataset.mediaContent = mediaUrl; | |
return dataset; | |
return { | |
...dataset, | |
mediaContent: mediaUrl, | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the suggestion to avoid mutating arguments in functions. In this specific context, we intend to mutate the object when fetching datasets in order to add the mediaContent property. While we could refactor this code chain to return a new object, it's not within the scope of this PR. We may consider making such a change when transitioning to the use of Redux Toolkit
export function addMarqueeImageToDataset(gitUrl: string, dataset: IDataset) { | ||
const urlRoot = cleanGitUrl(gitUrl) + "/-/raw/master"; | ||
let mediaUrl = dataset?.images?.[0]?.content_url ?? null; | ||
if (mediaUrl !== null && mediaUrl.startsWith(".renku/dataset_images/")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this logic non-intuitive here. Why do we not consider any relative path inside the repository? Non-relative locations would start with a URL scheme (<scheme>://
). Also, we should probably validate external URLs and only allow those starting with https://
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion is to use the URL class:
const mediaUrl = new URL("https://example.com/image.jpg", "https://gitlab.renkulab.io/namespace/name/-/raw/main/");
mediaUrl.toString() // 'https://example.com/image.jpg'
const mediaUrl = new URL("path/to/image.jpg", "https://gitlab.renkulab.io/namespace/name/-/raw/main/");
mediaUrl.toString() // 'https://gitlab.renkulab.io/namespace/name/-/raw/main/path/to/image.jpg'
const mediaUrl = new URL("s3://example/image.jpg", "https://gitlab.renkulab.io/namespace/name/-/raw/main/");
mediaUrl.toString() // 's3://example/image.jpg'
The URL constructor will handle relative vs absolute locations for you without needing to re-implement it.
Tearing down the temporary RenkuLab deplyoment for this PR. |
PR to resolve the dataset avatar URL issue. GitHub URL is included only if the content_url is a GitHub URL.
Testing
Every dataset in this project should display an image. https://renku-ci-ui-2791.dev.renku.ch/projects/lorenzo.cavazzi.tech/test-dataset-avatars/datasets
Fix #2765
/deploy #persist