Skip to content

Commit

Permalink
fix app packages
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Nov 16, 2023
1 parent f986944 commit b53796f
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 28 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ TODO.md
+ display block
appBlockAppPackage

+ articles frame are not in iframe, iframeize it

improvements UI
13 changes: 10 additions & 3 deletions app/controllers/apps/packages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def content
@package = get_app_package
@package_name = params[:id]
@conversation_key = params[:conversation_key] || params.dig(:ctx, :conversation_key)
@message_key = params[:message_key] || params.dig(:ctx, :message_key)

@location = params[:location] || params[:ctx][:location]
@blocks = @package.call_hook({
kind: "content",
Expand All @@ -148,14 +150,16 @@ def content
values: params[:values],
lang: I18n.locale,
current_user: @user,
conversation_key: params[:conversation_key]
message_key: @message_key,
conversation_key: @conversation_key
}.with_indifferent_access
})
@identifier = if @location == "fixed_sidebar"
"fixed-app-packages"
else
"#{@location}-#{@conversation_key}-#{@package_name}"
end

render template: "apps/packages/content", layout: false
end

Expand All @@ -182,6 +186,8 @@ def submit

@identifier = if @location == "fixed_sidebar"
"fixed_packages"
elsif params[:ctx][:frame]
params[:ctx][:frame]
else
"#{@location}-#{@message_key}-#{@package_name}"
end
Expand Down Expand Up @@ -275,8 +281,9 @@ def insert
controls = {
app_package: @package_name,
schema: payload["blocks"]["definitions"],
type: "app_package"
}
type: "app_package",
values: payload["blocks"]["values"]
}.with_indifferent_access

