1.6.26 • Published 1 month ago

@sparklink-pro/apant v1.6.26

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

apant

Apollo & Antd tools

Table of Contents

Usage

import { TypesContext, TypesRegistry, useTypeList } from "apant";

import client from "./apollo";
import operations from "./gql";
import types from "./types";

const typesRegistry = new TypesRegistry({ types, operations, apollo: client });

const Root = () => (
  <TypesContext.Provider value={typesRegistry}>
    <YourApp />
  </TypesContext.Provider>
);

TypesRegistryConfiguration

PropertyDescriptionTypeDefault
apolloApollo client instanceApolloClient\-
configurationGraphQL Operation configurationPartial<TypeOperationConfiguration>-
operationsGraphQL Operation file{ name: string: any };-
typesList of types configuration{ type: string: TypeConfiguration }-

example type

//types/index.ts
import { Foo } from "./Foo";

export default {
  foo
};

// example/src/types/Book.ts
import { TypeConfiguration } from 'apant';

const Book: TypeConfiguration = {
    label: 'title',
    search: 'title',
    admin: {
        route: 'admin/Book',
        searchable: true,
        selectable: true,
        filter(pattern: any) {
            return pattern.rank >= 9;
        },
        columns: () => [
            {
                title: 'Title',
                dataIndex: 'title',
                link: true,
            },
            {
                title: 'Description',
                dataIndex: 'description',
            },
            {
                title: 'Price',
                dataIndex: 'price',
                sorter: {
                    compare: (a: any, b: any) => a.price - b.price,
                },
            },
        ],
    },
    forms: {
        default: {
            props: {
                layout: 'vertical',
            },
            fields: [
                { name: 'title', label: 'Title' },
                { name: 'description', label: 'Description' },
                { name: 'price', label: 'Price', widget:'number' },
                { name: 'rank', label: 'Rank' },
                { name: 'author', label: 'Author',widget: {widget:'select_type', expand:true , type: 'Author'}},
                { name: 'genres', label: 'Genre', widget: {widget:'select_types', expand:true, type: 'Genre'}},
            ],
        },
    },
};
export default Book;

TypeOperationConfiguration

PropertyDescriptionTypeDefault
adminadmin configurationTypeConfigurationAdmin-
formsA list of configured forms for this types{ formName: string: <FormConfigurationType }-
idWhat is the id property for this type?stringid
labelFor selectTypestring|() =>string|React.ReactNode)'_name' property
metadataAdditional configuration for this type{ key: string: any }-
operationsOperation configuration for given typePartial\<TypeOperationConfiguration>-
orderFor SelectTypeorder:string| {field:string:'asc'|'desc'}'asc'
searchsearch in typestring|string[] | ((object:GraphQLObject,context?:any)=>string)|{custom:(object:GraphQLObject,search:string,context?:any)=>boolean}-
selectSelect type widget configuration{ label: any; fragment: any };-

TypeConfigurationAdmin

PropertyDescriptionTypeDefault
columnsthe configColumns()=>Promise|ColumnsType(see AntDesign)-
creatableallows to create new itemsbooltrue
filterFilter items(item:object)=>boolean-
footerComponentCustom footerReact.ComponentType<AdminHeaderType>-
headerComponentCustom headerReact.ComponentType<AdminHeaderType>-
routestring-
searchableAllow to search in this typebooltrue
selectableAllow to selectbooltrue
propsTableProps<GraphQLObject>-

FormConfigurationType

PropertyDescriptionTypeDefault
fieldsthe fieldsFormEntryType[] | ((context: FormContextType) => FormEntryType[]);-
propsprops?: Omit\<FormProps, 'onFinish'> | ((context: FormContextType) => Omit\<FormProps, 'onFinish'>);-
mappersFormFieldMapperType[] | ((context: FormContextType) => FormFieldMapperType[])-

FormFieldExtraType

