Skip to content

Commit

Permalink
Add a similar holdings component
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 14, 2024
1 parent 743e80d commit fce2e9c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
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

0 comments on commit fce2e9c

Please sign in to comment.