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

Bug 1505782 - Environment From Fix Drag & Order Display #2238

Merged

Conversation

cdcabrera
Copy link
Contributor

@cdcabrera cdcabrera commented Oct 9, 2017

Fix for making sure the drag and drop/order handles are hidden within a read only display. Related to #2182

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1505782

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 9, 2017
@@ -52,7 +52,7 @@
</div>
</div>

<div ng-if="!$ctrl.isReadonlyAny && !entry.isReadonlyValue" class="environment-from-editor-button">
<div ng-if="$ctrl.isEnvFromSelectable()" class="environment-from-editor-button">
Copy link
Contributor Author

@cdcabrera cdcabrera Oct 9, 2017

Choose a reason for hiding this comment

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

Going to look at placing the isReadonlyAny and isReadonlyValue back in...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Separated out the options length check and encased both isReadonlyAny and isReadonlyValue within the isEnvFromReadonly method

@cdcabrera cdcabrera changed the title [WIP] Environment From Fix Drag & Order Display Environment From Fix Drag & Order Display Oct 9, 2017
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 9, 2017
entry.isReadonlyValue === true ||
((entry.secretRef || entry.configMapRef) && !entry.selectedEnvFrom) ||
_.isEmpty(ctrl.envFromSelectorOptions);
return ctrl.isReadonlyAny || entry.isReadonlyValue === true || ((entry.secretRef || entry.configMapRef) && !entry.selectedEnvFrom);
Copy link
Member

Choose a reason for hiding this comment

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

We could simplify this a lot by just saying the whole thing is either read-only or it isn't. We currently don't have a need to make individual values read-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works, removing the "isReadonlyAny" and tweaking some of the related logic

@@ -50,11 +50,12 @@
ctrl.editEnvironmentFromForm.$setDirty();
};

ctrl.isEnvFromSelectable = function() {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest hasOptions

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 9, 2017
entry.isReadonlyValue === true ||
((entry.secretRef || entry.configMapRef) && !entry.selectedEnvFrom) ||
_.isEmpty(ctrl.envFromSelectorOptions);
return entry.isReadonlyValue === true || ((entry.secretRef || entry.configMapRef) && !entry.selectedEnvFrom);
Copy link
Member

Choose a reason for hiding this comment

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

I was proposing getting rid of isReadonlyValue and keeping only isReadonlyAny :)

I don't think we have a need for only certain values being read only. Either the entire list is read only or it isn't

Copy link
Contributor Author

@cdcabrera cdcabrera Oct 10, 2017

Choose a reason for hiding this comment

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

Hahahaha whoops, I'll go the other direction...

Edit:

To remove some of the confusion around this considering a going to rename for the value to towards "isReadOnly".

The current Read Only behavior removes the related binding parameter/property that can be passed in individually, and relies only on the Options List being populated and a Can I check for Secrets and Config Maps.

Copy link
Contributor Author

@cdcabrera cdcabrera Oct 10, 2017

Choose a reason for hiding this comment

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

After trying to pick this apart looks like the piece around Secrets or Config maps and duplicate entries falls into a strange area. Specifically around when a user edits the Yaml and purposefully enters duplicates.

With the current version these duplicates become read only because they lack the additional property around "selectedEnvFrom" due to the way lodash and find is being used... this is unintended but has kinda given us an inadvertent solution to the duplicate issue. Similar to the below example...

screen shot 2017-10-09 at 3 29 38 pm

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 I understand why we made duplicates read only, or missing secrets for that matter. Why prevent the user from editing those to fix the problem?

I think it should be a warning if it's there twice, but we shouldn't block it since it's not a validation error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Concur on the blocking at all, that shouldn't happen, and doesn't... kinda. The current implementation doesn't block a user from deleting or rearranging an item, just creating an additional duplicate/triplicate/quad/etc entry through the interface.

Can and will look at using lodash filter instead of find to handle the checks, this may correct the problem, keep you posted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spadgett looks like the aiming towards _.filter achieved the desired result, no more entries being read only if they're duplicates. Leveraged the same concept to apply a temporary placeholder duplicate class around the individual UI-Selects

