Skip to content
Snippets Groups Projects

CE Improve import status table UI

Closed Luke Bennett requested to merge import-go-to-project-cta into master
9 unresolved threads
Compare and Show latest version
66 files
+ 1032
745
Compare changes
  • Side-by-side
  • Inline
Files
66
@@ -7,11 +7,13 @@ import statusCodes from '../lib/utils/http_status';
@@ -7,11 +7,13 @@ import statusCodes from '../lib/utils/http_status';
import VariableList from './ci_variable_list';
import VariableList from './ci_variable_list';
function generateErrorBoxContent(errors) {
function generateErrorBoxContent(errors) {
const errorList = [].concat(errors).map(errorString => `
const errorList = [].concat(errors).map(
 
errorString => `
<li>
<li>
${_.escape(errorString)}
${_.escape(errorString)}
</li>
</li>
`);
`,
 
);
return `
return `
<p>
<p>
@@ -25,13 +27,7 @@ function generateErrorBoxContent(errors) {
@@ -25,13 +27,7 @@ function generateErrorBoxContent(errors) {
// Used for the variable list on CI/CD projects/groups settings page
// Used for the variable list on CI/CD projects/groups settings page
export default class AjaxVariableList {
export default class AjaxVariableList {
constructor({
constructor({ container, saveButton, errorBox, formField = 'variables', saveEndpoint }) {
container,
saveButton,
errorBox,
formField = 'variables',
saveEndpoint,
}) {
this.container = container;
this.container = container;
this.saveButton = saveButton;
this.saveButton = saveButton;
this.errorBox = errorBox;
this.errorBox = errorBox;
@@ -58,18 +54,21 @@ export default class AjaxVariableList {
@@ -58,18 +54,21 @@ export default class AjaxVariableList {
// to match it up in `updateRowsWithPersistedVariables`
// to match it up in `updateRowsWithPersistedVariables`
this.variableList.toggleEnableRow(false);
this.variableList.toggleEnableRow(false);
return axios.patch(this.saveEndpoint, {
return axios
variables_attributes: this.variableList.getAllData(),
.patch(
}, {
this.saveEndpoint,
// We want to be able to process the `res.data` from a 400 error response
{
// and print the validation messages such as duplicate variable keys
variables_attributes: this.variableList.getAllData(),
validateStatus: status => (
},
status >= statusCodes.OK &&
{
status < statusCodes.MULTIPLE_CHOICES
// We want to be able to process the `res.data` from a 400 error response
) ||
// and print the validation messages such as duplicate variable keys
status === statusCodes.BAD_REQUEST,
validateStatus: status =>
})
(status >= statusCodes.OK && status < statusCodes.MULTIPLE_CHOICES) ||
.then((res) => {
status === statusCodes.BAD_REQUEST,
 
},
 
)
 
.then(res => {
loadingIcon.classList.toggle('hide', true);
loadingIcon.classList.toggle('hide', true);
this.variableList.toggleEnableRow(true);
this.variableList.toggleEnableRow(true);
@@ -90,18 +89,21 @@ export default class AjaxVariableList {
@@ -90,18 +89,21 @@ export default class AjaxVariableList {
}
}
updateRowsWithPersistedVariables(persistedVariables = []) {
updateRowsWithPersistedVariables(persistedVariables = []) {
const persistedVariableMap = [].concat(persistedVariables).reduce((variableMap, variable) => ({
const persistedVariableMap = [].concat(persistedVariables).reduce(
...variableMap,
(variableMap, variable) => ({
[variable.key]: variable,
...variableMap,
}), {});
[variable.key]: variable,
 
}),
 
{},
 
);
this.container.querySelectorAll('.js-row').forEach((row) => {
this.container.querySelectorAll('.js-row').forEach(row => {
// If we submitted a row that was destroyed, remove it so we don't try
// If we submitted a row that was destroyed, remove it so we don't try
// to destroy it again which would cause a BE error
// to destroy it again which would cause a BE error
const destroyInput = row.querySelector('.js-ci-variable-input-destroy');
const destroyInput = row.querySelector('.js-ci-variable-input-destroy');
if (convertPermissionToBoolean(destroyInput.value)) {
if (convertPermissionToBoolean(destroyInput.value)) {
row.remove();
row.remove();
// Update the ID input so any future edits and `_destroy` will apply on the BE
// Update the ID input so any future edits and `_destroy` will apply on the BE
} else {
} else {
const key = row.querySelector('.js-ci-variable-input-key').value;
const key = row.querySelector('.js-ci-variable-input-key').value;
const persistedVariable = persistedVariableMap[key];
const persistedVariable = persistedVariableMap[key];
Loading