Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start to expand data- entries for auto_queues #3123

Merged
merged 8 commits into from
Nov 2, 2023
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
6 changes: 3 additions & 3 deletions apps/dashboard/app/javascript/dynamic_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,13 @@ function optionForFromToken(str) {
};

if(hide) {
option.style.display = 'none';
option.disabled = true;

if(option.selected) {
option.selected = false;
hideSelectedValue = option.textContent;
}

option.style.display = 'none';
option.disabled = true;
Comment on lines +677 to +679
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had to make this change because it was working by coincidence.

This PR has duplicate options - i.e., options with the same value but different data- directives which we've gone back and forth on, but yea I suspect it was working by coincidence before because there were fewer (or no) duplicate options.

} else {
option.style.display = '';
option.disabled = false;
Expand Down
54 changes: 35 additions & 19 deletions apps/dashboard/app/lib/account_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,28 @@ def dynamic_accounts
# @return [Array] - the dynamic form options
def queues
Rails.cache.fetch('queues', expires_in: 4.hours) do
unique_queue_names.map do |queue_name|
data = {}
queues_per_cluster.each do |cluster, cluster_queues|
cluster_queue_names = cluster_queues.map(&:to_s)
queue_info = cluster_queues.find { |q| q.name == queue_name }

# if the queue doesn't exist on the cluster OR you're not allowed to use the queue
if !cluster_queue_names.include?(queue_name) || blocked_queue?(queue_info)
data["data-option-for-cluster-#{cluster}"] = false
end

queues_per_cluster.map do |cluster, cluster_queues|
other_clusters = queues_per_cluster.reject do |c, _queues|
c == cluster
end.map do |c, _queues|
c.to_s
end

[queue_name, queue_name, data]
cluster_data = other_clusters.map do |other_cluster|
["data-option-for-cluster-#{other_cluster}", false]
end.to_h

cluster_queues.map do |queue|
unless blocked_queue?(queue)
data = cluster_data.merge(queue_account_data(queue))
[queue.name, queue.name, data]
end
end.compact
end.flatten(1).sort_by do |tuple|
tuple[0]
end

rescue StandardError => e
Rails.logger.warn("Did not get queues from system with error #{e}")
Rails.logger.warn(e.backtrace.join("\n"))
Expand Down Expand Up @@ -128,14 +136,6 @@ def blocked_queue?(queue)
end
end

def unique_queue_names
[].tap do |queues|
queues_per_cluster.map do |_, cluster_queues|
queues << cluster_queues.map(&:to_s)
end
end.flatten.uniq
end

def queues_per_cluster
Rails.cache.fetch('queues_per_cluster', expires_in: 24.hours) do
{}.tap do |hash|
Expand All @@ -145,4 +145,20 @@ def queues_per_cluster
end
end
end

def queue_account_data(queue)
account_names.map do |account|
["data-option-for-auto-accounts-#{account}", false] unless account_allowed?(queue, account)
end.compact.to_h
end

def account_allowed?(queue, account_name)
return false if queue.deny_accounts.any? { |account| account == account_name }

if queue.allow_accounts.nil?
true
else
queue.allow_accounts.any? { |account| account == account_name }
end
end
end
Loading