<commit_before>import * as React from "react";
import * as moment from "moment"
import * as numbro from "numbro"
import * as QueryString from "query-string"
import * as Navigator from "./Navigator"
import { Dic, classes } from './Globals'
import { ajaxGet, ajaxPost } from './Services';

import {
  QueryDescription, QueryValueRequest, QueryRequest, QueryEntitiesRequest, FindOptions,
  FindOptionsParsed, FilterOption, FilterOptionParsed, OrderOptionParsed, ValueFindOptionsParsed,
  QueryToken, ColumnDescription, ColumnOption, ColumnOptionParsed, Pagination, ResultColumn,
  ResultTable, ResultRow, OrderOption, SubTokensOptions, toQueryToken, isList, ColumnOptionsMode, FilterRequest, ModalFindOptions, OrderRequest, ColumnRequest,
  isFilterGroupOption, FilterGroupOptionParsed, FilterConditionOptionParsed, isFilterGroupOptionParsed, FilterGroupOption, FilterConditionOption, FilterGroupRequest, FilterConditionRequest, PinnedFilter, SystemTime, QueryTokenType
} from './FindOptions';

import { PaginationMode, OrderType, FilterOperation, FilterType, UniqueType, QueryTokenMessage, FilterGroupOperation } from './Signum.Entities.DynamicQuery';

import { Entity, Lite, toLite, liteKey, parseLite, EntityControlMessage, isLite, isEntityPack, isEntity, External, SearchMessage, ModifiableEntity } from './Signum.Entities';
import { TypeEntity, QueryEntity } from './Signum.Entities.Basics';

import {
  Type, IType, EntityKind, QueryKey, getQueryNiceName, getQueryKey, isQueryDefined, TypeReference,
  getTypeInfo, getTypeInfos, getEnumInfo, toMomentFormat, toNumbroFormat, PseudoType, EntityData,
  TypeInfo, PropertyRoute, QueryTokenString
} from './Reflection';

import SearchModal from './SearchControl/SearchModal';
import EntityLink from './SearchControl/EntityLink';
import SearchControlLoaded from './SearchControl/SearchControlLoaded';
import { ImportRoute } from "./AsyncImport";
import { SearchControl } from "./Search";
import ButtonBar from "./Frames/ButtonBar";
import { json, namespace } from "d3";
import { ButtonBarElement } from "./TypeContext";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { EntityBase } from "./Lines";


export const querySettings: { [queryKey: string]: QuerySettings } = {};

export function clearQuerySettings() {
  Dic.clear(querySettings);
}


export function start(options: { routes: JSX.Element[] }) {
  options.routes.push(<ImportRoute path="~/find/:queryName" onImportModule={() => FinderFindManager.getSearchPage()} />);
}

export function addSettings(...settings: QuerySettings[]) {
  settings.forEach(s => Dic.addOrThrow(querySettings, getQueryKey(s.queryName), s));
}

export function pinnedSearchFilter<T extends Entity>(type: Type<T>, ...tokens: ((t: QueryTokenString<T>) => (QueryTokenString<any> | FilterConditionOption))[]): FilterGroupOption {
  return pinnedSearchFilterWithValue(type, undefined, ...tokens);
}

export function pinnedSearchFilterWithValue<T extends Entity>(type: Type<T>, value: string | undefined, ...tokens: ((t: QueryTokenString<T>) => (QueryTokenString<any> | FilterConditionOption))[]): FilterGroupOption {
  return {
    groupOperation: "Or",
    value: value,
    pinned: { splitText: true },
    filters: tokens.map(t => {
      var res = t(type.token());

      if (res instanceof QueryTokenString)
        return { token: res, operation: "Contains" } as FilterConditionOption;

      return res;
    })
  };
} 

export function getSettings(queryName: PseudoType | QueryKey): QuerySettings | undefined {
  return querySettings[getQueryKey(queryName)];
}

export const isFindableEvent: Array<(queryKey: string, fullScreen: boolean) => boolean> = [];

export function isFindable(queryName: PseudoType | QueryKey, fullScreen: boolean): boolean {

  if (!isQueryDefined(queryName))
    return false;

  const queryKey = getQueryKey(queryName);

  return isFindableEvent.every(f => f(queryKey, fullScreen));
}