PropertyDescriptionTypeDefault
autoShould this field be display when the related form is diplayed automatically?boolfalse
groupIs the field parts of a group ?boolfalse
initialValueWhat is the initial/default value of the field?((context:FormContextType) => any) |any;-
listIs this field a list (ie. Form.List from antd)boolfalse
mappedShould this field be removed before submitting?boolean | ((context: FormContextType) => boolean | Promise);true
autoShould this field be display when the related form is diplayed automatically?boolean | ((context: FormContextType) => boolean | );true

Use AdminType

<AdminType
  key={type}
  type={type}
  heights={{ offset: 16 }}
  {...getDefaultTableProps()}
  />

Use Form

Basic use, if you want further customization, see our demo.

const formConfig = {
  props: { layout: "vertical" },
  fields: [
    {
      name: "name",
      label: "Nom",
      required: true,
      rules: [{ required: true }],
      initialValue: "Ode"
    },
    { name: "firstname", label: "Prénom", initialValue: "Jack" },
    { name: ['position','name'], label: 'Position'},
  ]
};

const object = {
    name: 'Doe',
    city: 'Paris',
    position:{
        name: 'Software Engineer',
        company: 'Google'
    },
};

  //...
  <Form
    config={formConfig}
    onFinish={values => console.log(values)}
    context={{ object }}
    footer={
      <div className="text-center">
        <Button type="primary" htmlType="submit">
          Sauvegarder
        </Button>
      </div>
    }
  />
);
PropertyDescriptionTypeDefault
childrenReact.ReactNode |((fields: FormEntryResolvedType[], form: FormInstance) => React ReactNode)-
configConfiguration of the formFormConfigurationType-
contextContext of the formOmit<FormContextType, 'form'>-
formPropsAdditional form PropsPartial\-
footerthe footerReact.ReactNode-
headerthe headerReact.ReactNode-
onValueProcess form values before submitting(values: object, context: FormContextType) => Promise\;
& Omit\<FormAntProps, 'children'>

Working locally with apant

Working locally with apant relies on yalc and yarn.

First, you neeed to compile the project.

$ cd apant
$ yarn
$ yarn build

Then, you'll need to publish the project with yalc.

$ yalc publish
apant@xxx published in store.

The project is now in the yalc store and is available to use for other project.

Use the apant in your project

To use the library in your local project, you need to link it with yalc.

$ cd myproject/
$ yalc link apant

apant is now linked to the project.

Work in realtime

To work and use apant in realtime, we must watch apant for change, compile it and publish it the yalc store.
To do so, we use the npm command defined in the package.json by

"watch-publish": "tsc-watch --onSuccess \"yalc push\""
$ cd apant/
$ yarn watch-publish

Test

1.6.26

1 month ago

1.6.25

1 month ago

1.6.24

3 months ago

1.6.23

3 months ago

1.6.22

3 months ago

1.6.21

5 months ago

1.6.17

5 months ago

1.6.18

5 months ago

1.6.20

5 months ago

1.6.4

6 months ago

1.6.3

7 months ago

1.6.2

8 months ago

1.6.1

10 months ago

1.6.0

10 months ago

1.6.11

5 months ago

1.6.10

5 months ago

1.6.13

5 months ago

1.6.15

5 months ago

1.6.14

5 months ago

1.6.16

5 months ago

1.6.9

5 months ago

1.6.7

5 months ago

1.6.6

6 months ago

1.6.5

6 months ago

1.5.26

10 months ago

1.5.25

11 months ago

1.5.24

11 months ago

1.5.23

12 months ago

1.5.22

12 months ago

1.5.18

1 year ago

1.5.17

1 year ago

1.5.19

1 year ago

1.5.21

1 year ago

1.5.20

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.4.2

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.5.10

1 year ago

1.5.12

1 year ago

1.5.11

1 year ago

1.5.14

1 year ago

1.5.13

1 year ago

1.5.16

1 year ago

1.5.15

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.3.3

1 year ago

1.4.0

1 year ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.3.2

2 years ago

1.1.4

2 years ago

1.3.1

2 years ago

1.2.2

2 years ago

1.1.3

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago