@atlassianlabs/jql-editor

中文文档
2.0.1发布于 2023/07/12TypeScriptESM + CJS近 30 天下载 2562

This package allows consumers to render an advanced JQL editor component to enable autocomplete-assisted authoring and validation of JQL queries.

原始使用文档
文档目录6 节
  1. Usage
  2. Installation
  3. Documentation
  4. Searching and authoring JQL
  5. Support
  6. License

JQL Editor

Atlassian license

This package allows consumers to render an advanced JQL editor component to enable autocomplete-assisted authoring and validation of JQL queries.

Usage

To render the editor, the consumer must configure an autocompleteProvider, which defines callback functions used to retrieve JQL fields, functions and values. To ease configuration, we also ship the @atlassianlabs/jql-editor-autocomplete-rest package, which wraps these callbacks and provides simple hooks to delegate to Jira REST API's.

A minimal configuration of the JQL editor is as follows:

import { useCallback } from 'react';
import { JQLEditorAsync as JQLEditor } from '@atlassianlabs/jql-editor';
import { useAutocompleteProvider } from '@atlassianlabs/jql-editor-autocomplete-rest';

const getInitialData = async (url: string) => {
  const response = await fetch(url, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ includeCollapsedFields: true })
  });
  const data = response.json();

  return {
    jqlFields: data.visibleFieldNames,
    jqlFunctions: data.visibleFunctionNames,
  };
};

const getSuggestions = async (url: string) => {
  const response = await fetch(url);
  return response.json();
};

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

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

  return (
    <JQLEditor
      analyticsSource={'my-app'}
      query={''}
      onSearch={onSearch}
      autocompleteProvider={autocompleteProvider}
      locale={"en"}
    />
  );
};

For app developers, please refer to the @atlassianlabs/jql-editor-connect and @atlassianlabs/jql-editor-forge packages. Which come pre-configured with Jira autocomplete integration.

Installation

yarn add @atlassianlabs/jql-editor

Documentation

Searching and authoring JQL

There are two main use cases for the editor:

  1. Searching by a JQL query
  2. Authoring a JQL query

The key difference between the two is that rendering a search button may not make sense when authoring JQL, e.g. when using the JQL editor as a form input. The searching use case is documented above, here we'll discuss authoring.

Authoring JQL

Hiding the search button is as simple as not providing an onSearch prop. Instead you'll want to use onUpdate which is triggered whenever the query is updated.

By default, the editor will automatically show any syntax errors when the user presses search. Without the search button the consumer will need to set errors to show manually.

import { useCallback, useMemo, useState } from 'react';
import { Jast, JQLParseError } from '@atlassianlabs/jql-ast';
import { JQLEditorAsync as JQLEditor, ExternalError } from '@atlassianlabs/jql-editor';
import debounce from 'lodash/debounce';

const MyJQLEditor = () => {
  const [errors, setErrors] = useState<ExternalError[]>([]);

  const debounceSetErrors = useMemo(() => {
    // Update our errors after a 1 second debounce
    return debounce((parseErrors: JQLParseError[]) => {
      // Format JQL parse errors to be shown as custom error messages in the editor
      const errorMessages: ExternalError[] = parseErrors.map(({ description }) => ({
        message: description,
        type: 'error',
      }));
      setErrors(errorMessages)
    }, 1000);
  }, [setErrors]);

  const onUpdate = useCallback((jql: string, jast: Jast) => {
    debounceSetErrors(jast.errors)
  }, []);

  return (
    <JQLEditor
      analyticsSource={'my-app'}
      query={''}
      onUpdate={onUpdate}
      messages={errors}
      autocompleteProvider={/* ... */}
      locale={"en"}
    />
  );
};

Using the same API, the editor may also show warning and info messages:

const [messages] = useState<ExternalMessage[]>([
  { type: 'error', message: `I'm an error message`} as ExternalError,
  { type: 'warning', message: `I'm a warning message`} as ExternalWarning,
  { type: 'info', message: `I'm an info message`} as ExternalInfo,
]);

return (
  <JQLEditor
    {/* ... */}
    messages={messages}
  />
);

Its worth mentioning that messages are rendered by the priority and only a single type of messages could be present on UI at once.

So in the example above, only an error message will be rendered.

Support

For developers outside of Atlassian looking for help, or to report issues, please make a post on the community forum . We will monitor the forums and redirect topics to the appropriate maintainers.

License

Copyright (c) 2021 - 2022 Atlassian and others. Apache 2.0 licensed, see LICENSE file.

版本与发布记录

@atlassianlabs/jql-editor 共发布 8 个版本,首次发布于 2021/12/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.1latest2023/07/123 年前
2.0.02023/06/023 年前
1.2.02022/09/264 年前
1.1.02022/08/114 年前
1.0.02022/02/214 年前
0.0.32021/12/174 年前

关于 @atlassianlabs/jql-editor 的常见问题

@atlassianlabs/jql-editor 是什么?

This package allows consumers to render an advanced JQL editor component to enable autocomplete-assisted authoring and validation of JQL queries.

如何安装 @atlassianlabs/jql-editor?

在项目目录运行 npm install @atlassianlabs/jql-editor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.8.0)、react-dom(^16.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atlassianlabs/jql-editor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atlassianlabs/jql-editor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atlassianlabs/jql-editor 可以商用吗?

@atlassianlabs/jql-editor 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@atlassianlabs/jql-editor 的下载量有多少?

根据 npm 官方下载统计,@atlassianlabs/jql-editor 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,562 次,日均约 85 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atlassianlabs/jql-editor 还在维护吗?

最新版本 2.0.1 发布于 2023/07/12(3 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/12/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。