Display rich inline nodes in @atlaskit/jql-editor on change

Hi everyone. I’m using @atlaskit/jql-editor component in my ReactJs project. I want to display rich inline nodes (avatar + name) for specific user values. I enable it by passing enableRichInlineNodes to true and an onHydrate props, which will only work if I reload the page or paste the user values

But I want to display rich inline nodes on query change as well (when I choose a user from suggestions), like how Jira did with JQL editor for assignee. How can i achieve it? Does JQLEditor support this, or i have to implement on my own?

Images:

Thank you in advance

Hey @NgocDuLe do you have an example implementation you could share? The behaviour you’re describing should work out of the box if you are initialising the component using useAutocompleteProvider from @atlaskit/jql-editor-autocomplete-rest.

2 Likes

Hi @Kyle , this is my code:

import { useCallback, useState } from "react";
import { JQLEditorAsync as JQLEditor } from "@atlaskit/jql-editor";
import { useAutocompleteProvider } from "@atlaskit/jql-editor-autocomplete-rest";

const getInitialData = async (url: string) => {
  return {
    jqlFields: [
      {
        value: `"user"`,
        displayName: "User",
        searchable: "true",
        orderable: "true",
        auto: "true",
        operators: ["=", "!=", "in"],
        types: ["user"],
      },
    ],
    jqlFunctions: [],
  };
};

const getSuggestions = async (url: string) => {
  return {
    results: [
      {
        value: `user1`,
        displayName: `User1`,
      },
      {
        value: `user2`,
        displayName: `User2`,
      },
      {
        value: `user3`,
        displayName: `User3`,
      },
    ],
  };
};

const MyJQLEditor = () => {
  const autocompleteProvider = useAutocompleteProvider(
    "my-app",
    getInitialData,
    getSuggestions
  );

  const [query, setQuery] = useState<string>(`"user" in (user1, user2, user3)`);

  const onUpdate = useCallback((jql: string) => {
    setQuery(jql);
  }, []);

  const onSearch = useCallback((jql: string) => {
    // Do some action on search
  }, []);

  return (
    <div>
      <button
        onClick={() => {
          setQuery(`"user" in (user1, user2, user3)`);
        }}
      >
        Reset
      </button>

      <JQLEditor
        analyticsSource={"my-app"}
        query={query}
        onUpdate={onUpdate}
        onSearch={onSearch}
        autocompleteProvider={autocompleteProvider}
        locale={"en"}
        enableRichInlineNodes={true}
        onHydrate={async (jql: string) => {
          return {
            user: [
              {
                type: "user",
                id: "user1",
                name: "User1",
                avatarUrl:
                  "https://lh3.googleusercontent.com/a/ACg8ocLWtffEyTpLLscynj5qsU_ZgbRZBWet07WGg8K7B5REGV07QQ=s96-c",
              },
              {
                type: "user",
                id: "user2",
                name: "User2",
                avatarUrl:
                  "https://lh3.googleusercontent.com/a/ACg8ocLWtffEyTpLLscynj5qsU_ZgbRZBWet07WGg8K7B5REGV07QQ=s96-c",
              },
              {
                type: "user",
                id: "user3",
                name: "user3",
                avatarUrl:
                  "https://lh3.googleusercontent.com/a/ACg8ocLWtffEyTpLLscynj5qsU_ZgbRZBWet07WGg8K7B5REGV07QQ=s96-c",
              },
            ],
          };
        }}
      />
    </div>
  );
};

export default MyJQLEditor;

packages version:
@atlaskit/jql-editor”: “^4.5.2”,
@atlaskit/jql-editor-autocomplete-rest”: “^2.0.1”,
“react”: “^18.3.1”,
“react-dom”: “^18.3.1”,
“react-router-dom”: “^6.26.1”,
“react-scripts”: “5.0.1”,
“typescript”: “^4.4.2”,

Images:

it will display rich-inline-node when you refresh the page or paste the user value or reset the query.
I want it to display rich-inline-node after choosing user in the editor aswell. Thank you so much

@NgocDuLe in order for rich inline nodes to appear after autocomplete the selected field must have a valid type, i.e. types: ["com.atlassian.jira.user.ApplicationUser"].

You can fetch the autocomplete data using the Jira Cloud REST API which will ensure the correct type is provided.

2 Likes

This solved my problem. Thank you @Kyle for really fast reply

1 Like

Hey @Kyle , sorry for bothering you again.
The rich-inline-node after choosing from autocomplete doesn’t display the proper avatar url (it uses the default avatar).
Do I have to do something else?

The sample code given looks correct. I’d double check if your onHydrate function is being called after selecting an autocomplete option and if the underlying img element in the DOM has the correct src set.

1 Like

Hey @Kyle , sorry for bothering you again.
The rich-inline-node after choosing from autocomplete doesn’t display the proper avatar url (it uses the default avatar).
Do I have to do something else?

The sample code given looks correct. I’d double check if your onHydrate function is being called after selecting an autocomplete option and if the underlying img element in the DOM has the correct src set.

This problem still exists until now :smiling_face_with_tear:.
Do you know the solution for it @Kyle ?