@spadgett & @benjaminapetersen

On the Readonly state as an all or nothing piece... can push them up, just need a confirmation for the conditions on my local, which so far encompass...

  • If options aren't populated, everything is Read Only
  • If either the Secrets OR Config Maps "Can I" checks fail, everything is Read Only
  • And finally, removed the block (similar to below) for binding attribute pass-through for Read Only
      if('isReadonly' in $attrs) {
        ctrl.isReadonlyAny = true;
      }

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 11, 2017
@spadgett
Copy link
Member

/test

Copy link
Contributor

@benjaminapetersen benjaminapetersen left a comment

Choose a reason for hiding this comment

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

Just a couple optional nits, but works for me when tested. I still do see that flicker after edits, but that might be addressed in your other PR.

@@ -99,8 +100,23 @@
});
};

var updateEnvFromEntries = function(entries) {
ctrl.envFromEntries = entries || [];
var getReferenceValues = function(option) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might be able to nix the switch statements & eliminate some duplication with:

var getReferenceValues = function(option) {
      var kindRef = _.camelCase(option.kind) + 'Ref';
      return _.filter(ctrl.envFromEntries, [kindRef, 'name', option.metadata.name]);      
    };

(untested)

Copy link
Contributor

Choose a reason for hiding this comment

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

Prob similar could be done to trim down lines 76-91

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benjaminapetersen looks like coincidentally wiped some of the duplication out. Good catch on the switch

@cdcabrera cdcabrera force-pushed the issue-envfrom-readonly branch 2 times, most recently from 963e6d0 to c5e53dd Compare October 17, 2017 20:12
};

ctrl.hasEntries = function() {
return angular.toJson(ctrl.entries) !== '[{}]' && ctrl.entries && ctrl.entries.length >= 1;
Copy link
Member

Choose a reason for hiding this comment

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

return _.some(ctrl.entries, function(entry) {
   return _.get(entry, 'configMapRef.name') || _.get(entry, 'secretRef.name');
});

break;
}
_.each(ctrl.envFromSelectorOptions, function(option) {
_.each(getReferenceValues(option), function(val, i) {
Copy link
Member

Choose a reason for hiding this comment

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

You should create two maps of options secretsByName and configMapsByName when options change. Then you can index directly into the map using configMapsByName[option.configMapRef.name], etc.

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.

Need separate maps for secrets and config maps since name is not unique.

I suggest this warning style for duplicates:

openshift web console 2017-10-20 15-22-41


if(!ctrl.envFromEntries.length) {
addEntry(ctrl.envFromEntries);
}
_.each(ctrl.envFromSelectorOptions, function(option) {
optionsByName[option.metadata.name] = option;
});
Copy link
Member

Choose a reason for hiding this comment

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

var secretsByName = {};
var configMapsByName = {};
_.each(ctrl.envFromSelectorOptions, function(option) {
  switch(option.kind) {
    case 'Secret':
      secretsByName[option.metadata.name] = option;
      break;
    // ...
  }
});

Copy link
Member

Choose a reason for hiding this comment

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

Select with .has-warning and .help-block
screen shot 2017-10-20 at 3 37 30 pm

@cdcabrera cdcabrera force-pushed the issue-envfrom-readonly branch 2 times, most recently from b5f4b72 to bdf9017 Compare October 20, 2017 22:20
Fix for making sure the drag and order handles are hidden
within a read only display
@spadgett
Copy link
Member

@cdcabrera The form is showing up as read only for me when it should be editable:

openshift web console 2017-10-24 14-08-07

@spadgett
Copy link
Member

I can no longer reproduce the readonly problem.

@spadgett
Copy link
Member

/lgtm
/hold

Needs #2367 to go in first or merge will fail

@openshift-ci-robot openshift-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Oct 24, 2017
@spadgett spadgett changed the title Environment From Fix Drag & Order Display Bug 1505782 - Environment From Fix Drag & Order Display Oct 24, 2017
@spadgett
Copy link
Member

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 24, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue.

@openshift-merge-robot openshift-merge-robot merged commit 849dda4 into openshift:master Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants