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

🐛fix: clone deployments when null #229

Merged
merged 2 commits into from
Dec 31, 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
17 changes: 12 additions & 5 deletions sld-dashboard/app/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,27 +688,34 @@ def clone_deploy(deploy_id):
headers={"Authorization": f"Bearer {token}"},
)
aws_content = aws_response.get("json")
aws_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in aws_content]

# Get data from gcp accounts
gcp_response = request_url(
verb="GET",
uri="accounts/gcp/",
headers={"Authorization": f"Bearer {token}"},
)
gcp_content = gcp_response.get("json")
gcp_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in gcp_content]

# Get data from azure accounts
azure_response = request_url(
verb="GET",
uri="accounts/azure/",
headers={"Authorization": f"Bearer {token}"},
)
azure_content = azure_response.get("json")
azure_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in azure_content]

# Get data from custom providers accounts
custom_response = request_url(
verb="GET",
uri="accounts/custom_providers/",
headers={"Authorization": f"Bearer {token}"},
)
custom_content = custom_response.get("json")
custom_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in custom_content]
# Get defaults vars by deploy
vars_json = request_url(
verb="GET",
Expand Down Expand Up @@ -788,10 +795,10 @@ def clone_deploy(deploy_id):
name="Edit Deploy",
form=form,
deploy=deploy,
aws_content=aws_content,
gcp_content=gcp_content,
azure_content=azure_content,
custom_content=custom_content,
aws_content=aws_result,
gcp_content=gcp_result,
azure_content=azure_result,
custom_content=custom_result,
data_json=vars_json["json"],
)
except TemplateNotFound:
Expand Down Expand Up @@ -833,7 +840,7 @@ def edit_schedule(deploy_id):
# Deploy
response = request_url(
verb="PATCH",
uri="{endpoint}",
uri=endpoint,
headers={"Authorization": f"Bearer {token}"},
json=data,
)
Expand Down
11 changes: 1 addition & 10 deletions sld-dashboard/app/home/templates/deploy-clone.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,10 @@ <h6><strong>{{key}}</strong></h6>
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Obtener el prefijo del deploy.stack_name
var stackName = "{{ deploy.stack_name | default('') }}";
var stackNamePrefix = stackName.split('_')[0];
console.log("Stack Name Prefix:", stackNamePrefix);

// Obtener el contenido correspondiente al prefijo
var contentList;
if (stackNamePrefix === "aws") {
contentList = {{ aws_content | safe }};
Expand All @@ -207,14 +205,12 @@ <h6><strong>{{key}}</strong></h6>
} else if (stackNamePrefix === "custom") {
contentList = {{ custom_content | safe }};
} else {
contentList = []; // Manejar otros casos según sea necesario
contentList = [];
}

// Filtrar la lista de squads y entornos según el tipo de contenido
var squads = Array.from(new Set(contentList.map(item => item.squad)));
var environments = Array.from(new Set(contentList.map(item => item.environment)));

// Actualizar los desplegables con los datos filtrados
var squadSelect = document.getElementById("squadSelect");
var environmentSelect = document.getElementById("environmentSelect");

Expand All @@ -232,17 +228,13 @@ <h6><strong>{{key}}</strong></h6>
environmentSelect.add(option);
});

// Función para actualizar las opciones del campo de entorno según el escuadrón seleccionado
function updateEnvironmentOptions(selectedSquad) {
// Filtrar la lista de entornos para el escuadrón seleccionado
var filteredEnvironments = contentList
.filter(item => item.squad === selectedSquad)
.map(item => item.environment);

// Limpiar las opciones actuales
environmentSelect.innerHTML = "";

// Agregar las nuevas opciones
filteredEnvironments.forEach(function (environment) {
var option = document.createElement("option");
option.value = environment;
Expand All @@ -251,7 +243,6 @@ <h6><strong>{{key}}</strong></h6>
});
}

// Agregar un evento de cambio al campo de escuadrón
squadSelect.addEventListener('change', function () {
var selectedSquad = squadSelect.value;
updateEnvironmentOptions(selectedSquad);
Expand Down
Loading