3.0.5 • Published 12 days ago

@balena/autoui v3.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
12 days ago

AutoUI

A library of UI components, built using React, styled-components to allow building a UI just using a model.

Table of Contents

Installation

npm install --save autoui

Usage

Wrap your application in the AutoUIProvider component and start using components!

import React from 'react';
import ReactDOM from 'react-dom';
import { AutoUIProvider } from 'autoui';
import {
	AutoUIBaseResource,
	AutoUIRawModel,
	autoUIDefaultPermissions,
	autoUIJsonSchemaPick,
  autoUIRunTransformers,
  autoUIGetModelForCollection,
} from 'autoui';


type AugmentedRelease = AutoUIBaseResource<{}>

interface EntityType {
  id: number,
  name: string,
  surname: string,
}

const observerPermissions = {
	read: [
		'id',
		'name',
		'surname',
	],
	create: [],
	update: [],
	delete: false,
};

const adminPermissions = {
	...observerPermissions,
	create: ['name'],
	update: ['name'],
	delete: true,
};

const model = {
  resource: 'user',
  schema: {
    type: 'object',
    required: [],
    properties: {
      id: {
        title: 'Id',
        type: 'number',
      },
      name: {
        title: 'Name',
        type: 'string',
      },
      surname: {
        title: 'Surname',
        type: 'string',
      },
    },
  },
  permissions: {
    default: autoUIDefaultPermissions,
    administrator: adminPermissions,
    developer: adminPermissions,
    member: autoUIDefaultPermissions,
    operator: observerPermissions,
    observer: observerPermissions,
    support_agent: observerPermissions,
    balena_admin: observerPermissions,
  },
  priorities: {
    primary: ['name'],
    secondary: [
      'surname',
      'id',
    ],
    tertiary: [],
  },
} as AutoUIRawModel<Partial<AugmentedRelease>>;

// where the UI can add new properties, but this will be removed soon as everything should live in the model
const transformers = {
	__permissions: (entity: BalenaSdk.Release, context: any) => {
		return model(getExpanded(entity.belongs_to__application)?.is_of__class!)
			.permissions[context.accessRole ?? 'default'];
	},
};

const App = () => {

  const data = [
    {
        "id": 2313948,
        "name": "John",
        "surname": "Smith",
    },
    {
        "id": 2307403,
        "name": "Robert",
        "surname": "Taylor",
    }
  ]

  const memoizedData = React.useMemo(() => {
		return autoUIRunTransformers(data, transformers, {});
	}, [data]);

	const memoizedModel = React.useMemo(() => {
		return autoUIGetModelForCollection(model);
	}, [model]);

	return <AutoUIProvider>
    <AutoUI<EntityType>
      data={data}
      model={model}
    />
  </AutoUIProvider>
};

ReactDOM.render(
  <App/>,
  document.getElementById('root')
);

Provider

Wrap your application in the <Provider> component so that child components can correctly inherit the following properties:

  • t: used for translations (expected lib i18n-next)
  • history: used to allow persistent filters. (expected lib history)

Contributing

Please read our contribution guidelines

3.0.5

18 days ago

3.0.4

19 days ago

3.0.3

23 days ago

3.0.2

26 days ago

3.0.1

30 days ago

3.0.0

1 month ago

2.0.3

1 month ago

2.0.2

1 month ago

2.0.1

2 months ago

2.0.0

2 months ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago

0.12.1

3 months ago

0.12.2

3 months ago

0.12.3

3 months ago

0.12.0

3 months ago

0.11.5

5 months ago

0.11.4

5 months ago

0.11.3

5 months ago

0.10.1

10 months ago

0.10.0

10 months ago

0.11.0

9 months ago

0.11.1

6 months ago

0.11.2

6 months ago

0.9.3

11 months ago

0.9.2

11 months ago

0.9.1

11 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.8.0

1 year ago

0.6.9

1 year ago

0.6.10

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.8

1 year ago

0.5.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.4.1

1 year ago

0.6.1

1 year ago

0.4.3

1 year ago

0.6.0

1 year ago

0.4.2

1 year ago

0.4.0

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago