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

Build hook editor on build configuration page #680

Merged
merged 1 commit into from
Jan 18, 2017

Conversation

MarkDeMaria
Copy link
Contributor

-Multi-select tag for Command, Script, and Args
-Warning states:
--On page load, if both Command and Script are both present, forms are disabled and user told to use YAML
--If either Command or Script present, and user tries to add the type not present, Save button is disabled and has-error info-block informs user of error and told to use YAML

All Selected
image

Script & Command present at page load. Form disabled and notification present
image

Page loaded with either script or command. Entered the other. Save button disabled and message shown to user.
image

@spadgett
Copy link
Member

spadgett commented Oct 17, 2016

@MarkDeMaria I spoke to @jwforres, and we decided that it's better to have a ui-select with only the valid options:

  • Shell Script
  • Command
  • Arguments to Default Image Entry Point
  • Shell Script with Arguments
  • Command with Arguments

This prevents users from selecting an invalid combination.

@spadgett spadgett self-assigned this Oct 18, 2016
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 20, 2016
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 27, 2016
@MarkDeMaria
Copy link
Contributor Author

MarkDeMaria commented Oct 27, 2016

As discussed, now uses UI-Select with each possible combination. Selecting save will overwrite the postCommit data with what is being shown on the page. For example, if saving on the Script+Args page while Commands has data, Commands will be wiped in favor of Script+Args, but Commands will still be accessible prior to saving if user switches back to the Commands drop-down.

Added bonus: Page will auto-select a dropdown option based on what is saved in Post Commit.

One problem that needs addressing is that the edit-command directive needs to be able to replace the phrase "No Command set" with "No Argument set." See screenshots below.

Drop Down
image

Script + Args
image

Command + Args
image

@MarkDeMaria MarkDeMaria force-pushed the postCommitEditor branch 3 times, most recently from ed07a16 to 269c025 Compare October 28, 2016 19:48
@spadgett
Copy link
Member

Can you add "Learn more" link to this topic?

https://docs.openshift.org/latest/dev_guide/builds.html#build-hooks

"Arguments to Default Image Entry Point",
"Shell Script with Arguments",
"Command with Arguments"
];
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer if we had a label and internal ID for each of these. I'd rather not do string comparisons on long labels, and it will make translation harder down the road.

$scope.buildHookSelection.type = "Command";
} else {
$scope.buildHookSelection.type = "Shell Script";
}
Copy link
Member

Choose a reason for hiding this comment

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

I think something like this would be easier to follow:

var postCommit = _.get($scope, 'buildConfig.spec.postCommit', {});
if (_.size(postCommit.args) && _.size(postCommit.command)) {
  $scope.buildHookSelection.type = "Command with Arguments";
  return;
}

if (postCommit.script && _.size(postCommit.args)) {
  $scope.buildHookSelection.type = "Shell Script with Arguments";
  return;
}

// etc...

Copy link
Member

Choose a reason for hiding this comment

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

Do we need an option for no post commit hooks? How do I unset the value?

var getInitialBuildHookSelection = function() {
if (($scope.buildConfig.spec.postCommit.args || []).length) {
if (($scope.buildConfig.spec.postCommit.command || []).length) {
$scope.buildHookSelection.type = "Command with Arguments";sdas
Copy link
Member

Choose a reason for hiding this comment

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

Random trailing chars

<h3 class="with-divider">Build Hooks
<span class="help action-inline">
<a href>
<i class="pficon pficon-help" data-toggle="tooltip" aria-hidden="true" data-original-title="Build hooks allow behavior to be injected into the build process."></i>
Copy link
Member

Choose a reason for hiding this comment

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

"Build hooks let you run commands at the end of the build to verify the image."

<h4>Hook Types</h4>
<ui-select required
ng-model="buildHookSelection.type"
title="Choose a Build Hook type to edit">
Copy link
Member

Choose a reason for hiding this comment

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

Choose a type of build hook

<h4>Command</h4>
<edit-command
args="buildConfig.spec.postCommit.command"
isRequired="true">
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure setting isRequired="true" is correct since this is inside an ng-show block, not an ng-if. If I don't have a command and switch types, can I submit the form?

ui-ace="{
mode: 'yaml',
theme: 'eclipse',
onLoad: aceLoaded,
Copy link
Member

Choose a reason for hiding this comment

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

aceLoaded is not defined in the controller, remove onLoad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like Line 112 & Line 293 both have onLoad: aceLoaded as well. Want me remove them too?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it shouldn't be there unless there is a controller aceLoaded method. (I don't think there is.)

ui-ace="{
mode: 'yaml',
theme: 'eclipse',
onLoad: aceLoaded,
Copy link
Member

Choose a reason for hiding this comment

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

aceLoaded is not defined in the controller, remove onLoad

showPrintMargin: false
}
}"
ng-model="buildConfig.spec.postCommit.script"
Copy link
Member

Choose a reason for hiding this comment

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

All of these fields should use updatedBuildConfig in the model. You shouldn't mutate the original build config.



<div class="section" ng-if="view.advancedOptions">
<div ng-if="!(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this div and its parent one div

<div ng-if="view.advancedOptions && !(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 5, 2016
@MarkDeMaria
Copy link
Contributor Author

@spadgett @jwforres

Build Hook Checkbox unselected
image

Build Hook Checkbox selected
image

@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 16, 2016
@jwforres
Copy link
Member

jwforres commented Dec 16, 2016 via email

@MarkDeMaria
Copy link
Contributor Author

Can do. Do you want sentence-case for all drop-down entries?

@@ -51,6 +51,7 @@ window.OPENSHIFT_CONSTANTS = {
"builds": "architecture/core_concepts/builds_and_image_streams.html#builds",
"image-streams": "architecture/core_concepts/builds_and_image_streams.html#image-streams",
"storage": "architecture/additional_concepts/storage.html",
"build-hooks": "https://docs.openshift.org/latest/dev_guide/builds.html#build-hooks",
Copy link
Member

Choose a reason for hiding this comment

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

Make it a relative URL.

"dev_guide/builds.html#build-hooks"

}, {
"id": "commandArgs",
"label": "Command with Arguments"
}];
Copy link
Member

Choose a reason for hiding this comment

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

Per @jwforres let's make these all sentence case

Copy link
Member

Choose a reason for hiding this comment

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

Nit: the quotes around id and label aren't needed.

}];

$scope.buildHookSelection = {
"type": {}
Copy link
Member

Choose a reason for hiding this comment

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

The quotes are type aren't needed.

var getInitialBuildHookSelection = function() {
$scope.view.hasHooks = (_.size($scope.buildConfig.spec.postCommit.args) ||
_.size($scope.buildConfig.spec.postCommit.command) ||
$scope.buildConfig.spec.postCommit.script) ? true : false;
Copy link
Member

@spadgett spadgett Jan 11, 2017

Choose a reason for hiding this comment

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

I don't think the postCommit property is guaranteed to be in the JSON. Using _.get guards against a runtime error.

var hasArgs = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.args'));
var hasCommand = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.command'));
var hasScript = !!_.get($scope, 'buildConfig.spec.postCommit.command');
$scope.view.hasHooks = hasArgs || hasCommand || hasScript;

Then you can use the local vars below without checking size again.

$scope.buildHookSelection.type.id = "command";
}

$scope.buildHookSelection.type.label = _.find($scope.buildHookTypes, {'id': $scope.buildHookSelection.type.id}).label;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't need to set this. You can use {{$select.selected.label}} in the ui-select markup.

$scope.buildHookSelection.type.label = _.find($scope.buildHookTypes, {'id': $scope.buildHookSelection.type.id}).label;
};

var clearIncompatibleBuildHookFields = function(selectedBuildHookID) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd delete the incompatible fields instead of setting them to empty values.

@@ -414,6 +487,7 @@ angular.module('openshiftConsole')