export function find<T extends Entity = Entity>(findOptions: FindOptions, modalOptions?: ModalFindOptions): Promise<Lite<T> | undefined>;
export function find<T extends Entity>(type: Type<T>, modalOptions?: ModalFindOptions): Promise<Lite<T> | undefined>;
export function find(obj: FindOptions | Type<any>, modalOptions?: ModalFindOptions): Promise<Lite<Entity> | undefined> {<commit_msg>remove pinnedSearchFilterWithValue<commit_after>import * as React from "react";
import * as moment from "moment"
import * as numbro from "numbro"
import * as QueryString from "query-string"
import * as Navigator from "./Navigator"
import { Dic, classes } from './Globals'
import { ajaxGet, ajaxPost } from './Services';

import {
  QueryDescription, QueryValueRequest, QueryRequest, QueryEntitiesRequest, FindOptions,
  FindOptionsParsed, FilterOption, FilterOptionParsed, OrderOptionParsed, ValueFindOptionsParsed,
  QueryToken, ColumnDescription, ColumnOption, ColumnOptionParsed, Pagination, ResultColumn,
  ResultTable, ResultRow, OrderOption, SubTokensOptions, toQueryToken, isList, ColumnOptionsMode, FilterRequest, ModalFindOptions, OrderRequest, ColumnRequest,
  isFilterGroupOption, FilterGroupOptionParsed, FilterConditionOptionParsed, isFilterGroupOptionParsed, FilterGroupOption, FilterConditionOption, FilterGroupRequest, FilterConditionRequest, PinnedFilter, SystemTime, QueryTokenType
} from './FindOptions';

import { PaginationMode, OrderType, FilterOperation, FilterType, UniqueType, QueryTokenMessage, FilterGroupOperation } from './Signum.Entities.DynamicQuery';

import { Entity, Lite, toLite, liteKey, parseLite, EntityControlMessage, isLite, isEntityPack, isEntity, External, SearchMessage, ModifiableEntity } from './Signum.Entities';
import { TypeEntity, QueryEntity } from './Signum.Entities.Basics';

import {
  Type, IType, EntityKind, QueryKey, getQueryNiceName, getQueryKey, isQueryDefined, TypeReference,
  getTypeInfo, getTypeInfos, getEnumInfo, toMomentFormat, toNumbroFormat, PseudoType, EntityData,
  TypeInfo, PropertyRoute, QueryTokenString
} from './Reflection';

import SearchModal from './SearchControl/SearchModal';
import EntityLink from './SearchControl/EntityLink';
import SearchControlLoaded from './SearchControl/SearchControlLoaded';
import { ImportRoute } from "./AsyncImport";
import { SearchControl } from "./Search";
import ButtonBar from "./Frames/ButtonBar";
import { json, namespace } from "d3";
import { ButtonBarElement } from "./TypeContext";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { EntityBase } from "./Lines";


export const querySettings: { [queryKey: string]: QuerySettings } = {};

export function clearQuerySettings() {
  Dic.clear(querySettings);
}


export function start(options: { routes: JSX.Element[] }) {
  options.routes.push(<ImportRoute path="~/find/:queryName" onImportModule={() => FinderFindManager.getSearchPage()} />);
}

export function addSettings(...settings: QuerySettings[]) {
  settings.forEach(s => Dic.addOrThrow(querySettings, getQueryKey(s.queryName), s));
}

export function pinnedSearchFilter<T extends Entity>(type: Type<T>, ...tokens: ((t: QueryTokenString<T>) => (QueryTokenString<any> | FilterConditionOption))[]): FilterGroupOption {
  return {
    groupOperation: "Or",
    pinned: { splitText: true },
    filters: tokens.map(t => {
      var res = t(type.token());

      if (res instanceof QueryTokenString)
        return { token: res, operation: "Contains" } as FilterConditionOption;

      return res;
    })
  };
} 

export function getSettings(queryName: PseudoType | QueryKey): QuerySettings | undefined {
  return querySettings[getQueryKey(queryName)];
}

export const isFindableEvent: Array<(queryKey: string, fullScreen: boolean) => boolean> = [];

export function isFindable(queryName: PseudoType | QueryKey, fullScreen: boolean): boolean {

  if (!isQueryDefined(queryName))
    return false;

  const queryKey = getQueryKey(queryName);

  return isFindableEvent.every(f => f(queryKey, fullScreen));
}

export function find<T extends Entity = Entity>(findOptions: FindOptions, modalOptions?: ModalFindOptions): Promise<Lite<T> | undefined>;
export function find<T extends Entity>(type: Type<T>, modalOptions?: ModalFindOptions): Promise<Lite<T> | undefined>;
export function find(obj: FindOptions | Type<any>, modalOptions?: ModalFindOptions): Promise<Lite<Entity> | undefined> {
{'fraction_non_alphanumeric': 0.11736469458778351, 'fraction_numerical': 0.00024000960038401536, 'mean_word_length': 6.4344335414808205, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533771', 'n_tokens_mistral': 2308, 'n_tokens_neox': 2290, 'n_words': 616}