Skip to content

Commit

Permalink
Add support for interactive app form descriptions (#3763)
Browse files Browse the repository at this point in the history
* Add support for interactive app form description

Allows providing longer descriptions as a form header in Markdown format
in form.yml.erb for interactive app forms.

* Sanitize rendered Markdown instead of html_safe

* Replace div in test with span

Div elements and ids are sanitized.
  • Loading branch information
robinkar authored Aug 30, 2024
1 parent f069b00 commit b3b3646
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/dashboard/app/models/batch_connect/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def metadata
ood_app.metadata.merge(form_config.fetch(:metadata, {}))
end

def form_header
form_config.fetch(:form_header, '')
end

def ssh_allow?
form_config[:ssh_allow]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<%= sanitize OodAppkit.markdown.render(@app.form_header) %>

<%= render "prefill_templates" if Configuration.bc_saved_settings? %>

<%= bootstrap_form_for(@session_context, html: { autocomplete: "off" }) do |f| %>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/test/fixtures/apps/bc_with_subapps/form.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
description: BC with sub apps description
form_header: BC with sub apps form header

attributes:
desktop: "mate"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "Owens Desktop"
description: "Owens Description"
form_header: "Owens Form Header"
icon: fa://clock
caption: 'gnome desktop on the owens cluster'
category: Interactive Apps Overridden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ cluster:
- "oakley"
description: |
This is a test jupyter app.
form_header: |
<span class="form_header_supports_some_html">
This is Markdown with [a link](https://openondemand.org).
</span>
attributes:
mode:
widget: "radio"
Expand Down
7 changes: 7 additions & 0 deletions apps/dashboard/test/integration/batch_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ def setup
assert_equal 'edit_name', css_select('input[name="template_name"]').first['value']
end
end

test 'form header is rendered correctly' do
get new_batch_connect_session_context_url('sys/bc_jupyter')
header_link = css_select('span.form_header_supports_some_html>a').first
assert_equal 'a link', header_link.text
assert_equal 'https://openondemand.org', header_link['href']
end
end
4 changes: 3 additions & 1 deletion apps/dashboard/test/models/batch_connect/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def expected_clusters(*args)
end
end

test 'subapps can override title, description, icon, caption, category, subcategory, and metadata from form' do
test 'subapps can override title, description, icon, caption, category, subcategory, metadata and form_header from form' do
r = PathRouter.new('test/fixtures/apps/bc_with_subapps/')
app = BatchConnect::App.new(router: r)
sub_apps = app.sub_app_list
Expand All @@ -304,6 +304,7 @@ def expected_clusters(*args)
# Oakley uses defaults
assert_equal'Desktops: Oakley', sub_apps[0].title
assert_equal'BC with sub apps description', sub_apps[0].description
assert_equal'BC with sub apps form header', sub_apps[0].form_header
assert_equal'fa://desktop', sub_apps[0].icon_uri
assert_equal'Interactive Apps', sub_apps[0].category
assert_equal'Desktops', sub_apps[0].subcategory
Expand All @@ -319,6 +320,7 @@ def expected_clusters(*args)
# Owens uses overrides
assert_equal'Owens Desktop', sub_apps[1].title
assert_equal'Owens Description', sub_apps[1].description
assert_equal'Owens Form Header', sub_apps[1].form_header
assert_equal'fa://clock', sub_apps[1].icon_uri
assert_equal'Interactive Apps Overridden', sub_apps[1].category
assert_equal'Desktops Overridden', sub_apps[1].subcategory
Expand Down

0 comments on commit b3b3646

Please sign in to comment.