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

Create VTag component #3137

Merged
merged 7 commits into from
Oct 13, 2023
Merged

Create VTag component #3137

merged 7 commits into from
Oct 13, 2023

Conversation

ngken0995
Copy link
Collaborator

@ngken0995 ngken0995 commented Oct 4, 2023

Fixes

Fixes #2773 by @obulat

Description

Created a VTag component for tags to be clickable. It is visible on the single result page when the additional_search_views flag is on.

Testing Instructions

Added by @obulat:
Go to /preferences and turn on the additional_search_views flag. Then, open a single result page. You should see "clickable" tags that match the Figma designs. The tags don't have the correct href yet, so nothing happens when you click on a tag.
Also, run Storybook (just frontend/run storybook) and check the VTag story.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • [N/A] I added or updated tests for the changes I made (if applicable).
  • [N/A] I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • [N/A] I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@ngken0995 ngken0995 requested a review from a team as a code owner October 4, 2023 19:44
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon 🌟 goal: addition Addition of new feature 🕹 aspect: interface Concerns end-users' experience with the software 🧱 stack: frontend Related to the Nuxt frontend labels Oct 4, 2023
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

This is a great start, @ngken0995!

I've added several requests for changes in the inline comments.

I also realized that it's not too difficult to add this new component to the VMediaTags.vue component under the additional_search_views feature flag. If you want, you can add those changes, too:

In the VMediaTags script, add:

 setup() {
    const featureFlagStore = useFeatureFlagStore()

    const additionalSearchViews = computed(() => featureFlagStore.isOn("additional_search_views"))

return {
additionalSearchViews
}

And in the template in the same file add VTag if the flag is on:

  <ul v-if="tags.length" class="flex flex-wrap gap-2">
+    <VTag v-if="additionalSearchViews" v-for="(tag, index) in tags" :key="index" href="/" :title="tag.name"/>
+    <VMediaTag v-else v-for="(tag, index) in tags" :key="index" tag="li">{{
      tag.name
    }}</VMediaTag>
  </ul>

</template>

<script lang="ts">
import { defineComponent } from "@nuxtjs/composition-api"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { defineComponent } from "@nuxtjs/composition-api"
import { defineComponent } from "vue"

We are trying to move away from @nuxtjs/composition-api wherever possible: this will make the transition to Nuxt 3 easier. This is why we only use the defineComponent imported from @nuxtjs/composition-api on pages. On a component like this, it's better to import it from vue.

})
</script>

<style scoped></style>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<style scoped></style>

name: "VTag",
components: { VButton },
props: {
title: { type: String },
Copy link
Contributor

Choose a reason for hiding this comment

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

This prop has to be required, too, because a tag without the title does not make sense.

},
})

<Meta title="Components/VTag" component={VTag} />
Copy link
Contributor

Choose a reason for hiding this comment

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

This story should have args and argTypes set up: this will allow us to set the title and the href to test in the storybook. You can see examples of how to set this up in other .mdx files.

@ngken0995
Copy link
Collaborator Author

ngken0995 commented Oct 5, 2023

@obulat Here is a video of how it works on the webpage: https://youtu.be/LpomDHUhY8U. I have made changes to VTag and VMediaTags. I'll start working on VTag Storybooks.

@ngken0995
Copy link
Collaborator Author

@obulat I tried running just frontend/run test:storybook and received the error below:

frontend-playwright-1  | 
frontend-playwright-1  | > @openverse/frontend@2.2.1 test:storybook:local /frontend
frontend-playwright-1  | > playwright test -c test/storybook
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | Running 303 tests using 4 workers
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 2023-10-05T19:42:19.491Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:19.497Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:19.497Z pw:webserver Starting WebServer process pnpm storybook...
frontend-playwright-1  | 2023-10-05T19:42:19.506Z pw:webserver Process started
frontend-playwright-1  | 2023-10-05T19:42:19.506Z pw:webserver Waiting for availability...
frontend-playwright-1  | 2023-10-05T19:42:19.506Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:19.508Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:19.508Z pw:webserver Waiting 100ms
frontend-playwright-1  | 2023-10-05T19:42:19.609Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:19.611Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:19.611Z pw:webserver Waiting 250ms
frontend-playwright-1  | [WebServer] 
frontend-playwright-1  | > @openverse/frontend@2.2.1 storybook /frontend
frontend-playwright-1  | > nuxt storybook --port=54000
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 2023-10-05T19:42:19.861Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:19.863Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:19.863Z pw:webserver Waiting 500ms
frontend-playwright-1  | 2023-10-05T19:42:20.364Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:20.365Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:20.365Z pw:webserver Waiting 1000ms
frontend-playwright-1  | 2023-10-05T19:42:21.367Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:21.368Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:21.368Z pw:webserver Waiting 1000ms
frontend-playwright-1  | 2023-10-05T19:42:22.370Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:22.371Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:22.372Z pw:webserver Waiting 1000ms
frontend-playwright-1  | [WebServer] ℹ @nuxt/postcss8 is disabled since nuxt has upgraded to postcss v8.
frontend-playwright-1  | [WebServer] [HPM] Proxy created: /api/event  -> https://plausible.io
frontend-playwright-1  | 2023-10-05T19:42:23.372Z pw:webserver HTTP GET: http://localhost:54000/iframe.html?id=introduction-openverse-ui--page
frontend-playwright-1  | 2023-10-05T19:42:23.373Z pw:webserver Error while checking if http://localhost:54000/iframe.html?id=introduction-openverse-ui--page is available: connect ECONNREFUSED 127.0.0.1:54000
frontend-playwright-1  | 2023-10-05T19:42:23.373Z pw:webserver Waiting 1000ms
frontend-playwright-1  | [WebServer] [nuxt:sentry] ℹ Sentry reporting is disabled (no DSN has been provided)
frontend-playwright-1  | [WebServer] ℹ Preparing project for development
frontend-playwright-1  | [WebServer] ℹ Initial build may take a while
frontend-playwright-1  | [WebServer] ℹ Discovered Components: .nuxt-storybook/components/readme.md
frontend-playwright-1  | [WebServer] ✔ Builder initialized
frontend-playwright-1  | [WebServer] ⚙ App root: /frontend/src
frontend-playwright-1  | [WebServer] [Error: EACCES: permission denied, mkdir '/frontend/.nuxt-storybook'] {
frontend-playwright-1  |   errno: -13,
frontend-playwright-1  |   code: 'EACCES',
frontend-playwright-1  |   syscall: 'mkdir',
frontend-playwright-1  |   path: '/frontend/.nuxt-storybook'
frontend-playwright-1  | }
frontend-playwright-1  | [WebServer] 
frontend-playwright-1  |  FATAL  Failed to run command nuxt-storybook:
frontend-playwright-1  | Error: Command failed with exit code 1: nuxt-storybook --port=54000
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | [WebServer]  ELIFECYCLE  Command failed with exit code 2.
frontend-playwright-1  | Error: Process from config.webServer was not able to start. Exit code: 1
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  | 
frontend-playwright-1  |   303 skipped

