Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<%=
render(Primer::Beta::BorderBox.new) do |box|
render(Primer::Beta::BorderBox.new(padding: :condensed)) do |box|
box.with_header do
render(Primer::Beta::Text.new(font_weight: :bold)) { provider.name }
render(Primer::OpenProject::BorderBox::CollapsibleHeader.new(collapsed: true)) do |header|
header.with_title { heading }
header.with_count(count: page_links.count)
end
end

box.with_row { render(Wikis::RelationPageLinksComponent.new(provider, work_package: @work_package)) }
box.with_row { render(Wikis::InlinePageLinksComponent.new(provider, work_package: @work_package)) }
page_links.each do |page_link|
box.with_row { render(Wikis::PageLinkComponent.new(page_link)) }
end
end
%>
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
#++

module Wikis
class ProviderLinkGroupComponent < ApplicationComponent
class CollapsiblePageLinksComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers

alias_method :provider, :model
attr_reader :heading

alias_method :page_links, :model

def initialize(model = nil, heading:, **)
@heading = heading

def initialize(model = nil, work_package: nil, **)
@work_package = work_package
super(model, **)
end
end
Expand Down

This file was deleted.

53 changes: 0 additions & 53 deletions modules/wikis/app/components/wikis/inline_page_links_component.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ See COPYRIGHT and LICENSE files for more details.
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(icon: :"kebab-horizontal", "aria-label": t(:label_more), scheme: :invisible)

menu.with_item(label: t(".remove"), scheme: :danger) do |item|
item.with_leading_visual_icon(icon: :trash)
if actions.include?(:remove)
menu.with_item(label: t(".remove"), scheme: :danger) do |item|
item.with_leading_visual_icon(icon: :trash)
end
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions modules/wikis/app/components/wikis/page_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ class PageLinkComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers

alias_method :link, :model
alias_method :page_info_result, :model

attr_reader :actions

def initialize(model = nil, actions: [], **)
@actions = actions

super(model, **)
end

def page_title
# TODO: Define behaviour for errors
Expand All @@ -46,15 +54,7 @@ def page_href
end

def show_action_menu?
link.relation?
end

private

def page_info_result
@page_info_result ||= Wikis::Adapters::Input::PageInfo.build(identifier: link.identifier).bind do |input|
link.provider.resolve("queries.page_info").call(input)
end
actions.any?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<%=
flex_layout do |container|
container.with_row(mb: 2) do
flex_layout(justify_content: :space_between, align_items: :center) do |header|
header.with_column { render(Primer::Beta::Text.new(font_weight: :bold)) { t(".heading") } }

render(Primer::Beta::BorderBox.new(padding: :condensed)) do |box|
box.with_header do
flex_layout(align_items: :center, justify_content: :space_between) do |header|
header.with_column do
concat(render(Primer::Beta::Text.new(font_weight: :bold, mr: 2)) { provider.name })
concat(render(Primer::Beta::Counter.new(count: page_link_infos.count, round: true, scheme: :primary)))
end
header.with_column do
render(Primer::Alpha::ActionMenu.new) do |menu|
menu.with_show_button(disabled: true) do |button|
Expand All @@ -48,17 +50,17 @@ See COPYRIGHT and LICENSE files for more details.
end
end

if page_links.empty?
container.with_row do
if page_link_infos.empty?
box.with_row do
render(Primer::Beta::Blankslate.new(border: false)) do |blankslate|
blankslate.with_heading(tag: :h2).with_content(t(".empty_heading"))
blankslate.with_description { t(".empty_text") }
end
end
end

page_links.each do |page_link|
container.with_row(mt: 3) { render(Wikis::PageLinkComponent.new(page_link)) }
page_link_infos.each do |info|
box.with_row { render(Wikis::PageLinkComponent.new(info, actions: [:remove])) }
end
end
%>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def initialize(model = nil, work_package: nil, **)
super(model, **)
end

def page_links
@page_links ||= page_link_service.relation_page_links_for(provider:, linkable: @work_package)
def page_link_infos
@page_link_infos ||= page_link_service.relation_page_link_infos_for(provider:, linkable: @work_package)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,22 @@ See COPYRIGHT and LICENSE files for more details.
<%=
content_tag("turbo-frame", id: "work-package-wikis-tab-content") do
component_wrapper do
flex_layout(test_selector: "op-work-package-wikis-tab-container") do |flex|
flex_layout(test_selector: "op-work-package-wikis-tab-container") do |container|
providers.each do |provider|
flex.with_row(mb: 3) do
render(Wikis::ProviderLinkGroupComponent.new(provider, work_package:))
container.with_row(mb: 3) do
render(::Wikis::RelationPageLinksComponent.new(provider, work_package:))
end
end

if inline_page_links.any?
container.with_row(mb: 3) do
render(::Wikis::CollapsiblePageLinksComponent.new(inline_page_links, heading: t(".inline_page_links")))
end
end

if referencing_wiki_pages.any?
container.with_row do
render(::Wikis::CollapsiblePageLinksComponent.new(referencing_wiki_pages, heading: t(".referencing_pages")))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,23 @@ class WorkPackageWikisTabComponent < ApplicationComponent
def providers
Wikis::Provider.enabled
end

def show_inline_and_references_section?
inline_page_links.any? || referencing_wiki_pages.any?
end

def inline_page_links
@inline_page_links ||= page_link_service.inline_page_link_infos_for(linkable: work_package)
end

def referencing_wiki_pages
@referencing_wiki_pages ||= page_link_service.referencing_wiki_page_infos_for(linkable: work_package)
end

private

def page_link_service
@page_link_service ||= PageLinkService.new
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
#++

module Wikis::Adapters::Results
PageInfo = Data.define(:title, :href)
PageInfo = Data.define(:identifier, :provider, :title, :href)
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,41 @@
# See COPYRIGHT and LICENSE files for more details.
#++

module Wikis::Adapters::Providers::Internal::Queries
class PageInfo < Wikis::Adapters::BaseQuery
def call(input_data)
# TODO: should we accept implicit User.current or do we want to pass in a user explicitly?
wiki_page = WikiPage.visible.find_by(id: input_data.identifier)
return failure(code: :not_found) if wiki_page.nil?
module Wikis
module Adapters
module Providers
module Internal
module Queries
class PageInfo < BaseQuery
def call(input_data)
# TODO: should we accept implicit User.current or do we want to pass in a user explicitly?
wiki_page = WikiPage.visible.find_by(id: input_data.identifier)
return failure(code: :not_found) if wiki_page.nil?

success(
Wikis::Adapters::Results::PageInfo.new(
title: wiki_page.title,
href: url_for(only_path: true,
controller: "/wiki",
action: "show",
project_id: wiki_page.project.identifier,
id: wiki_page.slug)
)
)
end
success(
Results::PageInfo.new(
identifier: input_data.identifier,
provider:,
title: wiki_page.title,
href: url_for(only_path: true,
controller: "/wiki",
action: "show",
project_id: wiki_page.project.identifier,
id: wiki_page.slug)
)
)
end

private
private

delegate :url_for, to: :url_helpers
delegate :url_for, to: :url_helpers

def url_helpers
OpenProject::StaticRouting::StaticRouter.new.url_helpers
def url_helpers
OpenProject::StaticRouting::StaticRouter.new.url_helpers
end
end
end
end
end
end
end
Loading
Loading