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

[WIP] Add a similar holdings component #4489

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/components/access_panels/similar_holdings_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module AccessPanels
class SimilarHoldingsComponent < ViewComponent::Base
def initialize(document:)
@id = document.id
super()
end

def call
helpers.turbo_frame_tag 'similar_holdings', src: "https://semantic-search-demo.stanford.edu/similar/#{@id}"
end
end
end
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ application.register("preview-brief", PreviewBriefController)

import PreviewFilmstripController from "./preview_filmstrip_controller"
application.register("preview-filmstrip", PreviewFilmstripController)

import LookupTitleController from "./lookup_title_controller"
application.register("lookup-title", LookupTitleController)
18 changes: 18 additions & 0 deletions app/javascript/controllers/lookup_title_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = {
druid: String
}

connect() {
fetch(`https://purl.stanford.edu/${this.druidValue}.json`)
.then(response => response.json())
.then(json => this.setJson(json))
}

setJson(json) {
const title = json.label
this.element.innerHTML = title
}
}
1 change: 1 addition & 0 deletions app/views/catalog/record/_metadata_panels.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<%= render AccessPanels::CourseReservesComponent.new(document: document) %>
<%= render AccessPanels::AtTheLibraryComponent.new(document: document) %>
<%= render AccessPanels::SimilarHoldingsComponent.new(document: document) %>

<% context = capture do %>
<%= render AccessPanels::AppearsInComponent.new(document: document) %>
Expand Down
15 changes: 15 additions & 0 deletions spec/components/access_panels/similar_holdings_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AccessPanels::SimilarHoldingsComponent, type: :component do
pending "add some examples to (or delete) #{__FILE__}"

# it "renders something useful" do
# expect(
# render_inline(described_class.new(attr: "value")) { "Hello, components!" }.css("p").to_html
# ).to include(
# "Hello, components!"
# )
# end
end