$scope.save = function() {
$scope.disableInputs = true;
clearIncompatibleBuildHookFields($scope.buildHookSelection.type.id);
Copy link
Member

Choose a reason for hiding this comment

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

I'd check $scope.buildHookSelection.type.id directly in the clearIncompatibleBuildHookFields instead of passing it in.

<div ng-if="view.advancedOptions && !(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
<h3 class="with-divider">Build Hooks
<span class="help action-inline">
<a href="{{'build-hooks' | helpLink}}" aria-hidden="true" target="_blank"><span class="learn-more-inline">Learn more&nbsp;<i class="fa fa-external-link"></i></span></a>
Copy link
Member

Choose a reason for hiding this comment

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

We've changed the "Learn More" links to use an uppercase M.

<h4>Script</h4>
<div
ui-ace="{
mode: 'sh',
Copy link
Member

Choose a reason for hiding this comment

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

Need to add mode-sh.js to ace-builds in bower.json.

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

See comments

@spadgett
Copy link
Member

Need to update edit-command to customize the "No command" message and help text for this context.

@MarkDeMaria MarkDeMaria force-pushed the postCommitEditor branch 6 times, most recently from e0407ed to 231ccb6 Compare January 13, 2017 19:48
@MarkDeMaria
Copy link
Contributor Author

@spadgett @jwforres All changes made with the exception of the edit-command directive alterations. Do you want that as a separate PR? And do you have any other categories (Command, Arg, Script, etc) you'd like supported for that directive?

@spadgett
Copy link
Member

I think it's small enough to add this PR. I'd make the label an optional attribute I can pass into the directive.

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

You have a change in dist.java that shouldn't be there. We'll have to fix that before we merge.

Note this needs to be in by the end of tomorrow (Wed Jan 18) to make feature cutoff for 1.5. We can make the edit-command directive changes a follow-on if necessary.

Thanks @MarkDeMaria

$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'script' });
} else {
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'command' });
}
Copy link
Member

@spadgett spadgett Jan 17, 2017

Choose a reason for hiding this comment

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

Nit: I'd assign the id to a var and the only do the _.find in one place. That avoids repeating the same code.

var id;
if (hasArgs && hasCommand) {
  id = 'commandArgs';
} else if ...

$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: id });

$scope.updatedBuildConfig.spec.postCommit.command = [];
$scope.updatedBuildConfig.spec.postCommit.args = [];
$scope.updatedBuildConfig.spec.postCommit.script = "";
}
Copy link
Member

Choose a reason for hiding this comment

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

What you have here is fine, although I might handle the simple case first and return early. It makes the code a little easier to understand because it avoids a big if block.

var clearIncompatibleBuildHookFields = function() {
  if (!$scope.view.hasHooks) {
    $scope.updatedBuildConfig.spec.postCommit.command = [];
    $scope.updatedBuildConfig.spec.postCommit.args = [];
    $scope.updatedBuildConfig.spec.postCommit.script = "";
    return;
  }
  
  switch ($scope.buildHookSelection.type.id) {
    // ...
  }
};

Probably should delete the keys for !hasHooks case as well instead of setting them to empty values.

-Single-select tag for Command, Script, and Args, Command+Args, Script+Args
-Whatever option is currently-selected upon hitting 'Save' will overwrite anything else. For example, if post commit has a command in it, and you hit save on the Args page, the command will be deleted and the args saved.
-Checkbox shows/hides the build hook editor. Leaving it unchcked and selecting "Save" with anything saved in the post commit section of the YAML will be deleted, as the user has indicated they do not wish to have any build hooks
-Alterations to edit-command directive to allow for a 'type' arg to be passed through. Will replace relevant wording. For example, 'argument.' If no type provided, defaults to 'command.'
@MarkDeMaria
Copy link
Contributor Author

@spadgett @jwforres Changes to edit-command directive made and bad dist file removed.

<!-- Single-line entry -->
<span ng-show="!multiline" class="input-group">
<input type="text"
ng-model="nextArg"
name="nextArg"
ng-attr-id="{{id}}-add-arg"
on-enter="addArg()"
placeholder="Add argument"
placeholder="Add {{type || 'command'}}"
Copy link
Member

Choose a reason for hiding this comment

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

Changing the default will affect other places where this is used, where it should be "Add argument"

Drag and drop command arguments to reorder them.
</div>
<div ng-if="type">
Enter the arguments that will be appended to the container's command. Drag and drop arguments to reorder them.
Copy link
Member

Choose a reason for hiding this comment

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

This text is not necessarily always correct when the type is set. We should add a description scope value if we need to say something specific like this.

@spadgett
Copy link
Member

I'm going to go ahead and merge so that we make DCUT. The remaining comments are fairly minor, and we can fix them in a follow up PR. @jwforres FYI

[merge]

@openshift-bot
Copy link

Evaluated for origin web console merge up to a968944

@openshift-bot
Copy link

openshift-bot commented Jan 18, 2017

Origin Web Console Merge Results: SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_web_console/932/) (Base Commit: f3d64d5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants