-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 207_sort_and_filter_component
- Loading branch information
Showing
36 changed files
with
711 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ exclude_patterns: | |
- vendor/ | ||
- "**/vendor/**/*" | ||
- app/assets/images/ | ||
- spec/**/* | ||
- spec/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ mkdir -p .nix-bundler | |
export BUNDLE_PATH=./.nix-bundler | ||
|
||
# Login Env Vars | ||
source .env_login | ||
source .env_dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ end | |
gem "factory_bot", "~> 6.5" | ||
|
||
gem "faker", "~> 3.4" | ||
|
||
gem "rails-reverse-proxy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
# Proxy Cloud.gov pages content at the root of the application | ||
class PagesController < ApplicationController | ||
include ReverseProxy::Controller | ||
# We must remove this for proxy of JS assets to be loaded by the browser | ||
protect_from_forgery except: :assets | ||
|
||
# TODO: When launched, the cloud.gov pages need to move off the www.challenge.gov domain | ||
DOMAIN = Rails.configuration.static_site_interop.fetch(:domain) | ||
HOST = Rails.configuration.static_site_interop.fetch(:host) | ||
BASE_URL = Rails.configuration.static_site_interop.fetch(:base_url) | ||
|
||
def index | ||
path = "#{BASE_URL}/#{params[:path]}/" | ||
reverse_proxy(HOST, path:, reset_accept_encoding: true, headers: { host: DOMAIN }) do |config| | ||
config.on_missing do |_code, _response| | ||
redirect_to "/dashboard" | ||
return true | ||
end | ||
|
||
config.on_response do |_code, response| | ||
response.body = rewrite_links(response.body) | ||
end | ||
end | ||
end | ||
|
||
def assets | ||
if params[:ext] == "min" | ||
path = "#{HOST}#{BASE_URL}/assets/#{params[:path]}.#{params[:ext]}.js" | ||
response = Faraday.get(path) | ||
send_data(response.body, type: 'application/javascript') | ||
else | ||
path = "#{BASE_URL}/assets/#{params[:path]}.#{params[:ext]}" | ||
reverse_proxy(HOST, path:, reset_accept_encoding: true, headers: { host: DOMAIN }) | ||
end | ||
end | ||
|
||
def root | ||
path = "#{BASE_URL}/" | ||
reverse_proxy(HOST, path:, reset_accept_encoding: true, headers: { host: DOMAIN }) do |config| | ||
config.on_response do |_code, response| | ||
if response.body.present? | ||
response.body = rewrite_links(response.body) | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def rewrite_links(html) | ||
parsed_html = html.gsub(HOST, "/") | ||
if BASE_URL.length > 1 | ||
parsed_html = parsed_html.gsub(BASE_URL, "") | ||
end | ||
# delete the data-public-url attribute from the react app element to send requests through rails proxy | ||
parsed_html = parsed_html.sub(/(<div id="challenge-gov-react-app".+)(data-public-url=[^ ]+)/, '\1') | ||
|
||
# rubocop:disable Rails/OutputSafety | ||
parsed_html.html_safe | ||
# rubocop:enable Rails/OutputSafety | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["modal"]; | ||
static values = { | ||
modalId: String, | ||
}; | ||
|
||
open(event) { | ||
const modalId = event.currentTarget.dataset.modalTargetId; | ||
const modal = this.modalTargets.find((modal) => modal.id === modalId); | ||
|
||
this.openEvent = event; | ||
|
||
event.preventDefault(); | ||
|
||
if (modal) { | ||
modal.showModal(); | ||
} else { | ||
console.warn(`Modal with ID '${modalId}' not found.`); | ||
} | ||
} | ||
|
||
confirm(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const confirmRedirect = modal.dataset.modalConfirmRedirect; | ||
const confirmAction = modal.dataset.modalConfirmAction; | ||
|
||
if (confirmRedirect) { | ||
window.location.href = confirmRedirect; | ||
} else if (confirmAction) { | ||
this.invokeAction(confirmAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
cancel(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const cancelRedirect = modal.dataset.modalCancelRedirect; | ||
const cancelAction = modal.dataset.modalCancelAction; | ||
|
||
if (cancelRedirect) { | ||
window.location.href = cancelRedirect; | ||
} else if (cancelAction) { | ||
this.invokeAction(cancelAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
_getModal(event) { | ||
return event.currentTarget.closest("dialog"); | ||
} | ||
|
||
invokeAction(actionName) { | ||
const [controllerName, action] = actionName.split("#"); | ||
const controllerElement = document.querySelector( | ||
`[data-controller~="${controllerName}"]` | ||
); | ||
|
||
if (!controllerElement) { | ||
console.warn(`Controller element for ${controllerName} not found.`); | ||
} | ||
|
||
const controller = this.application.getControllerForElementAndIdentifier( | ||
controllerElement, | ||
controllerName | ||
); | ||
|
||
if (controller && typeof controller[action] === "function") { | ||
controller[action](this.openEvent); | ||
} else { | ||
console.warn(`Action ${actionName} not found on ${controllerName}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.