Skip to content

Commit

Permalink
docs: enum field
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed May 23, 2024
1 parent 19576be commit 9473f72
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/models/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default class Test extends BaseModel {
@column({ isPrimary: true })
declare id: number

// @column()
// declare stringArrayTest: string[]
@column()
declare stringArrayTest: string[]

@column()
declare freeText: string
Expand Down
24 changes: 12 additions & 12 deletions app/test_adomin_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ export const PROFILE_CONFIG = createModelViewConfig(() => Profile, {
export const TEST_CONFIG = createModelViewConfig(() => Test, {
label: 'Test',
columns: {
// stringArrayTest: { type: 'array' },
// freeText: { type: 'string', label: 'Texte libre' },
// stringTest: {
// nullable: true,
// type: 'enum',
// label: 'Test select',
// options: [
// { label: '(Non renseigné)', value: null },
// { label: 'Salut', value: 'hello' },
// { label: 'Au revoir', value: 'bye' },
// ],
// },
stringArrayTest: { type: 'array' },
freeText: { type: 'string', label: 'Texte libre' },
stringTest: {
nullable: true,
type: 'enum',
label: 'Test enum',
options: [
{ label: '(Non renseigné)', value: null },
{ label: 'Salut', value: 'hello' },
{ label: 'Au revoir', value: 'bye' },
],
},
dateTest: { type: 'date', subType: 'date', defaultValue: { mode: 'now', plusDays: 2 } },
datetimeTest: { type: 'date', subType: 'datetime', defaultValue: { mode: 'now', plusDays: 2 } },
numberTest: { type: 'number' },
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/1697188415177_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class extends BaseSchema {
table.string('file_url')

// specific to postgresql
// table.specificType('string_array_test', 'text[]').defaultTo('{}')
table.specificType('string_array_test', 'text[]').defaultTo('{}')

table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE')

Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/backend/views/models/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ queryBuilderCallback: (q) => {

### [Date field](/adomin/docs/backend/views/models/date/)

### Enum field
### [Enum field](/adomin/docs/backend/views/models/enum/)

### File field

Expand Down
40 changes: 40 additions & 0 deletions docs/content/docs/backend/views/models/enum/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
weight: 5
title: 'Enum field'
---

# Enum field

{{< br >}}

In the table page, an enum field will look like this

![field image](/adomin/images/models/enum/table_enum.png)

In the create / edit page

![edit field image](/adomin/images/models/enum/enum.png)

## Config

### options

Options for the select component

example:

```ts
{
type: 'enum',
label: 'Test enum',
options: [
{ label: '(Non renseigné)', value: null },
{ label: 'Salut', value: 'ref_1' },
{ label: 'Au revoir', value: 'ref_2' },
],
}
```

### defaultValue

Optionnal, a static default value to show on the creation form
132 changes: 132 additions & 0 deletions docs/content/docs/frontend/deployment/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
weight: 3
title: 'Deployment'

---

# Frontend deployment

{{< br >}}

To deploy the Adomin frontend, you will need to:

- run `yarn build` with correct VITE_API_URL env variable set
- copy dist folder to your static files service
- serve those files with a rule for SPAs (e.g. serving the index.html on 404)

## S3 / Cloudfront

```fish
# copy dist files into your s3 bucket
aws s3 sync ./dist s3://your-s3-bucket-name/
# invalidate cloudfront distribution to serve the new files
aws cloudfront create-invalidation --distribution-id YOUR_DISTRIB_ID --paths "/*"
```

### Github action for S3 / Cloudfront

```yml
name: Deploy staging ⚙️
on:
push:
branches:
- does-not-exist # replace by e.g: staging

jobs:
back-office:
runs-on: ubuntu-latest
env:
VITE_API_URL: https://api.staging.your-own-domain.fr/ # replace by your API url
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
# you will have to create AWS_ACCESS_KEY and AWS_SECRET_KEY secrets in your repository settings
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: eu-west-3
- name: Deploy
run: aws s3 sync ./dist s3://your-s3-bucket-name/ # replace by your s3 bucket name
- name: Invalidate dashboard cloudfront
run: aws cloudfront create-invalidation --distribution-id YOUR_DISTRIB_ID --paths "/*" # replace by your cloudfront distribution id
```
## Caddy
Example of Caddy config to serve a SPA
```
example.com {
root * /usr/share/caddy/frontend
file_server
try_files {path} {path}/ /index.html
}
```

### Github action for Caddy

This github action is taken from a project that uses [Galacrypt](https://github.com/galadrimteam/galacrypt) to encrypt/decrypt the

```yml
name: Deploy staging ⚙️
on:
push:
branches:
- does-not-exist # replace by e.g: staging

jobs:
frontend:
runs-on: ubuntu-latest
env:
VITE_API_URL: https://api.staging.your-own-domain.fr/ # replace by your API url
SERVER_IP: 1.2.3.4 # replace by your server IP
KEY_PATH: ./ssh_keys/staging/id_ed25519 # do not commit/push this file directly
SSH_USER: YOUR_SSH_USER # replace by your ssh user
SSH_PARAMS: -i ./ssh_keys/staging/id_ed25519 [email protected] # replace dummy user / ip

steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

- name: Dependencies installation
run: yarn

- name: Galacrypt decrypt # used to decrypt ssh key, you will have to create GALACRYPT_KEY in your repository secrets
run: yarn galacrypt use ${{ secrets.GALACRYPT_KEY }} && yarn galacrypt decrypt

- name: Generate build
run: yarn build

- name: Generate frontend zip
run: cd dist && zip -r ../frontend.zip .

- name: Setup SSH
run: |
mkdir -p ~/.ssh
ssh-keyscan $SERVER_IP 2>/dev/null > ~/.ssh/known_hosts
chmod 600 $KEY_PATH
- name: Copy files
run: scp -i $KEY_PATH ./frontend.zip $SSH_USER@$SERVER_IP:/home/$SSH_USER/frontend.zip

- name: Unzip
run: ssh $SSH_PARAMS "cd /home/$SSH_USER/ && rm -rf front-build && mkdir front-build && mv frontend.zip front-build/ && cd front-build && unzip frontend.zip && rm frontend.zip"

- name: Move website files
run: ssh $SSH_PARAMS "cd /home/$SSH_USER/ && (sudo mv /usr/share/caddy/frontend old_frontend || echo 'skipping mv old_frontend') && sudo mv front-build /usr/share/caddy/frontend && sudo rm -rf old_frontend"
```
## Nginx
I don't want to deal with nginx anymore, but if you want to, you can find inspiration [here](https://sdickinson.com/nginx-config-for-single-page-applications/)
2 changes: 1 addition & 1 deletion docs/content/docs/frontend/routing/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ export const adominRoutes = createBrowserRouter([
<CustomPage currentView="User">
<MyOverridePage />
</CustomPage>,
};
}
```
12 changes: 11 additions & 1 deletion docs/content/docs/frontend/setup/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ git clone https://github.com/galadrimteam/adomin-frontend.git
cd adomin-frontend && yarn
```

- verify that the `VITE_API_URL` variable in the .env points to your backend (by default it's `http://localhost:3333`)
- check that the `VITE_API_URL` is set to your backend URL

- start the `vite` server

```fish
yarn dev
```

## Configuration

The real configurations are on the backend side (to set which tables to show, permissions, etc, etc), for more infos [check this](/adomin/docs/backend/configuration/)

## Missing features

If some features that you would like to have in your backoffice are not implemented, fear not, you can just edit the code, it's yours 🤭

If afterwards you would like to make a contribution to the official Adomin code base, you can create a pull request on [this repo](https://github.com/galadrimteam/adomin-frontend)
Binary file added docs/static/images/models/enum/enum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/models/enum/table_enum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9473f72

Please sign in to comment.