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] label template not showing value for url-image #1888

Open
Julien-athstat opened this issue Jul 12, 2022 · 5 comments
Open

[BUG] label template not showing value for url-image #1888

Julien-athstat opened this issue Jul 12, 2022 · 5 comments
Assignees
Labels
bug Something isn't working discover for discover reinvent good first issue Good for newcomers

Comments

@Julien-athstat
Copy link

Describe the bug
Label Template not showing {{Value}} when changing field format to url-image

To Reproduce
Steps to reproduce the behavior:

  1. Go to '[Stack Management]
    [Index patterns]'
  2. Click on 'Edit' to edit a string field
  3. Set "URL template" and "Label template"
  4. Sample will show expected behavior
  5. Go to Discover or a sample table with that field; ONLY the image will show NOT the Label

Expected behavior
That edited field should show the url-image and the field {{value}} as label next to the image

OpenSearch Version
1.2.0
Dashboards Version
1.2.0

Screenshots
Screenshot 2022-07-12 at 19 03 06
Screenshot 2022-07-12 at 19 03 26

Host/Environment (please complete the following information):

  • OS: macOS Monterey
  • Browser and version: Chrome Version 103.0.5060.114 (Official Build) (x86_64)
@Julien-athstat Julien-athstat added bug Something isn't working untriaged labels Jul 12, 2022
@kavilla kavilla changed the title [BUG] [BUG] label template not showing value for url-image Jul 12, 2022
@ananzh ananzh self-assigned this Jul 13, 2022
@ananzh ananzh removed the untriaged label Jul 13, 2022
@ananzh
Copy link
Member

ananzh commented Jul 15, 2022

I can re-produce this issue.
Screen Shot 2022-07-15 at 12 09 25

The reason is that the icons loaded are missing basePath, so the path is not correct and img can't be found. By adding the basePath in the browser, the problem is solved.
Screen Shot 2022-07-15 at 13 01 36

Screen Shot 2022-07-15 at 12 37 44

Issue code is at UrlFormatEditor component.

I will keep research on how to add basePath to this component.

ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Jul 18, 2022
The bug is caused by missing base path. This PR
uses opensearch_dashboards_ react context to get the
base path. Append the base path to original path.

Issue resolved:
opensearch-project#1888

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Jul 18, 2022
The bug is caused by missing base path. This PR
uses opensearch_dashboards_ react context to get the
base path. Append the base path to original path.

Issue resolved:
opensearch-project#1888

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Jul 18, 2022
The bug is caused by missing base path. This PR
uses opensearch_dashboards_ react context to get the
base path. Append the base path to original path.

Issue resolved:
opensearch-project#1888

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
ananzh added a commit to ananzh/OpenSearch-Dashboards that referenced this issue Jul 18, 2022
The bug is caused by missing base path. This PR
uses opensearch_dashboards_ react context to get the
base path. Append the base path to original path.

Issue resolved:
opensearch-project#1888

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
@ananzh
Copy link
Member

ananzh commented Nov 28, 2022

This is because in url format htmlConverter (https://github.com/opensearch-project/OpenSearch-Dashboards/blob/7f7c7449e8fcf3a3ad58bd8f009cc7830131758b/src/plugins/data/common/field_formats/converters/url.ts#L158)](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/808129bcf077912c2ed4af5aea517c32ec1315a5/src/plugins/data/common/field_formats/converters/url.ts#L160)

const baseUrl = escape(this.formatUrl(rawValue));

the baseUrl doesn't have the basePath (the random 3 letters, like rtl). I think there are two ways to fix this.

Add the basePath in url.ts

const baseUrl = escape(this.formatUrl(rawValue));
const url = basePath ? basePath.concat(baseUrl) : baseUrl;

change urlTemplate

We could also modify this from formatUrl(rawValue) method

private formatUrl(value: string): string {
    const template = this.param('urlTemplate');
    if (!template) return value;

    return this.compileTemplate(template)({
      value: encodeURIComponent(value),
      rawValue: value,
    });
}

we could see it is compile the urlTemplate. urlTemplate for img is created here. The default value is null. Once the url format img type is chosen, it will be set in indexPattern. An index pattern is constructed like

- id: "90943e30-9a47-11e8-b64d-95841ca0b247"
- title: "opensearch_dashboards_sample_data_logs"
- Fields (FldList(41)) // contains all field definitions
For example, for clientip, an IndexPatternField object will be
displayName: clientip
spec:
   aggregatable: true
   name: "clientip"
   type: "ip"
   format: DecoratedFieldFormat
       _params
           parsedUrl
               	basePath: "/jxv"
                 
                origin: "http://localhost:5603"
                 
                pathname: "/jxv/app/home"
           **urlTemplate: undefined // it will be reset**
           type: "img"

- fieldFormats (FieldFormatsRegistry object which register about 15 format types)

Currently it is set to a fixed value

/plugins/indexPatternManagement/assets/icons/{{value}}.png

To fix, we could change it to a func to fetch basePath and prepend it to the original path

private getIconPath = () => {
    const iconPath = `/plugins/indexPatternManagement/assets/icons/{{value}}.png`;
    return this.context?.services.http
      ? this.context.services.http.basePath.prepend(iconPath)
      : iconPath;
};

@joshuarrrr joshuarrrr added the discover for discover reinvent label Dec 9, 2022
@ananzh ananzh added the good first issue Good for newcomers label Oct 10, 2023
@vvavdiya
Copy link
Contributor

@ananzh
I would like to look into issue. can please assign to me?

@joshuarrrr
Copy link
Member

@vvavdiya Make sure you can first reproduce the issue locally - feel free to ask here if you need more help to reproduce it.

@vvavdiya
Copy link
Contributor

@ananzh
I am trying to reproduce the issue. I have created dashboard with sample ecommerce data.
Can you please help how I can reach/navigate to Label template page?
steps or screen record would be helpful to reproduce the issue.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discover for discover reinvent good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants