Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Fix types in VFilters and VContentReport (#1030)
Olga Bulatec1e0e0807d4
diff --git a/frontend/src/components/VCheckbox/VCheckbox.vue b/frontend/src/components/VCheckbox/VCheckbox.vueindex 2a472e728..e4b94fd71 100644--- a/frontend/src/components/VCheckbox/VCheckbox.vue+++ b/frontend/src/components/VCheckbox/VCheckbox.vue@@ -4,7 +4,7 @@class="relative flex text-sm leading-5":class="labelClasses">- <div class="relative">+ <span class="relative block"><!--The checkbox focus style is a slight variation on the `focus-slim-tx` style.Because it becomes filled when checked, it also needs the@@ -30,9 +30,9 @@/><!-- Knob, for when `ifSwitch` is `true` -->- <div+ <spanv-if="isSwitch"- class="absolute top-0.75 left-0.75 h-3 w-3 rounded-full transition-transform duration-100"+ class="absolute top-0.75 left-0.75 block h-3 w-3 rounded-full transition-transform duration-100":class="localCheckedState? ['bg-white', 'translate-x-[1.125rem]']@@ -51,7 +51,7 @@:icon-path="checkIcon":size="5"/>- </div>+ </span><!-- @slot The checkbox label --><slot /></label>diff --git a/frontend/src/components/VContentReport/VContentReportForm.vue b/frontend/src/components/VContentReport/VContentReportForm.vueindex 3c3854cf2..a8466fec9 100644--- a/frontend/src/components/VContentReport/VContentReportForm.vue+++ b/frontend/src/components/VContentReport/VContentReportForm.vue@@ -54,7 +54,7 @@v-model="selectedReason"class="mb-4"name="reason"- :value="reason"+ :value_="reason">{{ $t(`media-details.content-report.form.${reason}.option`) }}</VRadio>@@ -112,7 +112,7 @@</template><script lang="ts">-import { computed, defineComponent, ref } from "vue"+import { computed, defineComponent, PropType, ref } from "vue"import ReportService from "~/data/report-service"@@ -124,8 +124,11 @@ import {FAILED,WIP,DMCA_FORM_URL,+ ReportReason,} from "~/constants/content-report"+import type { AudioDetail, ImageDetail } from "~/types/media"+import VButton from "~/components/VButton.vue"import VIcon from "~/components/VIcon/VIcon.vue"import VRadio from "~/components/VRadio/VRadio.vue"@@ -146,23 +149,33 @@ export default defineComponent({VReportDescForm,},props: {- media: { required: true },- providerName: { required: true },- reportService: { required: false },- closeFn: { required: true },- allowCancel: { type: Boolean, default: true },+ media: {+ type: Object as PropType<AudioDetail | ImageDetail>,+ required: true,+ },+ providerName: {+ type: String as PropType<string>,+ required: true,+ },+ closeFn: {+ type: Function,+ required: true,+ },+ allowCancel: {+ type: Boolean,+ default: true,+ },},setup(props) {- const service = props.reportService || ReportServiceconst description = ref("")const status = ref<string | null>(WIP)- const selectedReason = ref<string | null>(DMCA)+ const selectedReason = ref<ReportReason>(DMCA)/* Buttons */const handleCancel = () => {- selectedReason.value = null+ selectedReason.value = DMCAdescription.value = ""props.closeFn()}@@ -170,12 +183,12 @@ export default defineComponent({const isSubmitDisabled = computed(() => selectedReason.value === OTHER && description.value.length < 20)- const handleSubmit = async (event) => {+ const handleSubmit = async (event: Event) => {event.preventDefault()if (selectedReason.value === DMCA) return// Submit reporttry {- await service.sendReport({+ await ReportService.sendReport({mediaType: props.media.frontendMediaType,identifier: props.media.id,reason: selectedReason.value,diff --git a/frontend/src/components/VContentReport/VContentReportPopover.vue b/frontend/src/components/VContentReport/VContentReportPopover.vueindex 383bf1077..86cb7fc64 100644--- a/frontend/src/components/VContentReport/VContentReportPopover.vue+++ b/frontend/src/components/VContentReport/VContentReportPopover.vue@@ -2,7 +2,7 @@<VPopoverref="popoverEl":hide-on-click-outside="false"- :label="$t('media-details.content-report.long')"+ :label="$t('media-details.content-report.long').toString()"placement="bottom-end"><template #trigger="{ a11yProps }">@@ -20,15 +20,17 @@class="w-80 p-6":close-fn="close":media="media"- :provider-name="media.providerName"+ :provider-name="media.providerName || media.provider"/></div></template></VPopover></template>-<script>-import { defineComponent } from "vue"+<script lang="ts">+import { defineComponent, PropType } from "vue"++import type { AudioDetail, ImageDetail } from "~/types/media"import VIconButton from "~/components/VIconButton/VIconButton.vue"import VPopover from "~/components/VPopover/VPopover.vue"@@ -51,7 +53,7 @@ export default defineComponent({* the media item to report; This can either be an audio track or an image.*/media: {- type: Object,+ type: Object as PropType<AudioDetail | ImageDetail>,required: true,},},diff --git a/frontend/src/components/VFilters/VFilterChecklist.vue b/frontend/src/components/VFilters/VFilterChecklist.vueindex 08278f6b5..118acf3f0 100644--- a/frontend/src/components/VFilters/VFilterChecklist.vue+++ b/frontend/src/components/VFilters/VFilterChecklist.vue@@ -15,13 +15,13 @@:disabled="isDisabled(item)"@change="onValueChange">- <VLicense v-if="filterType === 'licenses'" :license="item.code" />+ <VLicense v-if="isLicense(item.code)" :license="item.code" /><template v-else>{{ itemLabel(item) }}</template></VCheckbox><!-- License explanation --><VPopover- v-if="filterType === 'licenses'"+ v-if="isLicense(item.code)"strategy="fixed":label="$t('browse-page.aria.license-explanation').toString()">@@ -59,7 +59,11 @@ import { defineComponent, PropType } from "vue"import { useSearchStore } from "~/stores/search"import { useI18n } from "~/composables/use-i18n"+import type { NonMatureFilterCategory, FilterItem } from "~/constants/filters"++import type { License } from "~/constants/license"+import { defineEvent } from "~/types/emits"import { getElements } from "~/utils/license"@@ -124,7 +128,7 @@ export default defineComponent({filterType: props.filterType,})}- const getLicenseExplanationCloseAria = (license) => {+ const getLicenseExplanationCloseAria = (license: License) => {const elements = getElements(license).filter((icon) => icon !== "cc")const descriptions = elements.map((element) => i18n.t(`browse-page.license-description.${element}`))@@ -140,12 +144,18 @@ export default defineComponent({props.disabledconst icons = { help: helpIcon, closeSmall: closeSmallIcon }+ const isLicense = (code: string): code is License => {+ // Quick check that also prevents "`code` is declared but its value is never read" warning.+ return !!code && props.filterType === "licenses"+ }+return {icons,isDisabled,itemLabel,onValueChange,getLicenseExplanationCloseAria,+ isLicense,}},})diff --git a/frontend/src/components/VFilters/VSearchGridFilter.vue b/frontend/src/components/VFilters/VSearchGridFilter.vueindex 1f6961697..6494eac93 100644--- a/frontend/src/components/VFilters/VSearchGridFilter.vue+++ b/frontend/src/components/VFilters/VSearchGridFilter.vue@@ -22,7 +22,7 @@v-for="filterType in filterTypes":key="filterType":options="filters[filterType]"- :title="filterTypeTitle(filterType)"+ :title="filterTypeTitle(filterType).toString()":filter-type="filterType"@toggle-filter="toggleFilter"/>@@ -88,7 +88,7 @@ export default defineComponent({const { i18n } = useContext()const router = useRouter()- const filtersFormRef = ref<HTMLFormElement>(null)+ const filtersFormRef = ref<HTMLFormElement | null>(null)const isAnyFilterApplied = computed(() => searchStore.isAnyFilterApplied)const filters = computed(() => searchStore.searchFilters)diff --git a/frontend/src/components/VRadio/VRadio.vue b/frontend/src/components/VRadio/VRadio.vueindex e05e94177..83c04e214 100644--- a/frontend/src/components/VRadio/VRadio.vue+++ b/frontend/src/components/VRadio/VRadio.vue@@ -3,7 +3,7 @@<input:id="id"v-bind="$attrs"- :value="value"+ :value="value_"class="radio relative h-5 w-5 flex-shrink-0 appearance-none rounded-full border border-dark-charcoal bg-white me-3 focus:outline-none focus:ring focus:ring-pink focus:ring-offset-2 disabled:border-dark-charcoal-40 disabled:bg-dark-charcoal-10"type="radio":checked="isChecked"@@ -21,8 +21,8 @@</label></template>-<script>-import { computed } from "vue"+<script lang="ts">+import { computed, defineComponent } from "vue"import Radiomark from "~/assets/icons/radiomark.svg?inline"@@ -30,7 +30,7 @@ import Radiomark from "~/assets/icons/radiomark.svg?inline"* Renders a radio input field, useful for choosing one of a few options that* can all be presented on the screen at once.*/-export default {+export default defineComponent({name: "VRadio",components: { Radiomark },inheritAttrs: false,@@ -48,8 +48,13 @@ export default {},/*** the value associated with this radio input+ *+ * vue-tsc with Vue 2 throws TS1117 error "An object literal cannot have multiple properties with the same name"+ * if this prop is called `value` and we have a `v-model` (which uses `value` under the hood in Vue 2, and `modelValue` in Vue 3, so we rename it to `value_` here.+ **/- value: {+ // eslint-disable-next-line vue/prop-name-casing+ value_: {type: String,required: true,},@@ -62,9 +67,9 @@ export default {},},setup(props, { emit }) {- const isChecked = computed(() => props.value === props.modelValue)+ const isChecked = computed(() => props.value_ === props.modelValue)const handleInput = () => {- emit("change", props.value)+ emit("change", props.value_)}return {@@ -72,7 +77,7 @@ export default {handleInput,}},-}+})</script><style scoped>diff --git a/frontend/src/components/VRadio/meta/VRadio.stories.mdx b/frontend/src/components/VRadio/meta/VRadio.stories.mdxindex 088404dad..c41faa40b 100644--- a/frontend/src/components/VRadio/meta/VRadio.stories.mdx+++ b/frontend/src/components/VRadio/meta/VRadio.stories.mdx@@ -39,7 +39,7 @@ export const Template = (args, { argTypes }) => ({name="Default"args={{id: "default",- value: "value",+ value_: "value",modelValue: "modelValue", // if same as value, radio is checked}}>@@ -58,7 +58,7 @@ change the type as the field is specifically designed as a radio.name="Disabled"args={{id: "disabled",- value: "value",+ value_: "value",modelValue: "modelValue", // if same as value, radio is checkeddisabled: true,}}@@ -77,8 +77,8 @@ export const vModelTemplate = (args, { argTypes }) => ({template: `<div><form class="flex flex-col gap-2 mb-2">- <VRadio id="a" name="test" value="A" v-model="picked">A</VRadio>- <VRadio id="b" name="test" value="B" v-model="picked">B</VRadio>+ <VRadio id="a" name="test" own-value="A" v-model="picked">A</VRadio>+ <VRadio id="b" name="test" own-value="B" v-model="picked">B</VRadio></form>{{ picked ?? 'None' }}</div>diff --git a/frontend/src/components/VSelectField/meta/VSelectField.stories.mdx b/frontend/src/components/VSelectField/meta/VSelectField.stories.mdxindex 881a5b150..5184305f7 100644--- a/frontend/src/components/VSelectField/meta/VSelectField.stories.mdx+++ b/frontend/src/components/VSelectField/meta/VSelectField.stories.mdx@@ -86,7 +86,7 @@ export const SlotTemplate = (args) => ({template: `<VSelectField v-bind="args"><template #start>- <VIcon :icon-path="radioIcon">+ <VIcon :icon-path="radioIcon" /></template></VSelectField>`,diff --git a/frontend/test/unit/specs/components/v-content-report-form.spec.js b/frontend/test/unit/specs/components/v-content-report-form.spec.jsindex 486bdf730..2720dd384 100644--- a/frontend/test/unit/specs/components/v-content-report-form.spec.js+++ b/frontend/test/unit/specs/components/v-content-report-form.spec.js@@ -1,6 +1,8 @@import { fireEvent, render, screen } from "@testing-library/vue"import VueI18n from "vue-i18n"+import ReportService from "~/data/report-service"+import VContentReportForm from "~/components/VContentReport/VContentReportForm.vue"const messages = require("~/locales/en.json")@@ -43,12 +45,16 @@ const getDescriptionTextarea = () =>name: /other\.note/i,})+const mockImplementation = () => Promise.resolve()+const mock = jest.fn().mockImplementation(mockImplementation)+jest.mock("~/data/report-service", () => ({+ sendReport: () => mock,+}))+describe("VContentReportForm", () => {let props = nulllet options = {}- let reportServiceProp = { sendReport: () => Promise.resolve() }-beforeEach(() => {props = {media: {@@ -59,7 +65,6 @@ describe("VContentReportForm", () => {},providerName: "Provider",closeFn: jest.fn(),- reportService: reportServiceProp,}options = {@@ -88,7 +93,7 @@ describe("VContentReportForm", () => {})it("should render error message if report sending fails", async () => {- options.propsData.reportService = { sendReport: () => Promise.reject() }+ ReportService.sendReport = () => Promise.reject()const { getByText } = render(VContentReportForm, options)await fireEvent.click(getMatureInput())@@ -119,13 +124,13 @@ describe("VContentReportForm", () => {})it("should dispatch SEND_CONTENT_REPORT on next when mature is selected", async () => {- const serviceMock = { sendReport: jest.fn() }- options.propsData.reportService = serviceMock+ ReportService.sendReport = jest.fn()+render(VContentReportForm, options)await fireEvent.click(getMatureInput())await fireEvent.click(getReportButton())- expect(serviceMock.sendReport).toHaveBeenCalledWith({+ expect(ReportService.sendReport).toHaveBeenCalledWith({identifier: props.media.id,reason: "mature",mediaType: props.media.frontendMediaType,@@ -133,9 +138,8 @@ describe("VContentReportForm", () => {})})- it("should dispatch SEND_CONTENT_REPORT on other form submit", async () => {- const serviceMock = { sendReport: jest.fn() }- options.propsData.reportService = serviceMock+ it("should send report on other form submit", async () => {+ ReportService.sendReport = jest.fn()render(VContentReportForm, options)await fireEvent.click(getOtherInput())@@ -144,7 +148,7 @@ describe("VContentReportForm", () => {await fireEvent.update(getDescriptionTextarea(), description)await fireEvent.click(getReportButton())- expect(serviceMock.sendReport).toHaveBeenCalledWith({+ expect(ReportService.sendReport).toHaveBeenCalledWith({identifier: props.media.id,reason: "other",mediaType: "image",@@ -153,7 +157,7 @@ describe("VContentReportForm", () => {})it("should not send other report if description is short", async () => {- options.propsData.reportService = { sendReport: jest.fn() }+ ReportService.sendReport = jest.fn()render(VContentReportForm, options)await fireEvent.click(getOtherInput())diff --git a/frontend/tsconfig.json b/frontend/tsconfig.jsonindex 2034cefa1..7052efed1 100644--- a/frontend/tsconfig.json+++ b/frontend/tsconfig.json@@ -56,6 +56,7 @@"src/components/VAudioTrack/layouts/**.vue","src/components/VCheckbox/**.vue","src/components/VContentLink/**.vue",+ "src/components/VFilters/**.vue","src/components/VHomeGallery/**.vue","src/components/VIcon/**.vue","src/components/VIconButton/**.vue",@@ -67,15 +68,15 @@"src/components/VMediaTag/**.vue","src/components/VModal/**.vue","src/components/VPopover/**.vue",+ "src/components/VRadio/**.vue","src/components/VRecentSearches/**.vue","src/components/VSkeleton/**.vue","src/components/VTabs/**.vue",- "src/components/VContentReport/VReportDescForm.vue",+ "src/components/VContentReport/**.vue","src/components/VContentSwitcher/VSearchTypeButton.vue","src/components/VContentSwitcher/VSearchTypeItem.vue","src/components/VContentSwitcher/VSearchTypeRadio.vue","src/components/VErrorSection/VErrorImage.vue",- "src/components/VFilters/VLicenseExplanation.vue","src/components/VHeader/VFilterButton.vue","src/components/VHeader/VPageLinks.vue","src/components/VHeader/VFilterIconOrCounter.vue",diff --git a/frontend/typings/svg/index.d.ts b/frontend/typings/svg/index.d.tsindex d5d1bf25e..cf5f65402 100644--- a/frontend/typings/svg/index.d.ts+++ b/frontend/typings/svg/index.d.ts@@ -4,7 +4,9 @@ declare module "*.svg" {}declare module "*.svg?inline" {- const SVG: unknown+ import type { Component } from "vue"++ const SVG: Componentexport default SVG}