@grafana/data#escapeStringForRegex TypeScript Examples

The following examples show how to use @grafana/data#escapeStringForRegex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterInput.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
FilterInput = forwardRef<HTMLInputElement, Props>((props, ref) => (
  <label className={props.labelClassName}>
    <input
      ref={ref}
      type="text"
      className={props.inputClassName}
      value={unEscapeStringFromRegex(props.value)}
      onChange={event => props.onChange(escapeStringForRegex(event.target.value))}
      placeholder={props.placeholder ? props.placeholder : null}
    />
    <i className="gf-form-input-icon fa fa-search" />
  </label>
))
Example #2
Source File: renderer.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
initColumns() {
    this.formatters = [];
    this.colorState = {};

    for (let colIndex = 0; colIndex < this.table.columns.length; colIndex++) {
      const column = this.table.columns[colIndex];
      column.title = column.text;

      for (let i = 0; i < this.panel.styles.length; i++) {
        const style = this.panel.styles[i];

        const escapedPattern = stringStartsAsRegEx(style.pattern)
          ? style.pattern
          : escapeStringForRegex(unEscapeStringFromRegex(style.pattern));
        const regex = stringToJsRegex(escapedPattern);
        if (column.text.match(regex)) {
          column.style = style;

          if (style.alias) {
            column.title = escapeHtml(column.text.replace(regex, style.alias));
          }

          break;
        }
      }

      this.formatters[colIndex] = this.createColumnFormatter(column);
    }
  }
Example #3
Source File: TagFilter.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
render() {
    const tags = this.props.tags.map(tag => ({ value: tag, label: tag, count: 0 }));

    const selectOptions = {
      classNamePrefix: 'gf-form-select-box',
      isMulti: true,
      defaultOptions: true,
      loadOptions: this.onLoadOptions,
      onChange: this.onChange,
      className: 'gf-form-input gf-form-input--form-dropdown',
      placeholder: 'Tags',
      loadingMessage: () => 'Loading...',
      noOptionsMessage: () => 'No tags found',
      getOptionValue: (i: any) => i.value,
      getOptionLabel: (i: any) => i.label,
      value: tags,
      styles: resetSelectStyles(),
      filterOption: (option: any, searchQuery: string) => {
        const regex = RegExp(escapeStringForRegex(searchQuery), 'i');
        return regex.test(option.value);
      },
      components: {
        Option: TagOption,
        IndicatorsContainer,
        NoOptionsMessage,
        MultiValueLabel: (): any => {
          return null; // We want the whole tag to be clickable so we use MultiValueRemove instead
        },
        MultiValueRemove: (props: any) => {
          const { data } = props;

          return (
            <components.MultiValueRemove {...props}>
              <TagBadge key={data.label} label={data.label} removeIcon={true} count={data.count} />
            </components.MultiValueRemove>
          );
        },
      },
    };

    return (
      <div className="gf-form gf-form--has-input-icon gf-form--grow">
        <div className="tag-filter">
          <AsyncSelect {...selectOptions} />
        </div>
        <i className="gf-form-input-icon fa fa-tag" />
      </div>
    );
  }