Skip to content

Commit

Permalink
Merge branch 'main' into renovate/configure
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle authored Sep 18, 2023
2 parents efe7170 + b518c6c commit f8f4a64
Show file tree
Hide file tree
Showing 223 changed files with 5,325 additions and 43,133 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
message: 'Update Storybook beta (develop branch)'
branch: 'gh-pages'


publish_beta_on_npm:
runs-on: ubuntu-latest
steps:
Expand All @@ -66,7 +65,7 @@ jobs:
- run: |
yarn build
- name: Publishing on NPM
run: |
run: |
git config --global user.email "[email protected]"
git config --global user.name "Insee"
export TAG=beta
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Create release

on:
push:
branches:
- main

jobs:
check-version:
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Print version
run: echo ${{ steps.version.outputs.version }}
- uses: mukunku/[email protected]
name: Check tag existence
id: check-tag-exists
with:
tag: ${{ steps.version.outputs.version }}

- if: ${{ steps.check-tag-exists.outputs.exists == 'false' }}
name: Check tag format
id: check-tag-format
run: |
if ! [[ "${{ steps.version.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "is-tag-format-correct=false" >> $GITHUB_OUTPUT
fi
- name: Tag verification
id: check-tag
run: |
if [[ "${{ steps.check-tag-exists.outputs.exists }}" == "true" ]]; then
echo "Nothing to tag/release, the tag ${{ steps.version.outputs.version }} already exists"
exit 1
fi
if ! [[ "${{ steps.version.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "Nothing to tag/release, the tag ${{ steps.version.outputs.version }} is not in correct format X.Y.Z"
exit 1
fi
create-release:
needs: check-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Get previous final release tag
id: previousTag
run: |
previousTag=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$" | tail -1)
if [ -z "$previousTag" ]; then
echo "previousTag=$(git rev-list --max-parents=0 HEAD)" >> $GITHUB_OUTPUT
else
echo "previousTag=$previousTag" >> $GITHUB_OUTPUT
fi
- name: Create release note
id: changelog
uses: requarks/changelog-action@v1
with:
fromTag: ${{ github.sha }}
toTag: ${{ steps.previousTag.outputs.previousTag}}
token: ${{ secrets.GITHUB_TOKEN }}
writeToFile: false
- uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-version.outputs.release-version }}
target_commitish: ${{ github.head_ref || github.ref }}
name: ${{ needs.check-version.outputs.release-version }}
body: ${{steps.changelog.outputs.changes}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/publish-stable-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
export TAG=prisme
export NEW_VERSION=${{steps.version.outputs.prop}}-$TAG ;;
esac
if [ "$(npm show . dist-tags.$TAG)" = "$NEW_VERSION" ]; then
echo "This version is already published"
exit 1
Expand All @@ -108,7 +108,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 15
node-version: 16
- uses: bahmutov/npm-install@v1
- run: yarn
# Build Storybook
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Code quality
name: Code quality

on: [push]

Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests - Unit & End to end

on:
push:
branches: [main]
branches: ['main','develop']
pull_request_target:
branches: [main]
branches: ['main','develop']

jobs:
test:
Expand All @@ -25,10 +25,8 @@ jobs:
run: yarn playwright install --with-deps
- name: Build Storybook
run: yarn run build-storybook --quiet
- name: Serve Storybook and run tests
run: npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" "npx http-server storybook-static --port 9999 --silent" "npx wait-on tcp:9999 && yarn run test:storybook"
- name: E2E Tests
run: npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" "npx http-server storybook-static --port 9999 --silent" "npx wait-on tcp:9999 && yarn run test:e2E"
run: npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" "npx http-server storybook-static --port 9999 --silent" "npx wait-on tcp:9999 && yarn run test:e2e"
- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ playwright-report
test-report.xml
/playwright-report/
/playwright/.cache/
*.tgz
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,44 @@

# Lunatic

[![Lunatic CI](https://github.com/InseeFr/Lunatic/actions/workflows/ci.yml/badge.svg)](https://github.com/InseeFr/Lunatic/actions/workflows/ci.yml)
[![Lunatic CI](https://github.com/InseeFr/Lunatic/actions/workflows/quality.yml/badge.svg)](https://github.com/InseeFr/Lunatic/actions/workflows/quality.yml)
[![npm version](https://badge.fury.io/js/%40inseefr%2Flunatic.svg)](https://badge.fury.io/js/%40inseefr%2Flunatic)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=InseeFr_Lunatic&metric=coverage)](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=InseeFr_Lunatic&metric=alert_status)](https://sonarcloud.io/dashboard?id=InseeFr_Lunatic)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

Lunatic est une librairie front-end sous forme de hook react et de librairies de composants pour générer un questionnaire à partir du format de données [Lunatic-Model](https://github.com/InseeFr/Lunatic-Model).

- [Storybook v2](https://inseefr.github.io/Lunatic/storybook-v2)
- [Storybook v1](https://inseefr.github.io/Lunatic/storybook-v1)
- [Storybook Beta](https://inseefr.github.io/Lunatic/storybook-beta)
- [Editeur Lunatic](https://inseefr.github.io/Lunatic/editor/)
- [Storybook](https://inseefr.github.io/Lunatic/storybook), branche `main`
- [Storybook v1](https://inseefr.github.io/Lunatic/storybook-v1), branche `v1-main`
- [Storybook Beta](https://inseefr.github.io/Lunatic/storybook-beta), branche `develop`
- [Documentation](https://inseefr.github.io/Lunatic/fr/)

## Sommaire

- [Lunatic](#lunatic)
- [Sommaire](#sommaire)
- [Utilisation](#utilisation)
- [Le hook useLunatic](#le-hook-uselunatic)
- [Les composants](#les-composants)
- [Personnalisation](#personnalisation)
- [Fonctionnement interne](#fonctionnement-interne)
- [Fonctionnement général](#fonctionnement-général)
- [pages et pager](#pages-et-pager)
- [Exécution du VTL](#exécution-du-vtl)
- [Convention et bonnes pratiques](#convention-et-bonnes-pratiques)
- [Sommaire](#sommaire)
- [Utilisation](#utilisation)
- [Le hook useLunatic](#le-hook-uselunatic)
- [Les composants](#les-composants)
- [Personnalisation](#personnalisation)
- [Fonctionnement interne](#fonctionnement-interne)
- [Fonctionnement général](#fonctionnement-général)
- [pages et pager](#pages-et-pager)
- [Exécution du VTL](#exécution-du-vtl)
- [Convention et bonnes pratiques](#convention-et-bonnes-pratiques)

## Utilisation

Pour commencer il faut installer lunatic

```bash
yarn add @inseefr/lunatic@2.0.7-v2
yarn add @inseefr/lunatic@2.5.0
```

### Le hook useLunatic

Ensuite, à l'endroit où vous souhaitez afficher le formulaire il faudra utiliser le hook `useLunatic`.
Ensuite, à l'endroit où vous souhaitez afficher le formulaire il faudra utiliser le hook `useLunatic`.

```js
import { useLunatic } from '@inseefr/lunatic';
Expand All @@ -56,8 +55,9 @@ Ce hook prend 3 paramètres :
- **features** (défaut `['VTL', 'MD']`), permet de définir les fonctionnalité supportées
- **preferences** (défaut `['COLLECTED']`)
- **onChange** (défaut `() => {}`), permet d'ajouter une logique à appliquer lorsqu'une réponse est modifiée (doit être mémoïsé car est utilisé comme dépendance d'un useCallback en interne)
- **management** (défaut `false`)
- **management** (défaut `false`) : Non implémenté encore, permettra de gérer plusieurs état d'une même variable (utilisation par des postes de reprise)
- **initialPage** (défaut `'1'`), permet de définir la page de départ
- **lastReachedPage** (défaut `undefined`) permet de définir quelle est la page la plus lointaine déjà atteinte
- **autoSuggesterLoading** (défaut `false`)
- **suggesters**
- **suggesterFetcher** (défaut `fetch`), méthode utilisée pour récupérer les données du suggester
Expand All @@ -68,7 +68,7 @@ Et retourne un objet permettant de piloter le questionnaire :
- `getComponents()`, renvoie les composants à afficher pour la page courante
- `goPreviousPage()`, permet d'aller à la page précédente
- `goNextPage()`, permet d'aller à la page suivante
- `goToPage(page: string)`, permet d'aller à une page arbitraire
- `goToPage({ page: string })`, permet d'aller à une page arbitraire
- `getErrors()`, renvoie les erreurs
- `getModalErrors()`, renvoie les erreurs dans les modales
- `getCurrentErrors()`, renvoie les erreurs de la page courante
Expand Down Expand Up @@ -120,14 +120,14 @@ Par défaut les composants offerts par Lunatic sont plutôt simples avec un styl

```jsx
const custom = {
Input: MyCustomInput,
InputNumber: MyCustomInputNumber
}
Input: MyCustomInput,
InputNumber: MyCustomInputNumber,
};

function App({ source, data }) {
const {} = useLunatic(source, data, { custom });

function App ({source, data}) {
const {} = useLunatic(source, data, {custom})

// ...
// ...
}
```

Expand Down
5 changes: 2 additions & 3 deletions e2e/simpson.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { test, expect } from '@playwright/test';

test('can complete simpson form', async ({ page }) => {
page.setDefaultTimeout(30_000);
page.setDefaultNavigationTimeout(30_000);
await page.goto(
'http://localhost:9999/iframe.html?viewMode=story&id=questionnaires-simpsons--default'
);
Expand Down Expand Up @@ -40,7 +42,6 @@ test('can complete simpson form', async ({ page }) => {
await page.getByRole('button', { name: 'Next' }).click();
await page
.getByRole('combobox', { name: '➡ In which state do The Simpsons reside?' })
.locator('div')
.click();
await page.getByText('Not in any state, you fool!').click();
await page.getByRole('button', { name: 'Next' }).click();
Expand Down Expand Up @@ -98,7 +99,6 @@ test('can complete simpson form', async ({ page }) => {
name: 'Break the windows of the whole city',
})
.getByRole('combobox')
.locator('div')
.click();
await page.getByText('Krusty the clown').click();
await page
Expand Down Expand Up @@ -136,7 +136,6 @@ test('can complete simpson form', async ({ page }) => {
.getByRole('radio', { name: 'Down' })
.click();
await page.getByRole('button', { name: 'Next' }).click();
await page.getByRole('row', { name: 'Leave with pay' }).fill('12');
await page
.getByRole('row', { name: 'Leave with pay' })
.getByText('Please, do something...')
Expand Down
4 changes: 0 additions & 4 deletions example/lunatic-editor/.env

This file was deleted.

23 changes: 0 additions & 23 deletions example/lunatic-editor/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions example/lunatic-editor/LICENSE

This file was deleted.

3 changes: 0 additions & 3 deletions example/lunatic-editor/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions example/lunatic-editor/jsconfig.json

This file was deleted.

41 changes: 0 additions & 41 deletions example/lunatic-editor/package.json

This file was deleted.

Binary file removed example/lunatic-editor/public/favicon.ico
Binary file not shown.
Loading

0 comments on commit f8f4a64

Please sign in to comment.