Skip to content

Commit

Permalink
Persist schedule prompt on launch fields when editing (#14736)
Browse files Browse the repository at this point in the history
* persist schedule prompt on launch fields when editing

* Merge job template default credentials with schedule overrides in schedule prompt

* rename vars for clarity

* handle undefined defaultCredentials

---------

Co-authored-by: Michael Abashian <mabashia@redhat.com>
  • Loading branch information
keithjgrant and mabashian committed Dec 21, 2023
1 parent 19dff9c commit 2529fdc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions awx/ui/src/components/Schedule/shared/ScheduleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import UnsupportedScheduleForm from './UnsupportedScheduleForm';
import parseRuleObj, { UnsupportedRRuleError } from './parseRuleObj';
import buildRuleObj from './buildRuleObj';
import buildRuleSet from './buildRuleSet';
import mergeArraysByCredentialType from './mergeArraysByCredentialType';

const NUM_DAYS_PER_FREQUENCY = {
week: 7,
Expand Down Expand Up @@ -350,6 +351,12 @@ function ScheduleForm({
startDate: currentDate,
startTime: time,
timezone: schedule.timezone || now.zoneName,
credentials: mergeArraysByCredentialType(
resourceDefaultCredentials,
credentials
),
labels: originalLabels.current,
instance_groups: originalInstanceGroups.current,
};

if (hasDaysToKeepField) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default function mergeArraysByCredentialType(
defaultCredentials = [],
overrides = []
) {
const mergedArray = [...defaultCredentials];

overrides.forEach((override) => {
const index = mergedArray.findIndex(
(defaultCred) => defaultCred.credential_type === override.credential_type
);
if (index !== -1) {
mergedArray.splice(index, 1);
}
mergedArray.push(override);
});

return mergedArray;
}

0 comments on commit 2529fdc

Please sign in to comment.