lodash#findKey TypeScript Examples

The following examples show how to use lodash#findKey. 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: operation.ts    From openapi-mock-express-middleware with MIT License 6 votes vote down vote up
getResponseStatus(): number {
    const responses = get(this.operation, 'responses');

    if (!responses) {
      return 200;
    }

    const status: string | undefined = findKey(responses, (content, code) => {
      const statusCode = parseInt(code, 10);

      if (Number.isNaN(statusCode)) {
        return false;
      }

      return statusCode >= 200 && statusCode < 299;
    });

    return status ? parseInt(status, 10) : 200;
  }
Example #2
Source File: completion-items.ts    From ui5-language-assistant with Apache License 2.0 5 votes vote down vote up
function getClassNamespacePrefix(
  suggestion: UI5ClassesInXMLTagNameCompletion,
  additionalTextEdits: TextEdit[]
): string | undefined {
  const xmlElement = suggestion.astNode;
  const parent = suggestion.ui5Node.parent;
  /* istanbul ignore else */
  if (parent !== undefined) {
    const parentFQN = ui5NodeToFQN(parent);
    let xmlnsPrefix = findKey(xmlElement.namespaces, (_) => _ === parentFQN);
    // Namespace not defined in imports - guess it
    if (xmlnsPrefix === undefined) {
      // It should be the parent simple name by default, but if that already exists we'll add an index to it (name2 etc)
      xmlnsPrefix = parent.name;
      let i = 2;
      while (
        find(xmlElement.namespaces, (v, k) => k === xmlnsPrefix) !== undefined
      ) {
        xmlnsPrefix = parent.name + i;
        ++i;
      }
      const addNamespaceEdit = getAddNamespaceEdit(
        xmlElement,
        xmlnsPrefix,
        parentFQN
      );
      // Add text edit for the missing xmlns attribute definition
      // The 'else' should not happen because it would only happen in case we can't find the root element of
      // the document, and in that case we also won't get any suggestions for classes
      /* istanbul ignore else */
      if (addNamespaceEdit !== undefined) {
        additionalTextEdits.push(addNamespaceEdit);
      }
    }
    if (
      xmlnsPrefix !== undefined &&
      xmlnsPrefix !== DEFAULT_NS &&
      xmlnsPrefix.length > 0
    ) {
      return xmlnsPrefix;
    }
  }
  return undefined;
}
Example #3
Source File: table-drawer.tsx    From erda-ui with GNU Affero General Public License v3.0 5 votes vote down vote up
TableDrawer = (props) => {
  const [tableRowClassNameMap, setTableRowClassNameMap] = React.useState({});

  const initTableRowClassNameMap = (_centerRelatedGroup: any) => {
    const COLOR_KEYS = ['purple', 'pink', 'green', 'purple-2', 'blue', 'red', 'green-2', 'orange'];
    const result = reduce(
      _centerRelatedGroup,
      (acc, value) => ({ ...acc, [COLOR_KEYS.pop() || '']: value.map((item: any) => item.relAttr) }),
      {},
    );
    setTableRowClassNameMap(result);
  };

  const {
    drawerVisible,
    closeDrawer,
    isFetching,
    tableAttrsList,
    tableAttrsPaging,
    centerRelatedGroup,
    getTableAttrs,
    selectedItem,
  } = props;
  const { pageNo: current, total } = tableAttrsPaging;

  React.useEffect(() => {
    centerRelatedGroup && initTableRowClassNameMap(centerRelatedGroup);
    !isEmpty(selectedItem) && getTableAttrs({ filePath: get(selectedItem, 'file'), pageNo: 1 });
  }, [centerRelatedGroup, getTableAttrs, selectedItem]);

  const getRelatedGroupClassName = (enName: string) => {
    return findKey(tableRowClassNameMap, (item: string[]) => item.includes(enName));
  };

  const onTableSearch = (searchKey: string) => {
    getTableAttrs({ filePath: get(selectedItem, 'file'), searchKey, pageNo: 1 });
  };

  const onPageChange = (pageNo: number) => {
    getTableAttrs({ filePath: get(selectedItem, 'file'), pageNo });
  };

  return (
    <Drawer
      destroyOnClose
      title={i18n.t('dop:class catalog')}
      width="50%"
      visible={drawerVisible}
      onClose={closeDrawer}
    >
      <Spin spinning={isFetching}>
        <SearchTable
          placeholder={i18n.t('dop:search by chinese/english name of attribute')}
          onSearch={onTableSearch}
          needDebounce
        >
          <Table
            columns={columns}
            rowKey="enName"
            rowClassName={({ enName }) =>
              centerRelatedGroup ? `with-group-tag group-tag-${getRelatedGroupClassName(enName)}` : ''
            }
            dataSource={tableAttrsList}
            pagination={{
              current,
              pageSize: PAGINATION.pageSize,
              total,
              onChange: onPageChange,
            }}
            scroll={{ x: '100%' }}
          />
        </SearchTable>
      </Spin>
    </Drawer>
  );
}