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

Added documentation for htmlIdGenerator #3076

Merged
merged 30 commits into from
Mar 27, 2020
Merged

Conversation

anishagg17
Copy link
Contributor

@anishagg17 anishagg17 commented Mar 14, 2020

Summary

Fixes : #639
added documentation for htmlIdGenerator with all cases

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox
- [ ] Props have proper autodocs

  • Added documentation examples
    - [ ] Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
    - [ ] A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Some comments that apply to the suffix/prefix examples,

  • Use EuiFormRow to provide a label for the input boxes; placeholder text should be used to provide example data, not to label the field
  • Use EuiFieldText instead of EuiFieldSearch
  • I think it'd be nice if the examples pre-populated the input boxes to better demonstrate their use, instead of leaving them unused by default.

@anishagg17
Copy link
Contributor Author

I have made the requested changes. Also, I have removed the reGenerate button so that user can see live changes with clicking on the button unnecessarily

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Let's trim the examples down to one generated ID per section; having a mix of 1, 2, and 3 examples is a little confusing

@anishagg17
Copy link
Contributor Author

All changes have been made

@cchaos
Copy link
Contributor

cchaos commented Mar 19, 2020

Jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3076/

anishagg17 and others added 12 commits March 19, 2020 19:34
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
@anishagg17
Copy link
Contributor Author

@cchaos I have added description,

@anishagg17
Copy link
Contributor Author

anishagg17 commented Mar 20, 2020

I have updated it accordingly

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

@chandlerprall I don't think the prefix with suffix example is working properly. The function never produces a generated string. It just concatenates the prefix with an underscore then suffix.

So doing htmlIdGenerator('Some')('Id') produces Some_Id.

Co-Authored-By: Caroline Horn <549577+cchaos@users.noreply.github.com>
@anishagg17
Copy link
Contributor Author

it('should create the same id for the same suffix', () => {

I think this should not be the desired behaviour

@cchaos cchaos changed the title added documentation for htmlIdGenerator Added documentation for htmlIdGenerator Mar 24, 2020
@chandlerprall
Copy link
Contributor

Heh, you're right. Didn't realize the original function worked that way that - we should continue supporting the existing test cases, including the original logic of ${suffix || uuid()}. Go ahead and revert back... Actually - this shouldn't need any changes to the function itself. Why were those changes made? (we've been going through so much typescript conversion lately I'd assumed this was being converted from JS and needed to be updated to pass typescript, I apologize for the oversight).

@anishagg17
Copy link
Contributor Author

anishagg17 commented Mar 24, 2020

So doing htmlIdGenerator('Some')('Id') produces Some_Id.

This was the main cause to change the function, currently

if no suffix is provided it generates

prefix_UUID_UUID

if there is a suffix it renders

prefix_UUID_suffix

It also includes the logic ${suffix || uuid()}

Earlier also if no prefix and no suffix was provided it generated UUID_UUID

@chandlerprall
Copy link
Contributor

chandlerprall commented Mar 24, 2020

Ach, thank you. This is an annoying set of rules! The following passes tests and the values shown in the docs appear correct

export function htmlIdGenerator(idPrefix: string = '') {
  const staticUuid = uuid.v1();
  return (idSuffix: string = '') => {
    const prefix = `${idPrefix}${idPrefix !== '' ? '_' : 'i'}`;
    const suffix = idSuffix ? `_${idSuffix}` : '';
    return `${prefix}${suffix ? staticUuid : uuid.v1()}${suffix}`;
  };
}

@anishagg17
Copy link
Contributor Author

The generator function has been updated.

@chandlerprall
Copy link
Contributor

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3076/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Functionality & docs interactions LGTM

@anishagg17 anishagg17 requested a review from cchaos March 26, 2020 20:43
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@cchaos
Copy link
Contributor

cchaos commented Mar 27, 2020

One last, jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3076/

@cchaos cchaos merged commit bbc5db3 into elastic:master Mar 27, 2020
miukimiu pushed a commit to miukimiu/eui that referenced this pull request Mar 30, 2020
@anishagg17 anishagg17 deleted the util branch July 11, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document htmlIdGenerator use cases
5 participants