Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Refactor media services #867

Merged
merged 12 commits into from
Feb 23, 2022
Merged

Refactor media services #867

merged 12 commits into from
Feb 23, 2022

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Feb 15, 2022

Fixes

Fixes #866 by @obulat

Description

This PR joins three separate modules for media-services into one generic MediaService that can be created with a mediaType parameter. All of the methods for both audio and image are the same. This change will allow us to simplify media fetching, and make the store conversion to Pinia and addition of other media types easier.

Testing Instructions

Run the app as usual, and check that you can search for all media types.

Checklist

  • My pull request has a descriptive title (not a vague title like Update 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.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

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.

@obulat obulat added 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Feb 15, 2022
@obulat obulat requested a review from a team as a code owner February 15, 2022 09:04
@obulat obulat self-assigned this Feb 15, 2022
@obulat obulat requested review from zackkrida and stacimc February 15, 2022 09:04
@obulat obulat force-pushed the refactor_media_services branch from e882a16 to edc9a43 Compare February 15, 2022 09:08
@obulat obulat force-pushed the refactor_media_services branch from edc9a43 to 6d16616 Compare February 15, 2022 09:09
@sarayourfriend
Copy link
Contributor

This is great Olga! I haven't tested the code locally yet but I did take it for a spin to do some fun TypeScript hoop-jumping to make the MediaStore a generic class based on the mediaType in the constructor. Take it or leave it, up to you 🙂

@obulat
Copy link
Contributor Author

obulat commented Feb 15, 2022

This is great Olga! I haven't tested the code locally yet but I did take it for a spin to do some fun TypeScript hoop-jumping to make the MediaStore a generic class based on the mediaType in the constructor. Take it or leave it, up to you 🙂

Thank you, Sara, your PR is amazing! I've left my notes there, and added some changes from it here.

@obulat obulat added 🧰 goal: internal improvement Improvement that benefits maintainers, not users and removed 🛠 goal: fix Bug fix labels Feb 15, 2022
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM! Tested locally and it works great. Left a couple more subtle TypeScript things but given the files aren't added to tsconfig yet anyway it's no big deal to leave them out, we'll just have to fix them later when we add them to tsconfig.

src/constants/media.js Outdated Show resolved Hide resolved
src/store/types.d.ts Outdated Show resolved Hide resolved
src/data/api-service.js Outdated Show resolved Hide resolved
src/store/types.d.ts Outdated Show resolved Hide resolved
obulat and others added 4 commits February 15, 2022 20:34
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
@sarayourfriend
Copy link
Contributor

@WordPress/openverse-frontend can we get a second review on this? 🙂

@obulat obulat mentioned this pull request Feb 22, 2022
7 tasks
@zackkrida zackkrida removed the request for review from stacimc February 23, 2022 00:50
Comment on lines +14 to +17
const getResourceSlug = (resource) => {
const slug = { [AUDIO]: 'audio', [IMAGE]: 'images' }[resource] ?? resource
return `${slug}/`
}
Copy link
Member

Choose a reason for hiding this comment

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

nice fix here.

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

The new abstraction is quite nice, and the types are fantastic. Some non-blocking questions:

  • Should we add the peaks key here to the AudioDetail interface? Since it will be used for the waveforms soon and is already accessed in the VWaveform component implementations.
  • How will we handle if a media type has a one-off endpoint, like the /waveform endpoint for audio or future endpoints that, say, 3D models might need?

@sarayourfriend
Copy link
Contributor

How will we handle if a media type has a one-off endpoint, like the /waveform endpoint for audio or future endpoints that, say, 3D models might need?

Subclass the MediaService:

class Model3DService extends MediaService<'3d models'> {
  constructor() {
    super('3d models')
  }

  getCustomData() {
    // impl
  }
}

@obulat obulat merged commit e77826c into main Feb 23, 2022
@obulat obulat deleted the refactor_media_services branch February 23, 2022 04:06
obulat added a commit that referenced this pull request Feb 23, 2022
* Rename AudioDetails (#892)

* Rename AudioDetails folder

* Fix store access

* Revert conversion to Composition API

* Revert conversion to defineComponent

* Update pot

* Use v-show instead of v-if for width-based condition (#884)

* Use v-show instead of v-if for width-based condition

Use v-show instead of v-if to fix server-client mismatch

* Fix waveform not loading on SSR

* Split CI into discrete jobs (#981)

* Split CI into discrete jobs

* Update outdated POT file

* Skip writing POT file if the only thing changing is the date

* Format yaml

* Add yaml to lint staged

* Get locales when setting up node env

* Cram it all into a single workflow

* Add getting translations

* Update license explanation tooltip (#850)

Co-authored-by: Zack Krida <zackkrida@pm.me>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Fix attribution HTML glyph reference and fix historical usages as well (#990)

* Fix attribution HTML glyph reference and fix historical usages as well

* Add missing license parts

* Add note to explain directory structure

* Refactor media services (#867)

* Create a single media-service data fetching object

* Move slug creation from media service to the api service

* Use typing data from #868

* Update src/constants/media.js

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* edit api-service styles; format

* fix decode-media-data type import

* Return decoded data from the media services

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Make active media setup store and add unit tests

* Commit the lock file

* Fix merge problems

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Co-authored-by: Dhruv Bhanushali <dhruv_b@live.com>
Co-authored-by: Zack Krida <zackkrida@pm.me>
obulat added a commit that referenced this pull request Mar 3, 2022
* Install Pinia

* Update the active media store to use Pinia

* Delete the Vuex store

* Update type definition and use it

* Document the store composition variable

* Fix a lint error that Prettier did not catch locally

* Use `~` instead of `@` in imports

* Update the nav store to use Pinia

* Rename store

* Make mutation payload fields non-nullable

* Fix leftover incorrect usage of the active media store

* Make active media setup store and add unit tests (#997)

* Rename AudioDetails (#892)

* Rename AudioDetails folder

* Fix store access

* Revert conversion to Composition API

* Revert conversion to defineComponent

* Update pot

* Use v-show instead of v-if for width-based condition (#884)

* Use v-show instead of v-if for width-based condition

Use v-show instead of v-if to fix server-client mismatch

* Fix waveform not loading on SSR

* Split CI into discrete jobs (#981)

* Split CI into discrete jobs

* Update outdated POT file

* Skip writing POT file if the only thing changing is the date

* Format yaml

* Add yaml to lint staged

* Get locales when setting up node env

* Cram it all into a single workflow

* Add getting translations

* Update license explanation tooltip (#850)

Co-authored-by: Zack Krida <zackkrida@pm.me>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Fix attribution HTML glyph reference and fix historical usages as well (#990)

* Fix attribution HTML glyph reference and fix historical usages as well

* Add missing license parts

* Add note to explain directory structure

* Refactor media services (#867)

* Create a single media-service data fetching object

* Move slug creation from media service to the api service

* Use typing data from #868

* Update src/constants/media.js

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* edit api-service styles; format

* fix decode-media-data type import

* Return decoded data from the media services

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Make active media setup store and add unit tests

* Commit the lock file

* Fix merge problems

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Co-authored-by: Dhruv Bhanushali <dhruv_b@live.com>
Co-authored-by: Zack Krida <zackkrida@pm.me>

* fix possibly undefined

* Add tests and other small fixes

* Update nuxt.config.ts

Co-authored-by: Zack Krida <zackkrida@pm.me>

* Move converted modules to /stores/ and add unit tests

* Fix linting error

* Update nuxt.config.ts

Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>

* Add changes from review

* Register component

* Make properties readonly

* Remove dublicates

Co-authored-by: Olga Bulat <obulat@gmail.com>
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
Co-authored-by: Zack Krida <zackkrida@pm.me>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟨 priority: medium Not blocking but should be addressed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify media services
3 participants