Skip to content
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

[#467] Add Title Component #2102

Merged
merged 34 commits into from
Feb 19, 2024
Merged

[#467] Add Title Component #2102

merged 34 commits into from
Feb 19, 2024

Conversation

sopa301
Copy link
Contributor

@sopa301 sopa301 commented Jan 29, 2024

Fixes #467

Proposed commit message

Implement Title Component

With a new focus on allowing users to use RepoSense as a portfolio
tool, more functionality supporting this focus is needed.

Let's allow users to add customizable content in Markdown format at the
top of the report for a personalized introduction.

Other information

The input file 'title.md' is inserted with the --assets flag when the jar file is used.

@sopa301 sopa301 changed the title [467] Add Title Component [#467] Add Title Component Jan 29, 2024
@sopa301 sopa301 marked this pull request as ready for review January 30, 2024 07:07
@sopa301 sopa301 removed the s.Ongoing label Jan 30, 2024
@sopa301 sopa301 requested a review from a team January 30, 2024 07:08
Copy link
Contributor

@asdfghjkxd asdfghjkxd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ckcherry23
Copy link
Member

Hi @sopa301, thanks for working on this! I have not tested your code yet, but after skimming through the changes, I have some thoughts.

  • I think this feature would be more extensible if we allow the user to specify the markdown content needed as a config file in the RepoSense build command rather than a file within the frontend directory itself.
  • I am not fully sure if we are still looking for a simple text intro or a navbar like the CS2103T website. Would help if prof @damithc can clarify.
  • If a navbar is more preferable, one approach that we could try out is to require YAML frontmatter in the markdown file provided by the user. The frontmatter obtained (for example, a list of links and the header color) using a tool like gray-matter could be inserted into a template header component as props and displayed accordingly on the report.

@ckcherry23 ckcherry23 requested a review from a team January 31, 2024 13:24
@damithc
Copy link
Collaborator

damithc commented Jan 31, 2024

  • I am not fully sure if we are still looking for a simple text intro or a navbar like the CS2103T website. Would help if prof @damithc can clarify.

@sopa301 Can you provide screenshots of how it looks and how one is supposed to configure the content?

@sopa301
Copy link
Contributor Author

sopa301 commented Jan 31, 2024

Currently, the content is obtained by looking for a title.md file in the markdown folder. I can rewrite it in the way that is suggested to give more flexibility.

Regarding prof @damithc 's query of how it looks:
Input file (an excerpt of the RepoSense README):
image

Html report (the whole screen):
image

The rest of the report can be accessed by scrolling down and the title can be removed from view by scrolling down.

@damithc
Copy link
Collaborator

damithc commented Jan 31, 2024

The rest of the report can be accessed by scrolling down and the title can be removed from view by scrolling down.

Sounds promising @sopa301 Is there any live preview for me to see how it work?
I assume if the title.md is not present, the report looks same as before adding this feature?

@sopa301
Copy link
Contributor Author

sopa301 commented Feb 1, 2024

Unfortunately I don't have a way to provide a live preview now. Also there's a bug in the tests, so the github preview doesn't work. I can show it to you in person next monday if I don't solve the bug by then. If someone knows of another way to host a preview do let me know!

If the title.md is empty, the report will look the same as before. I forgot to handle the case where the file is missing, but I think I'll rewrite the code to account for this scenario.

@damithc
Copy link
Collaborator

damithc commented Feb 1, 2024

Unfortunately I don't have a way to provide a live preview now.

Generate the report locally and upload to a temp github.io site?

@sopa301
Copy link
Contributor Author

sopa301 commented Feb 1, 2024

I managed to host the html file here, although I messed up somewhere and the data didn't get uploaded as well. I'll update the link if I got it fixed.

Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I would recommend getting approval for the UI from Prof as well, either by deploying an example or demoing it during the lecture slot.

frontend/src/components/c-title.vue Outdated Show resolved Hide resolved
@ckcherry23 ckcherry23 requested a review from a team February 15, 2024 19:39
Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @sopa301!

Just wanted to highlight some things about the usage of v-html: There are some pretty important security concerns we need to be mindful of when using this, since rendering HTML that's partly controlled by users has the potential to lead to XSS vulnerabilities.

Reference: Vue's docs and React's equivalent (React even deliberately named their property dangerouslySetInnerHTML)

Did some reading and it seems like it's OK in this case, as the library we're using (Markdown-it) claims to output safe HTML as long as the raw HTML option is disabled (which it is by default). Just wanted to highlight this point to make sure we are mindful of it if we want to introduce any more advanced features like custom styling in the future.

frontend/src/components/c-title.vue Outdated Show resolved Hide resolved
frontend/src/shims-vue.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sopa301 Would it be possible to add tests for the title component?

Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Will wait for approval re: the UI from prof as per @ckcherry23 above before merging

@sopa301
Copy link
Contributor Author

sopa301 commented Feb 17, 2024

@sopa301 Would it be possible to add tests for the title component?

I can implement some tests to check for correct handling of exceptions. I think this would be a good time to try to integrate Jest since this component needs to handle negative cases and needs unit testing.

On the other hand, I don't think testing the markdown itself should be necessary, right?

@ckcherry23
Copy link
Member

On the other hand, I don't think testing the markdown itself should be necessary, right?

Yes, since rendering the Markdown is handled by an external library, we don't have to test it.

Since we have to do some setup for the unit tests, we could do that in a different PR.
We could also look into Vitest instead of Jest since it is recommended by Vue and see if it benefits us (eg. speed).

@sopa301
Copy link
Contributor Author

sopa301 commented Feb 19, 2024

I have discussed this with Prof @damithc and he suggested allowing raw HTML so that we can do styling with the md file. The security risks might be reasonable because the users will host their own reports, so they will have full control over what they insert into the title. I have enabled it for now.

@ckcherry23 ckcherry23 merged commit b103e28 into reposense:master Feb 19, 2024
10 checks passed
Copy link
Contributor

The following links are for previewing this pull request:

@@ -31,7 +31,8 @@ The section below provides explanations for each of the flags.
<div id="section-assets">

**`--assets ASSETS_DIRECTORY`**: Specifies where to place assets for report generation.
* Parameter: `ASSETS_DIRECTORY` The directory containing the assets files. A `favicon.ico` file can be placed here to customize the favicon of the dashboard.
* Parameter: `ASSETS_DIRECTORY` The directory containing the assets files. A `favicon.ico` file can be placed here to customize the favicon of the dashboard,
while a `title.md` file can be placed to customize the header of the report using [Markdown syntax](https://www.markdownguide.org/basic-syntax/).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sopa301 Noticed while passing: There should not be a line break here (in markdown files, we should not wrap lines to a specific length).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sopa301 Further comments:

  1. There should be more details of this feature. For example, code for an example title component.
  2. Doesn't feel like this is the right place to document this feature. Perhaps add as a separate section in https://reposense.org/ug/customizingReports.html ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, perhaps add a title component to our preview dashboard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review prof, I'll work on it!

@damithc
Copy link
Collaborator

damithc commented Mar 14, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Give a way to add an intro to the generated report
5 participants