Skip to content

Added documentation for htmlIdGenerator - #3076

Merged
cchaos merged 30 commits into
elastic:masterfrom
anishagg17:util
Mar 27, 2020
Merged

cchaos merged 30 commits into
elastic:masterfrom
anishagg17:util

Conversation

@anishagg17

@anishagg17 anishagg17 commented Mar 14, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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?

@chandlerprall chandlerprall left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

@chandlerprall chandlerprall left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

All changes have been made

@cchaos

cchaos commented Mar 19, 2020

Copy link
Copy Markdown
Contributor

Jenkins test this

@kibanamachine

Copy link
Copy Markdown
Contributor

@anishagg17

Copy link
Copy Markdown
Contributor Author

@cchaos I have added description,

@anishagg17

anishagg17 commented Mar 20, 2020 •

Copy link
Copy Markdown
Contributor Author

I have updated it accordingly

@cchaos cchaos left a comment

Copy link
Copy Markdown
Contributor

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.

@anishagg17

Copy link
Copy Markdown
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
Copy Markdown
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

anishagg17 commented Mar 24, 2020 •

Copy link
Copy Markdown
Contributor Author

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

chandlerprall commented Mar 24, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

The generator function has been updated.

@chandlerprall

Copy link
Copy Markdown
Contributor

jenkins test this

@kibanamachine

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Functionality & docs interactions LGTM

@chandlerprall
chandlerprall requested a review from cchaos March 25, 2020 16:35
@anishagg17
anishagg17 requested a review from cchaos March 26, 2020 20:43

@cchaos cchaos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, thanks!

@cchaos

cchaos commented Mar 27, 2020

Copy link
Copy Markdown
Contributor

One last, jenkins test this

@kibanamachine

Copy link
Copy Markdown
Contributor

@cchaos
cchaos merged commit bbc5db3 into elastic:master Mar 27, 2020
elizabetdev pushed a commit to elizabetdev/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