How can I resolve this?

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Video looks nice, but there are duplicated tags now. I added suggestions on what to do to remove the old VMediaTags when additional_search_views feature flag is on.

As for the error you mention, I'm not sure what causes it. Maybe your local folder needs permissions to be adjusted?

@@ -1,25 +1,45 @@
<template>
<ul v-if="tags.length" class="flex flex-wrap gap-2">
<div v-if="additionalSearchViews">
<VTag
v-for="(tag, index) in tags"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
v-for="(tag, index) in tags"
v-if="additionalSearchViews"
v-for="(tag, index) in tags"

You don't need to wrap the tags in a separate div. Also, we need to hide the VMediaTags if additionalSearchViews is true.

href="/"
:title="tag.name"
/>
</div>
<VMediaTag v-for="(tag, index) in tags" :key="index" tag="li">{{
Copy link
Contributor

Choose a reason for hiding this comment

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

If you add v-else to VMediaTag here, it will be hidden when additionalSearchViews is true, so there'll be no duplication of tags.

@ngken0995
Copy link
Collaborator Author

@obulat I'm getting a eslint error for putting v-if in VTag component.

eslint...................................................................Failed
- hook id: eslint
- exit code: 1
- files were modified by this hook

> openverse@0.0.0 preeslint /home/kenneth/Documents/projects/openverse
> pnpm --filter eslint-plugin run build


> @openverse/eslint-plugin@0.0.0 build /home/kenneth/Documents/projects/openverse/packages/eslint-plugin
> swc ./src -d ./dist

Successfully compiled: 10 files with swc (10.95ms)

> openverse@0.0.0 eslint /home/kenneth/Documents/projects/openverse
> eslint --ext .js,.ts,.vue,.json,.json5 --ignore-path .gitignore --ignore-path .eslintignore --max-warnings=0 frontend automations/js packages .pnpmfile.cjs .eslintrc.js prettier.config.js tsconfig.base.json "--fix"


/home/kenneth/Documents/projects/openverse/frontend/src/components/VMediaInfo/VMediaTags.vue
   5:7   error  This 'v-if' should be moved to the wrapper element  vue/no-use-v-if-with-v-for

✖ 2 problems (2 errors, 0 warnings)

 ELIFECYCLE  Command failed with exit code 1.

@obulat
Copy link
Contributor

obulat commented Oct 6, 2023

@obulat I'm getting a eslint error for putting v-if in VTag component.

Right, sorry, @ngken0995, I didn't check the suggestion locally before. You can wrap the tags with <template> and put the v-if and v-else on the templates:

   <template v-if="additionalSearchViews">
      <VTag
        v-for="(tag, index) in tags"
        :key="index"
        href="/"
        :title="tag.name"
      >
        {{ tag.name }}
      </VTag>
    </template>
    <template v-else>
      <VMediaTag v-for="(tag, index) in tags" :key="index" tag="li">{{
        tag.name
      }}</VMediaTag>
    </template>

@ngken0995 ngken0995 requested a review from obulat October 12, 2023 03:14
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

I updated the testing instructions for the other reviewers.

Thank you for your contribution, @ngken0995 , the tags look great!

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

The tags work well, thanks for the contribution @ngken0995!

While I do think there is a possibility to improve VTag further (by forwarding all props to the inner VButton, using a slot for the content instead of a prop, adding accessible labels to the links etc.), I won't block the merge of this PR and we can consider those improvements in a separate issue.

@ngken0995
Copy link
Collaborator Author

The tags work well, thanks for the contribution @ngken0995!

While I do think there is a possibility to improve VTag further (by forwarding all props to the inner VButton, using a slot for the content instead of a prop, adding accessible labels to the links etc.), I won't block the merge of this PR and we can consider those improvements in a separate issue.

Please let me know if you will create one. I will be interested in working on it.

@obulat obulat merged commit 2e4cc83 into WordPress:main Oct 13, 2023
42 checks passed
@dhruvkb
Copy link
Member

dhruvkb commented Oct 13, 2023

Created #3190 for further refinements, cc: @ngken0995.

@krysal krysal mentioned this pull request Oct 13, 2023
8 tasks
@Stagge Stagge mentioned this pull request Mar 4, 2024
8 tasks
@obulat obulat mentioned this pull request Mar 27, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕹 aspect: interface Concerns end-users' experience with the software 🌟 goal: addition Addition of new feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Component: VTag
4 participants