Skip to content

Eui sharing top nav#21997

Merged
nreese merged 33 commits intoelastic:masterfrom
nreese:euiSharingTopNav
Aug 28, 2018
Merged

Eui sharing top nav#21997
nreese merged 33 commits intoelastic:masterfrom
nreese:euiSharingTopNav

Conversation

@nreese
Copy link
Copy Markdown
Contributor

@nreese nreese commented Aug 15, 2018

EUI share top nav

screen shot 2018-08-14 at 9 27 22 am

screen shot 2018-08-14 at 9 27 30 am

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 15, 2018

@snide @cchaos Do you know why the tooltip is disabled when the radio group option is disabled? The tooltip behaves weirdly. When the menu is first opened, the tooltip is opened even though the user has not moused over the icon.

To reproduce the problem, checkout this PR and create a new dashboard. Before saving the dashboard, click the share top nav button. Select either option in the context menu. Notice how the tooltip is open when the panel first opens.

screen shot 2018-08-15 at 8 15 31 am

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 15, 2018

My guess would be that it's trying to put focus into the popover and finding the first focusable element which would be the tooltip since the first radio is disabled?

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 15, 2018

sounds like a good theory. How do I make it stop doing that?

@snide
Copy link
Copy Markdown
Contributor

snide commented Aug 15, 2018

That's definitely what it is. I tried looking at this local but it doesn't seem to work. This is using a context menu which by nature hijacks focus and places it in the first available item within the panel.

Off hand I can't think of a quick way around this other than reorganizing your form so that a disabled item isn't first (ex: moving short url before the other options).

@snide
Copy link
Copy Markdown
Contributor

snide commented Aug 15, 2018

Happy to troubleshoot when I get started today (9AM PST)

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 15, 2018

The short URL option can't be moved because it's dependent on the selection of choosing "snapshot". It's not available for saved objects.

Could adding autofocus on the first enabled radio work?

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 15, 2018

@cchaos that worked. I will have to create a PR in EUI to pass autoFocus down from the radio group option to the radio input

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 15, 2018

@snide @cchaos Another work around is to just change the order of options so that the disabled option is never first.

screen shot 2018-08-15 at 9 31 40 am

Which is the preferred solution? Changing the radio group order or passing autoFocus in?

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 15, 2018

The nice think about swapping them is that when the saved object option is disabled the help text is more closely coupled with the disabled option. However, when the saved object option is enabled, it's set to the default picked option, which seems odd to me that the default wouldn't be first.

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 15, 2018

I guess, just to make your life easier, swap the options :). But can you make an issue in EUI that we need to be able pass more options per radio from radio group?

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@stacey-gammon
Copy link
Copy Markdown

can trigger a console error:

Warning: Failed prop type: The prop textToCopyis marked as required inEuiCopy, but its value is undefined.

Steps to repro:

  1. Open permalink share menu.
  2. Switch to saved object type
  3. Modify url and click enter

I think this is because url is stored on state, so when it's set to null after a refresh, it causes the object to re-render.

I made some code suggestions here: c61b3ed

They are:

  • Using enum type instead of string type for exportUrlAs
  • Combined getUrl and setUrl. Rather than read from passed in parameters, it's just reading the values off state.
  • Combined url and shortUrl. Made getUrl async so there is no need for the short url creation to communicate to the caller via the special this.state.shortUrl value, but through the return value of createShortUrl.
  • Changed type of this.state.url to not allow undefined, instead setting default value to an empty string to avoid the prop warning from above. Also got rid of resetUrl from setting the url to undefined. It turns off short url, so the function is then synchronous, so it should always set the url to something in setState. I don't think we have to clear it out before updating the url.

Take what you like!

Do you think it would be difficult to add a jest test to ensure saved object url copied does not include _a parameter? I made a mistake in my first suggestions code that failed to use the right url and jest tests still passed.

allowEmbed: boolean;
objectId?: string;
objectType: string;
getUnhashableStates: () => any[];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Think you can make this object[] to be a little more specific, until we have state definitions.

? `Can't share as saved object until the ${this.props.objectType} has been saved.`
: undefined;
return (
<EuiFormRow label="Generate the link as" helpText={generateLinkAsHelp}>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe something to file in EUI, but this shows up as a clickable link which is a little strange.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

);
};

private handleShortUrlChange = async (evt: any) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you add a comment here to switch this to ChangeEvent<HTMLInputElement> or EuiSwitchChangeCallback once elastic/eui#1134 is fixed?

