Giter VIP home page Giter VIP logo

react-async-select's Introduction

react-async-select

Description

This component is a combination of a combobox with asynchronous fetching of results and a modal search dialog for more filtering possibilities.

Installation

npm install @opuscapita/react-async-select

Demo

View the DEMO

Migrate guide

View the Migrate guide between major versions

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Prop name Type Default Description
value any The initially selected value
onSelect function () => {} Selection callback function
loadOptions function () => Promise.resolve([]) Function for fetching options for the combobox
isDisabled boolean false Disables the component from user interaction
localizationTexts object A dictionary with translated texts as values
localizationTexts.["searchBy"] string UI text prefix for the first search field
localizationTexts.["by"] string UI text prefix for other search fields
localizationTexts.["close"] string UI text for the Close-button
localizationTexts.["select"] string UI text for the Select-button
localizationTexts.["field.XYZ"] string Label for the search field with name "XYZ"
localizationTexts.["column.XYZ"] string Header for the column with name "XYZ"
localizationTexts.["loading"] string 'Loading...' Loading placeholder text
localizationTexts.["noItems"] string '--' Empty result set text for the dropdown
localizationTexts.["noData"] string 'No rows found' Empty result set text for the modal
localizationTexts.["previous"] string 'Previous' Paging text
localizationTexts.["next"] string 'Next' Paging text
localizationTexts.["page"] string 'Page' Paging text
localizationTexts.["of"] string 'of' Paging text
localizationTexts.["rows"] string 'rows' Paging text
localizationTexts.["pageJump"] string 'jump to page' Paging text
localizationTexts.["rowsSelector"] string 'rows per page' Paging text
modal object Modal dialog specific props
modal.title string '' Localized title of the modal
modal.fields [string] [] List of fields to show as columns
modal.loadOptions function () => Promise.resolve({ data: [], totalCount: 0 }) Function for fetching entries to the table
modal.components object {} A collection of custom components
modal.components.LeftPanel element null Custom component for left side panel
modal.components.RightPanel element null Custom component for right side panel
setRef function () => {} Allows access to select component ref from outside
onKeyDown function () => {} Allows handling of keydown events from outside

Code example

import React, { useState } from 'react';
import { Dropdown } from '@opuscapita/react-component-example';

export default class ReactView extends React.Component {
  const [value, setValue] = useState(null);

  render() {
    return (
      <Dropdown
        localizationTexts={{
          searchBy: 'Search by',
          by: 'By',
          close: 'Close',
          select: 'Select',
          "field.fieldName1": 'my field',
          "field.fieldName2": 'another field'
          "column.fieldName1": 'My field',
          "column.fieldName2": 'Another field',
          "previous": "PREV",
          "next": "NEXT",
          "loading": "LOADING",
          "noData": "NODATA",
          "page": "PAGE",
          "of": "OF",
          "rows": "ROWS",
          "pageJump": "JUMP",
          "rowsSelector": "RPP",
        }}
        isDisabled={false}
        value={value}
        loadOptions={
          () => Promise.resolve([
            { label: 'a_DisplayValue', value: 'a' }
            { label: 'b_DisplayValue', value: 'b' }
          ])
        }
        onSelect={value => setValue(value)}
        modal={{
          title: 'Search entries',
          fields: [
            'fieldName1',
            'fieldName2',
          ],
          loadOptions: () => Promise.resolve({
            data: [
              {
                fieldName1: 'a_DisplayValue',
                fieldName2: 'a_AnotherDisplayValue'
                value: 'a'
              },
              {
                fieldName1: 'b_DisplayValue',
                fieldName2: 'b_AnotherDisplayValue'
                value: 'b'
              },
            ],
            totalCount: 0
          }),
          components: {
            LeftPanel: ({ selectedRow }) => (<div></div>),
            RightPanel: ({ selectedRow }) => (<div></div>),
          }
        }}
      />
    );
  }
}

react-async-select's People

Contributors

jluukka-ge avatar azhurauski-sc avatar

Stargazers

Butonix avatar liyi avatar Nurhak Altın avatar Cristian Razvan avatar  avatar  avatar

Watchers

James Cloos avatar Régis Déau avatar liyi avatar  avatar Dusty Wilhelm Murray avatar Alexander Chernyakevich avatar Dmitriy Dmovskiy avatar

react-async-select's Issues

Empty lines shown in the ReactTable

Background:
When the user has selected a large number of items to be shown in the ReactTable, empty lines are shown if there are not enough results to fill the table.

Task:

  • remove empty lines, showing less than selected number of rows if there are not enough results.

Paging controls send request to server twice

Background:
Paging controls "Next" and "Previous" send two requests to the server, both with different offsets.

Task:
Reduce the number of requests to server to one, if ReactTable component's internal logic allows it.

Example code seems completely different.

Example code import the {Dropdown} from react-component-example, whereas it instructed to install a different package which, when used, gives error that dropdown isnt exported from the file.

Custom sidepanel for search modal

Background:
To improve the advanced search, it would be beneficial to provide additional information to the user. For this purpose, provide a method to display a custom component as a side panel for the advanced search.

Tasks:

  • Modify SearchModal to render a custom component as a sidepanel
  • Add a demo with a custom sidepanel component
  • Update README

Dynamic results for the dropdown component

Related issue in invoice: https://github.com/OpusCapita/invoice/issues/1798

Background:
The customized behavior of the dropdown component for Approval Assignees requires that the result set for any input will be modified by what has been selected before – for one input there may be different result sets. Therefore, we should be able to disable result set caching and similar features.

Task:

  • Investigate if react-select v2 caches result sets by default.
  • Ensure that result sets may be defined only by the fetcher function and any caching methods can be turned off.

Improve localization possibilities

Currently there are hardcoded strings and object property names shown on the UI. Improve localization by:

  • processing all UI texts with i18n object's getMessage function
  • providing a method for transforming the translation keys defined within the component

Custom change handler not working with react-select v2

Background:
The react-select component's behaviour should be customizeable by the caller as it was before react-select v2 upgrade. Examples of different behavior:

  • In the usual case, when a value is selected, it should be displayed on the react-select component.
  • In approval assignee selectors, the selected value is added to a list below the select component. Here, the react-select should not display a selected value after the selection has been made.

Task:

  • Fix the component so that customized behavior works as it did before react-select v2 upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.