Code Monkey home page Code Monkey logo

ngqp's Introduction

Build Status npm version Coverage Conventional Commits Gitter

ngqp logo

ngqp

Declaratively synchronize form controls with the URL
Documentation

Description

ngqp makes it easy to synchronize form controls with query parameters in your URL by using a declarative approach. Examples include pagination information or the current settings of filters in a data view. ngqp is designed to resemble the Forms API from @angular/forms, making it intuitive to work with.

Quick Start

ng add @ngqp/core

Read the Getting Started page for information on how to use it.

Contributing

See CONTRIBUTING.md.

Code of Conduct

Please take a moment to read the Code of Conduct.


MIT License

ngqp's People

Contributors

airblader avatar alexey-anufriev avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ngqp's Issues

Update README

  • CoC
  • License section
  • Demo → Website
  • Super-small installation
  • Getting help

Provide simple means of building, deploying and publishing

  • Have a single release script that takes care of: removing dist, building with prod and base href, running standard-version, publishing to npm and deploying the demo
  • How to extract and build API documentation and add to the demo?
  • Make sure to copy README + LICENSE

Provide a StackBlitz starter

What's your idea?

We could provide a Stackblitz starter template which has a small example preconfigured. This could be linked in the README.

Should combineWith work with form controls instead of params?

Currently, `combineWith' is required to return a list of "finished" query params. However, it could also be useful to instead return a list of control names + values. This would require that

  1. serializers are run on these values
  2. combineWith is evaluated recursively

Perhaps introducing this as a separate combineWithValue option would be best since it might make sense to retain both features separately.

This issue serves as a placeholder for future discussion.

Support controls with multiple values

We should support controls which can take multiple values (such as a multi-select). On the URL side, this should just use Angular's router functionality for array values.

We need to think about the API for this as it might also affect (de-)serializer signatures. Very likely we at least need some multi: boolean property to also know whether to call get or getAll.

Provide a keepEmptyOn option

What's your idea?

When using emptyOn, the value is not only used as a default if missing in the URL, but also the parameter is removed from the URL if the form control takes on this value. If we want to avoid the latter, we currently need to create a custom deserializer. Perhaps adding a simple keepEmptyOn: boolean would make this a bit easier to use.

Support routing options per QueryParam

What's your idea?

Router options like replaceUrl are currently set either globally or per QueryParamGroup. We should consider whether we should also allow a third override per QueryParam.

If so, the replaceUrl example should be updated to use this mechanism.

[Feature] Track events in Google Analytics

We already track navigations, but maybe worth tracking as events:

  • Interactions with the demo browser (send URL, go back)
  • Viewing HTML / Typescript code
  • Using the TOC
  • Switching to the API Docs (not tracked since external)

Support debouncing controls

It should be possible to define a debounce: number property on a QueryParamControl which debounces the change. It needs to be defined still whether the change should be debounced before or after the URL is updated.

The use-case for this is, e.g., a text input search field where it's very likely that a user would want to debounce this, but not other controls (such as dropdowns), so allowing this gives users an easy way to achieve it.

Refactor synchronization logic into a service

What's your idea?

All the "meat" of the logic is currently handled in QueryParamGroupDirective. As a first step, this should be refactored into a service (which this directive then provides) to decouple the logic from the view directive. A further step would be to have this redirect to some global service which can orchestrate the different groups or whatever together.

Pass history state to determine whether to ignore a route change

Once Angular 7.2.0 lands, we should update the dependency to it and use this.router.getCurrentNavigation().extras.state and navigate(…, {state: {ngqp: true}} to determine whether to ignore a change in the route.

This would replace the current mechanism of using compareWith. We could consider making this optional again as a result.

[RELEASE] Release V1

This issue is meant to coordinate the first release:

  • Make a breaking change announcement commit
  • Adapt schematics to use v1 for Angular 7

Changes in a control should have the ability to change other parameters as well

There should be some configuration surface that allows changing other parameters when the model of a control changes. The use-case would be pagination where changing certain controls needs to reset the current page.

A first idea is to provide a combineWith: (previousValue: T, currentValue: T) => Params coniguration option on control level.

[Bug] Github button disappears when coming back to main page

What does the bug look like?
The GitHub social button on the landing page works if that's the page you load initially, but once you navigate away and come back it no longer works.

How can this bug be reproduced?

  1. Go to https://ngqp.io
  2. Navigate to "docs"
  3. Click on the logo in the upper left

The GitHub button is now gone and just a link is shown.

Provide an interface for form controls to implement (de-)serializers

We should expose an interface like QueryParamAccessor (see below) for form controls to implement. Note that this should use an injection token as we might want to provide this on native controls (to be determined).

This would allow using a form control without specifying a (de-)serializer on param control level. If those are specified, they need to take precedence.

A possible interface would look like this:

interface QueryParamAccessor<T> {
    serializeValue: (value: T | null) => string | null;
    deserializeValue: (value: string | null) => T | null;
}

Support all base value accessors

The missing ones are currently:

  • NumberValueAccessor (can just exend the default accessor and override the change function)
  • RangeValueAccessor (can just extend the default accessor and override the writeValue function)
  • CheckboxValueAccessor
  • RadioControlValueAccessor
  • SelectMultipleControlValueAccessor (only meaningful once #5 is implemented)

The radio one is a bit tricky since here we will have multiple form controls with the same queryParamName. This means we need to properly support using the same name on multiple controls.

(Edit: which should now work)

Tests

Rapid prototyping is cool, but we need to ensure we know our library before we ship it, so make sure we have a good test coverage.

Add documentation for custom URL serializer

Since this is very much related to the stated goal of ngqp, it would make sense to provide some easily accessible information for that even if it isn't directly handled by ngqp.

[Feature] Add separate schematics package?

If we added a separate @ngqp/schematics package to handle ng add, we could determine the Angular version used and install the appropriate ngqp version. This assumes we align the versions with Angular.

Update QueryParam properties dynamically

What's your idea?

Currently, all properties of QueryParam are "fixed". We should consider for each option whether it makes sense to support changing the configuration dynamically (and implement it).

[Feature] Passing an array to the group builder

Allowing to pass an array / rest params rather than an object to the group builder would allow removing the potentially unnecessary duplication of control name and parameter name for users who don't care about this:

builder.group(
  builder.param({/*…*/}),
  builder.param({/*…*/}),
);

Support emptyOn for multi-params

Perhaps requires a separate mechanism / refactoring since currently emptyOn is evaluated in the serializer, which is invoked per-value.

Avoid type aliases in API

What's your idea?

We should avoid type aliases like RouterAdapterOptions and instead use proper interfaces.

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.