try {
await this.createShortUrl();
} catch (fetchError) {
this.setState(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think this will ever be hit because there is already a try/catch inside this.ceateShortUrl. I think you can get rid of this outer one and just add useShortUrl: false inside the catch from createShortUrl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The error was getting re-thrown. I have cleaned up the logic by moving creatingShortUrl into handleShortUrlChange so its easier to follow the logic

const defaultUseShortUrl = false;

this.state = {
exportUrlAs: defaultExportUrlAs,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can do:

enum ExportUrlAsType {
  EXPORT_URL_AS_SAVED_OBJECT = 'savedObject',
  EXPORT_URL_AS_SNAPSHOT = 'snapshot',
}

interface State {
  exportUrlAs: ExportUrlAsType;
  useShortUrl: boolean;
  isCreatingShortUrl: boolean;
  url?: string;
  shortUrl?: string;
  shortUrlErrorMsg?: string;
}
...

    const defaultExportUrlAs = ExportUrlAsType.EXPORT_URL_AS_SNAPSHOT;
....

        id: ExportUrlAsType.EXPORT_URL_AS_SNAPSHOT,
etc, etc

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 22, 2018

Combined url and shortUrl. Made getUrl async so there is no need for the short url creation to communicate to the caller via the special this.state.shortUrl value, but through the return value of createShortUrl.

The existing angular implementation stored shortUrl to avoid the network overhead of creating new shortUrl every time the checkbox is selected. The network overhead does not matter much, but if the implementation of /api/shorten_url ever changed you could get into a situation where each time the user checked the box then a new short url token would be created. This is not the case now but I think caching the results of /api/shorten_url prevent unneeded server calls.

@stacey-gammon
Copy link
Copy Markdown

Interesting. I don't think that would need to be part of state, if we wanted to cache the results. Could just store mapping of full url to short url, look it up if available and use that instead of createShortUrl.

something like:

       const snapshotUrl = this.getSnapshotUrl();
       if (this.state.useShortUrl) {
          if (!this.shortUrlCache.contains(snapshotUrl) {
            this.shortUrlCache[snapshotUrl] = await this.createShortUrl();
          }
          url = this.shortUrlCache[snapshotUrl];
        } else {
          url = snapshotUrl;
        }
}

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

Did not pull latest code. Extra test looks good!

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@nreese
Copy link
Copy Markdown
Contributor Author

nreese commented Aug 28, 2018

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@nreese nreese merged commit 9d24c00 into elastic:master Aug 28, 2018
nreese added a commit to nreese/kibana that referenced this pull request Aug 28, 2018
* just getting the popover to open and start laying out the context menu

* pass getUnhashableStates to ShareMenu

* generate original and snapshot ids

* move state into ShareUrlContent

* start working on form

* use radio group

* add input for creating short URL

* display URL in alert until copy functionallity gets migrated to EUI

* allowEmbed prop

* replace share directive with showShareContextMenu

* fix button styling

* add jest test for share_context_menu

* use EuiCopy to copy URL, add jest test for ShareUrlContent component

* clean up

* display short URL create error message in form instead of with toast

* switch option order so disbaled option can not be first

* fix discover share functional tests

* add functions required by reporting

* typescript

* remove empty file

* fix typescript compile error

* move import so jest tests work

* fix Failed prop type: The proptextToCopyis marked as required inEuiCopy, but its value isundefined

* move shortUrl out of react state and into Component object

* getUnhashableStates type from any[] to object[]

* add comment about type change once EUI issue is solved

* add functional test for saved object URL sharing

* remove commit
nreese added a commit that referenced this pull request Aug 28, 2018
* just getting the popover to open and start laying out the context menu

* pass getUnhashableStates to ShareMenu

* generate original and snapshot ids

* move state into ShareUrlContent

* start working on form

* use radio group

* add input for creating short URL

* display URL in alert until copy functionallity gets migrated to EUI

* allowEmbed prop

* replace share directive with showShareContextMenu

* fix button styling

* add jest test for share_context_menu

* use EuiCopy to copy URL, add jest test for ShareUrlContent component

* clean up

* display short URL create error message in form instead of with toast

* switch option order so disbaled option can not be first

* fix discover share functional tests

* add functions required by reporting

* typescript

* remove empty file

* fix typescript compile error

* move import so jest tests work

* fix Failed prop type: The proptextToCopyis marked as required inEuiCopy, but its value isundefined

* move shortUrl out of react state and into Component object

* getUnhashableStates type from any[] to object[]

* add comment about type change once EUI issue is solved

* add functional test for saved object URL sharing

* remove commit
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.

5 participants