@message = @conversation.add_message(
from: author,
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/concerns/package_iframe_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def package_iframe
data.merge!({
current_user: CHASKIQ_FRAME_VERIFIER.verify(params[:user_token])
})
elsif !data[:current_user] && session[:messenger_session_id]
elsif (!data[:current_user] && !data[:current_user_id]) && session[:messenger_session_id]
app_user = @app.app_users.find_by(session_id: session[:messenger_session_id])
data[:user] = app_user
end
Expand Down Expand Up @@ -123,13 +123,13 @@ def package_iframe_internal
opts = {
app_key: app.key,
user: user,
field: params.dig(:data, :field),
values: params.dig(:data, :values)
field: params.dig(:data, :field) || params.dig(:ctx, :field),
values: params.dig(:data, :values) || params[:values]
}

opts.merge!({
conversation_key: params.dig(:data, :conversation_key),
message_key: params.dig(:data, :message_key)
conversation_key: params.dig(:data, :conversation_key) || params.dig(:ctx, :conversation_key),
message_key: params.dig(:data, :message_key) || params.dig(:ctx, :message_key)
})

html = presenter.sheet_view(opts)
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/components/banner/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def style_string
hash = {
position: "absolute",
width: "100%",
height: "72px"
height: "64px"
# fontSize: "16px",
}.merge!(placement_option || default_placement_option)

Expand Down
15 changes: 9 additions & 6 deletions app/frontend/components/button_renderer/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ def json_data
def action_method
return "click->definition-renderer#sendForm" if @action.blank?

case @action["type"]
when "frame" then "click->definition-renderer#visitFrame"
when "submit", "url" then "click->definition-renderer#sendForm"
when "link" then "click->definition-renderer#visitLink"
when "content" then "click->definition-renderer#openContent"
end
action_mappings = {
"frame" => "click->definition-renderer#visitFrame",
"submit" => "click->definition-renderer#sendForm",
"url" => "click->definition-renderer#openUrl",
"link" => "click->definition-renderer#visitLink",
"content" => "click->definition-renderer#openContent"
}

result = action_mappings[@action["type"]]
end
end
1 change: 1 addition & 0 deletions app/frontend/components/content_renderer/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ class ContentRenderer::Component < ApplicationViewComponent
option :id
option :values
option :path
option :ctx, default: -> {}
end
12 changes: 11 additions & 1 deletion app/frontend/components/content_renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './index.css'
//
import { Controller as BaseController } from '@hotwired/stimulus'
import { post } from '@rails/request.js'
import serialize from "form-serialize"

export default class Controller extends BaseController {
initialize() {
Expand All @@ -15,8 +16,17 @@ export default class Controller extends BaseController {
disconnect() {}

async sendData() {

const form = this.element.closest("form")



let formData = serialize(form, { hash: true, empty: true })

const data = {...JSON.parse(this.element.dataset.values), ...{ctx: formData.message}}

const response = await post(this.element.dataset.url, {
body: this.element.dataset.values,
body: JSON.stringify(data),
responseKind: 'html', //'turbo-stream'
})

Expand Down
15 changes: 9 additions & 6 deletions app/frontend/components/definition_renderer/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<fieldset <%= @disabled? "disabled" : "" %>>
<% if @frame %>
<input type="hidden" name="frame" value="<%= @frame %>">
<input type="hidden" name="message[frame]" value="<%= @frame %>">
<% end %>
<% if @conversation_key %>
Expand Down Expand Up @@ -95,11 +95,14 @@
size: @size || item['size']
)
end
when "content" then render ContentRenderer::Component.new(
id: item['id'],
values: {values: @values}.to_json,
path: content_app_package_path(@app.key, @app_package, @ctx)
)
when "content"
render ContentRenderer::Component.new(
id: item['id'],
values: {values: @values}.to_json,
path: content_app_package_path(
@app.key, @app_package, location: @location, ctx: @ctx
)
)
when "input"
render PadderRenderer::Component.new(size: @size ) do
render InputRenderer::Component.new(
Expand Down
1 change: 1 addition & 0 deletions app/frontend/components/definition_renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class Controller extends BaseController {
let formData = serialize(this.formTarget, { hash: true, empty: true })

const field = JSON.parse(e.currentTarget.dataset.fieldJson);

let data = {
ctx: {
field: field,
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/controllers/slide_modal_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export default class extends Controller {
}

open(e) {
if (!this.hasContainerTarget) return;
this.containerTarget.classList.remove('hidden');
}

close(e) {
if (!this.hasContainerTarget) return;
this.containerTarget.classList.add('hidden');
document.getElementById('slide-modal').innerHTML = null;
document.getElementById('slide-modal').src = null;
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/new_embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ window.Chaskiq = window.Chaskiq || {
result = 'bottom: 0';
}

const height = mode === 'floating' ? '88px' : '60px';
const height = mode === 'floating' ? '88px' : '64px';
const style = `
position: fixed;
left: 0px;
Expand Down
1 change: 1 addition & 0 deletions app/javascript/tour_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TourManager {

const cssPath = finder(target); // Assuming 'finder' is available in the context
const encodedCssPath = encodeURIComponent(cssPath);
debugger;
const url = `http://localhost:3000/apps/kLNE8uApck2uRH8phAGWpGNJ/campaigns/16/tour_step?target=${encodedCssPath}`;
const path = {
target: cssPath,
Expand Down
2 changes: 1 addition & 1 deletion app/views/apps/conversations/_header_top.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div id="button-element" class="hidden"></div>

<%= render 'apps/conversations/menu_items/call' %>
<% #= render 'apps/conversations/menu_items/call' %>
<%= render 'apps/conversations/menu_items/tags' %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/apps/conversations/menu_items/_assignee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
class: "flex items-center btn btn-rounded btn-padless w-9 h-9",
data: {
'turbo-frame': 'modal',
}
"controller"=> "tippy", "content": "Assign Agent", "placement": 'bottom',
}
) do %>
<%= @conversation.assignee ?
image_tag( @conversation&.assignee&.avatar_url, class: "rounded-full")
Expand Down
3 changes: 3 additions & 0 deletions app/views/apps/conversations/menu_items/_priorize.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
step: 'priorize'
},
method: :patch,
data: {
"controller"=> "tippy", "content": "Prioritize Conversation", "placement": 'bottom',
},
class: "focus:outline-none outline-none mr-1 rounded-full
font-semibold border
border-gray-400 shadow
Expand Down
5 changes: 5 additions & 0 deletions app/views/apps/conversations/menu_items/_state.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
state: @conversation.state,
step: 'state'
},
data: {
"controller"=> "tippy",
"content": @conversation.opened? ? "Close" : "Open",
"placement": 'bottom',
},
method: :patch,
class: "focus:outline-none outline-none mr-1 rounded-full
font-semibold border
Expand Down
1 change: 1 addition & 0 deletions app/views/apps/conversations/menu_items/_tags.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class: "flex items-center btn btn-rounded w-9 h-9",
data: {
'turbo-frame': 'modal',
"controller"=> "tippy", "content": "Tag conversation", "placement": 'bottom'
}
) do %>
<svg fill="currentColor"
Expand Down
2 changes: 1 addition & 1 deletion app/views/apps/packages/configure.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
schema: @blocks["definitions"],
size: 'sm',
blocks: @blocks,
values: {},
values: @blocks[:values],
location: @location,
path: "/apps/#{@app.key}/packages/#{@package_name}",
conversation_key: @conversation_key,
Expand Down
1 change: 1 addition & 0 deletions app/views/apps/packages/content.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
location: @location,
category: @category,
frame: @identifier,
message_key: @message_key,
conversation_key: @conversation_key,
app_package: @package_name,
app: @app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= content_tag :iframe, '', src: 'about:blank',
data:{ package_iframe_target:"iframe"},
id: 'package-frame',
style: 'width:100%; height:100%;' %>
style: 'width:100%; height:100vh;' %>
</div>
<% end %>
Expand Down

0 comments on commit b53796f

Please sign in to comment.