fix: keep mobile board widgets unchanged
This commit is contained in:
1 parent
e2732dce2c
commit
b5ffefe707
43 files changed
+1669
-181
No files matched your search
@@ -80,6 +80,6 @@ The OpenAPI and MCP APIs include board management endpoints for common automatio
|
|||||||
- Change board visibility
|
- Change board visibility
|
||||||
- Update board visual and behavior settings
|
- Update board visual and behavior settings
|
||||||
- Set desktop and mobile home boards for the current user
|
- Set desktop and mobile home boards for the current user
|
||||||
- Configure global board defaults such as public home boards and status behavior
|
- Configure global board defaults such as public home boards, automatic mobile layout mode, and status behavior
|
||||||
|
|
||||||
Use the interactive API reference to inspect the exact request body for each endpoint under the `boards` and `settings` tags.
|
Use the interactive API reference to inspect the exact request body for each endpoint under the `boards` and `settings` tags.
|
||||||
@@ -9,9 +9,9 @@ tags:
|
|||||||
- Layout
|
- Layout
|
||||||
---
|
---
|
||||||
|
|
||||||
import iconColorImage from './img/icon-color.png'
|
import iconColorImage from "./img/icon-color.png";
|
||||||
import itemRadiusImage from './img/item-radius.png'
|
import itemRadiusImage from "./img/item-radius.png";
|
||||||
import layoutLargeImage from './img/layout-large.png'
|
import layoutLargeImage from "./img/layout-large.png";
|
||||||
|
|
||||||
Each dashboard is called a "board".
|
Each dashboard is called a "board".
|
||||||
You can create as many boards as you want.
|
You can create as many boards as you want.
|
||||||
@@ -22,24 +22,29 @@ Other boards can be viewed by direct links (e.g. my-homarr.com/board/smart-home)
|
|||||||
Names of boards must be unique because this will be used in the URL to load the desired board.
|
Names of boards must be unique because this will be used in the URL to load the desired board.
|
||||||
|
|
||||||
## Create a new board
|
## Create a new board
|
||||||
|
|
||||||
When creating a board, the availability of the board name will be checked for you.
|
When creating a board, the availability of the board name will be checked for you.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Name
|
### Name
|
||||||
|
|
||||||
The name must not include any special characters and must be at least one character long.
|
The name must not include any special characters and must be at least one character long.
|
||||||
Underscores and hyphen-minus are allowed.
|
Underscores and hyphen-minus are allowed.
|
||||||
|
|
||||||
### Column count
|
### Column count
|
||||||
|
|
||||||
Homarr has a complex drag and drop system that can be used from the browser.
|
Homarr has a complex drag and drop system that can be used from the browser.
|
||||||
The column count defines how many horizontal columns are available to drag and drop elements to.
|
The column count defines how many horizontal columns are available to drag and drop elements to.
|
||||||
|
|
||||||
### Public
|
### Public
|
||||||
|
|
||||||
This will enable public access for everyone - regardless of whether they are logged in or not.
|
This will enable public access for everyone - regardless of whether they are logged in or not.
|
||||||
This can be really useful if you want to have public boards in your company or for family and fiends.
|
This can be really useful if you want to have public boards in your company or for family and fiends.
|
||||||
Modifications for public boards must be allowed explicitly using user groups and their permissions.
|
Modifications for public boards must be allowed explicitly using user groups and their permissions.
|
||||||
|
|
||||||
## Board settings
|
## Board settings
|
||||||
|
|
||||||
You navigate to the board settings by clicking on these three dots:
|
You navigate to the board settings by clicking on these three dots:
|
||||||
|
|
||||||

|

|
||||||
@@ -49,7 +54,9 @@ Alternatively, you can also navigate from the board page itself using the cog ic
|
|||||||

|

|
||||||
|
|
||||||
### General
|
### General
|
||||||
|
|
||||||
#### Page title
|
#### Page title
|
||||||
|
|
||||||
This is the title that will be visible at the top left in the navigation bar:
|
This is the title that will be visible at the top left in the navigation bar:
|
||||||
|
|
||||||

|

|
||||||
@@ -57,6 +64,7 @@ This is the title that will be visible at the top left in the navigation bar:
|
|||||||
This field is optional and Homarr will fall back to "Homarr" if nothing is set.
|
This field is optional and Homarr will fall back to "Homarr" if nothing is set.
|
||||||
|
|
||||||
#### Meta title
|
#### Meta title
|
||||||
|
|
||||||
This is the secondary title of the page that is not directly visible in the page itself.
|
This is the secondary title of the page that is not directly visible in the page itself.
|
||||||
Browser will use it to set the title of tabs:
|
Browser will use it to set the title of tabs:
|
||||||
|
|
||||||
@@ -65,64 +73,85 @@ Browser will use it to set the title of tabs:
|
|||||||
Homarr will fall back to the board name and a suffix if nothing is set.
|
Homarr will fall back to the board name and a suffix if nothing is set.
|
||||||
|
|
||||||
#### Logo image URL
|
#### Logo image URL
|
||||||
|
|
||||||
This is the URL that is used for the image at the top left.
|
This is the URL that is used for the image at the top left.
|
||||||
Homarr will fall back to the Homarr logo if nothing is set.
|
Homarr will fall back to the Homarr logo if nothing is set.
|
||||||
|
|
||||||
#### Favicon image URL
|
#### Favicon image URL
|
||||||
|
|
||||||
This is the URL that is used for the favicon in the tab title.
|
This is the URL that is used for the favicon in the tab title.
|
||||||
Homarr will fall back to the Homarr logo if nothing is set.
|
Homarr will fall back to the Homarr logo if nothing is set.
|
||||||
|
|
||||||
### Layout
|
### Layout
|
||||||
|
|
||||||
In this section you can configure the number of columns in the desktop layout.
|
The available controls depend on the server-wide **Use automatic mobile layout** setting under `Management` > `Settings` > `Boards`.
|
||||||
|
|
||||||
Items and sections can be moved and resized on desktop while the board is in edit mode.
|
#### Automatic mobile layout
|
||||||
Changing the column count automatically adjusts item positions and sizes to fit the new grid.
|
|
||||||
|
When automatic mode is enabled, this section configures the desktop column count. Items and sections can be moved and resized on desktop while the board is in edit mode.
|
||||||
|
|
||||||
|
Phones and small tablets display the same widgets in a generated, read-only two-column grid. Widget content and controls are unchanged. Items follow desktop visual order and retain their desktop footprint, clamped to two columns wide and three rows high.
|
||||||
|
|
||||||
|
Categories and dynamic sections are flattened: their items participate directly in the generated grid instead of rendering nested layout containers. To rearrange, add, remove, or resize items, open the board on a larger screen.
|
||||||
|
|
||||||
<img src={layoutLargeImage} height={256} />
|
<img src={layoutLargeImage} height={256} />
|
||||||
|
|
||||||
#### Mobile layout
|
#### Saved responsive layouts
|
||||||
|
|
||||||
Mobile boards use an automatic, read-only layout with two columns. Items follow the visual order of the desktop layout and are limited to two columns wide and three rows high.
|
When automatic mode is disabled, boards use their saved responsive layouts and breakpoint selection. These layouts can still be edited on mobile.
|
||||||
|
|
||||||
Categories and dynamic sections are not displayed as containers on mobile. Their items are included directly in the automatic grid, even when a category is collapsed on desktop. To rearrange, add, remove, or resize board items, open the board on a larger screen.
|
Switching automatic mode on does not delete saved responsive layouts. They remain available if the server is switched back.
|
||||||
|
|
||||||
### Background
|
### Background
|
||||||
|
|
||||||
#### Background image URL
|
#### Background image URL
|
||||||
|
|
||||||
Homarr can display a background image behind apps and widgets.
|
Homarr can display a background image behind apps and widgets.
|
||||||
This URL can be used to define what image should be shown.
|
This URL can be used to define what image should be shown.
|
||||||
|
|
||||||
#### Background image attachment
|
#### Background image attachment
|
||||||
|
|
||||||
This defines whether the background should move when the user scrolls.
|
This defines whether the background should move when the user scrolls.
|
||||||
|
|
||||||
#### Background image size
|
#### Background image size
|
||||||
|
|
||||||
This defines whether the background should cover the entire page (and possibly be cropped) or never be cropped but may not cover the entire page.
|
This defines whether the background should cover the entire page (and possibly be cropped) or never be cropped but may not cover the entire page.
|
||||||
|
|
||||||
#### Background image repeat
|
#### Background image repeat
|
||||||
|
|
||||||
This defines whether the background should be repeated if it cannot cover the entire page.
|
This defines whether the background should be repeated if it cannot cover the entire page.
|
||||||
This option can be useful if you have patterns that can be repeated easily (e.g. patterns):
|
This option can be useful if you have patterns that can be repeated easily (e.g. patterns):
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### Appearance
|
### Appearance
|
||||||
|
|
||||||
#### Primary color
|
#### Primary color
|
||||||
|
|
||||||
Color that can be chosen freely to give accents to active elements.
|
Color that can be chosen freely to give accents to active elements.
|
||||||
|
|
||||||
#### Secondary color
|
#### Secondary color
|
||||||
|
|
||||||
Color that can be chosen freely to give accents.
|
Color that can be chosen freely to give accents.
|
||||||
|
|
||||||
#### Opacity
|
#### Opacity
|
||||||
|
|
||||||
Opacity of the colors.
|
Opacity of the colors.
|
||||||
|
|
||||||
#### Icon color
|
#### Icon color
|
||||||
|
|
||||||
Change the color of your bookmark / app icons.
|
Change the color of your bookmark / app icons.
|
||||||
|
|
||||||
<img src={iconColorImage} height={100} />
|
<img src={iconColorImage} height={100} />
|
||||||
|
|
||||||
#### Item radius
|
#### Item radius
|
||||||
|
|
||||||
Change the radius of your items / categories.
|
Change the radius of your items / categories.
|
||||||
|
|
||||||
<img src={itemRadiusImage} height={100} />
|
<img src={itemRadiusImage} height={100} />
|
||||||
|
|
||||||
|
|
||||||
### Custom CSS
|
### Custom CSS
|
||||||
|
|
||||||
This is the field where you can enter custom CSS.
|
This is the field where you can enter custom CSS.
|
||||||
The styling will only be applied on the respective board page.
|
The styling will only be applied on the respective board page.
|
||||||
|
|
||||||
@@ -131,14 +160,16 @@ The styling will only be applied on the respective board page.
|
|||||||
### Behaviour
|
### Behaviour
|
||||||
|
|
||||||
#### Disable app status
|
#### Disable app status
|
||||||
|
|
||||||
This will disable the status check for apps.
|
This will disable the status check for apps.
|
||||||
|
|
||||||
### Access control
|
### Access control
|
||||||
|
|
||||||
With the access control, you can permit a single user or a group to your board.
|
With the access control, you can permit a single user or a group to your board.
|
||||||
The users and groups can have one of these three levels of access:
|
The users and groups can have one of these three levels of access:
|
||||||
|
|
||||||
| **Permission Level** | View board | Edit mode | Settings | Danger zone (eg. delete) |
|
| **Permission Level** | View board | Edit mode | Settings | Danger zone (eg. delete) |
|
||||||
|----------------------|------------|-----------|----------|--------------------------|
|
| -------------------- | ---------- | --------- | -------- | ------------------------ |
|
||||||
| View board | X | | | |
|
| View board | X | | | |
|
||||||
| Modify board | X | X | X | |
|
| Modify board | X | X | X | |
|
||||||
| Full access | X | X | X | X |
|
| Full access | X | X | X | X |
|
||||||
@@ -157,18 +188,23 @@ After editing permissions, the save button below the table must be pressed.
|
|||||||
Otherwise, all changes will be discarded.
|
Otherwise, all changes will be discarded.
|
||||||
|
|
||||||
### Danger zone
|
### Danger zone
|
||||||
|
|
||||||
#### Rename
|
#### Rename
|
||||||
|
|
||||||
Renaming a board will break all existing links to it permanently with no redirect.
|
Renaming a board will break all existing links to it permanently with no redirect.
|
||||||
|
|
||||||
#### Board visibility
|
#### Board visibility
|
||||||
|
|
||||||
By default, boards will be private. This means only authenticated users that are authorized have access.
|
By default, boards will be private. This means only authenticated users that are authorized have access.
|
||||||
Making a board public will expose it to everyone - including unauthenticated users.
|
Making a board public will expose it to everyone - including unauthenticated users.
|
||||||
|
|
||||||
#### Delete
|
#### Delete
|
||||||
|
|
||||||
This will permanently delete the board.
|
This will permanently delete the board.
|
||||||
This action is irreversible and cannot be undone.
|
This action is irreversible and cannot be undone.
|
||||||
|
|
||||||
## Delete boards
|
## Delete boards
|
||||||
|
|
||||||
The deletion of boards is permanent and cannot be undone.
|
The deletion of boards is permanent and cannot be undone.
|
||||||
There are two ways to delete a board:
|
There are two ways to delete a board:
|
||||||
|
|
||||||
@@ -180,7 +216,7 @@ Both actions will execute the same deletion process.
|
|||||||
## Duplicate boards
|
## Duplicate boards
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
Duplicating a board will not copy the users and groups that have access to the board
|
Duplicating a board will not copy the users and groups that have access to the board
|
||||||
nor the integrations the user does not have access to.
|
nor the integrations the user does not have access to.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
@@ -190,47 +226,51 @@ You can duplicate a board by clicking on the three dots in the list of boards an
|
|||||||

|

|
||||||
|
|
||||||
## Setting boards as your home board
|
## Setting boards as your home board
|
||||||
|
|
||||||
The home board is the dashboard, that will be shown at the root path of Homarr or if no board name was passed in the URL.
|
The home board is the dashboard, that will be shown at the root path of Homarr or if no board name was passed in the URL.
|
||||||
All the following paths will lead to the home board:
|
All the following paths will lead to the home board:
|
||||||
- ``my-homarr.com``
|
|
||||||
- ``my-homarr.com/boards``
|
- `my-homarr.com`
|
||||||
|
- `my-homarr.com/boards`
|
||||||
|
|
||||||
Your home board will have a special small badge at the top right in the list of boards:
|
Your home board will have a special small badge at the top right in the list of boards:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### For yourself
|
### For yourself
|
||||||
|
|
||||||
To set the home board yourself, the easiest option is to set it directly in the list of boards:
|
To set the home board yourself, the easiest option is to set it directly in the list of boards:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Alternatively, you can also define it via your user profile:
|
Alternatively, you can also define it via your user profile:
|
||||||
|
|
||||||
1. Click on your user profile at the top right
|
1. Click on your user profile at the top right
|
||||||
2. Click on ``Your preferences``
|
2. Click on `Your preferences`
|
||||||
3. Change the home board in the ``home board`` dropdown and click on ``Save``.
|
3. Change the home board in the `home board` dropdown and click on `Save`.
|
||||||
|
|
||||||
### For other users
|
### For other users
|
||||||
|
|
||||||
1. Navigate to the users: ``Management`` > ``Users`` > ``Manage``
|
1. Navigate to the users: `Management` > `Users` > `Manage`
|
||||||
2. Click on the username of the user that you want to adjust
|
2. Click on the username of the user that you want to adjust
|
||||||
3. Select the desired home board via the dropdown and click on ``Save`` \
|
3. Select the desired home board via the dropdown and click on `Save` \
|
||||||

|

|
||||||
|
|
||||||
### For user groups
|
### For user groups
|
||||||
|
|
||||||
1. Navigate to the user groups: ``Management`` > ``Users`` > ``Groups`` > ``Manage``
|
1. Navigate to the user groups: `Management` > `Users` > `Groups` > `Manage`
|
||||||
2. Go to tab ``Settings``
|
2. Go to tab `Settings`
|
||||||
3. Select the desired home board via the dropdown and click on ``Save`` \
|
3. Select the desired home board via the dropdown and click on `Save` \
|
||||||

|

|
||||||
|
|
||||||
### For whole server
|
### For whole server
|
||||||
|
|
||||||
You can also set a global home board that will be used for all users that have not set a home board themselves.
|
You can also set a global home board that will be used for all users that have not set a home board themselves.
|
||||||
It will also be used for anonymous users.
|
It will also be used for anonymous users.
|
||||||
|
|
||||||
1. Navigate to the settings: ``Management`` > ``Settings`` > ``Boards``
|
1. Navigate to the settings: `Management` > `Settings` > `Boards`
|
||||||
2. Select the desired home board via the dropdown and click on ``Save`` \
|
2. Select the desired home board via the dropdown and click on `Save` \
|
||||||

|

|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
For the global home board you can only select boards that are public.
|
For the global home board you can only select boards that are public.
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ tags:
|
|||||||
---
|
---
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
|
|
||||||
The settings page has a few options that will be applied to the entire Homarr application.
|
The settings page has a few options that will be applied to the entire Homarr application.
|
||||||
They may require a full page reload for changes to apply.
|
They may require a full page reload for changes to apply.
|
||||||
|
|
||||||
## Analytics
|
## Analytics
|
||||||
|
|
||||||
By default, Homarr is collecting anonymous analytics to identify issues and prioritize bugfixes and improvements.
|
By default, Homarr is collecting anonymous analytics to identify issues and prioritize bugfixes and improvements.
|
||||||
The data is never shared with any third-parties and is fully GDPR & CCPA compliant.
|
The data is never shared with any third-parties and is fully GDPR & CCPA compliant.
|
||||||
The software being used is [Umami Analytics](https://umami.is/) which is fully open source.
|
The software being used is [Umami Analytics](https://umami.is/) which is fully open source.
|
||||||
@@ -21,25 +23,29 @@ The main server software can be found [here](https://github.com/umami-software/u
|
|||||||
A full list of the collected data by default can be found here: https://umami.is/docs/metric-definitions.
|
A full list of the collected data by default can be found here: https://umami.is/docs/metric-definitions.
|
||||||
|
|
||||||
We understand that you might not want Homarr to communicate with our services.
|
We understand that you might not want Homarr to communicate with our services.
|
||||||
By unchecking the ``Send anonymous analytics`` checkbox and reloading the full page, all communication by Umami will be disabled and no data will be collected.
|
By unchecking the `Send anonymous analytics` checkbox and reloading the full page, all communication by Umami will be disabled and no data will be collected.
|
||||||
If you are paranoid, you can permanently block ``umami.homarr.dev`` from your DNS / firewall.
|
If you are paranoid, you can permanently block `umami.homarr.dev` from your DNS / firewall.
|
||||||
|
|
||||||
Additionally, you opt in to more data collection to help us provide more useful data.
|
Additionally, you opt in to more data collection to help us provide more useful data.
|
||||||
|
|
||||||
### Integration data
|
### Integration data
|
||||||
|
|
||||||
Enabling this optional data will send the types of integrations (e.g. SABnzbd, Sonarr, ...) and how many you have configured of them.
|
Enabling this optional data will send the types of integrations (e.g. SABnzbd, Sonarr, ...) and how many you have configured of them.
|
||||||
This will not include any URLs, names, secrets, errors and others. This is disabled by default.
|
This will not include any URLs, names, secrets, errors and others. This is disabled by default.
|
||||||
|
|
||||||
### Widget data
|
### Widget data
|
||||||
|
|
||||||
Enabling this optional data will send the types of widgets (e.g. downloads, media streams, iframe, ...) and how many you have configured of them.
|
Enabling this optional data will send the types of widgets (e.g. downloads, media streams, iframe, ...) and how many you have configured of them.
|
||||||
This will not include any URLs, names, secrets, errors and others. This is disabled by default.
|
This will not include any URLs, names, secrets, errors and others. This is disabled by default.
|
||||||
|
|
||||||
### Users data
|
### Users data
|
||||||
|
|
||||||
Enabling this optional data will send the count of users and whether you activated SSO.
|
Enabling this optional data will send the count of users and whether you activated SSO.
|
||||||
This will not include any usernames, passwords, emails, URLs, authentication flows or client IDs.
|
This will not include any usernames, passwords, emails, URLs, authentication flows or client IDs.
|
||||||
This is disabled by default.
|
This is disabled by default.
|
||||||
|
|
||||||
## Search Engine Optimization (SEO)
|
## Search Engine Optimization (SEO)
|
||||||
|
|
||||||
Big companies [like Google, Microsoft, Baidu and Yandex](https://de.wikipedia.org/wiki/Web-Index) will use [web crawlers](https://de.wikipedia.org/wiki/Webcrawler) to index the Internet for new websites & pages.
|
Big companies [like Google, Microsoft, Baidu and Yandex](https://de.wikipedia.org/wiki/Web-Index) will use [web crawlers](https://de.wikipedia.org/wiki/Webcrawler) to index the Internet for new websites & pages.
|
||||||
This is desirable in many cases (for example when selling products in an online shop) but can lead to unwanted traffic and attention to your personal dashboard.
|
This is desirable in many cases (for example when selling products in an online shop) but can lead to unwanted traffic and attention to your personal dashboard.
|
||||||
Homarr is requesting the crawlers to not index Homarr instances by default for this reason.
|
Homarr is requesting the crawlers to not index Homarr instances by default for this reason.
|
||||||
@@ -47,22 +53,26 @@ If you use Homarr as a public website and want it to be searchable on these sear
|
|||||||
Please note that Homarr doesn't have control over what the crawlers do; it is a mere request to them to not perform these actions but will not guarantee that your website doesn't land on some index.
|
Please note that Homarr doesn't have control over what the crawlers do; it is a mere request to them to not perform these actions but will not guarantee that your website doesn't land on some index.
|
||||||
|
|
||||||
### No index
|
### No index
|
||||||
|
|
||||||
This will ask crawlers to not index your Homarr instance on any indexes.
|
This will ask crawlers to not index your Homarr instance on any indexes.
|
||||||
It is up to the crawler to properly respect this request.
|
It is up to the crawler to properly respect this request.
|
||||||
By default, this setting is enabled. Disabling it will allow indexing.
|
By default, this setting is enabled. Disabling it will allow indexing.
|
||||||
|
|
||||||
### No follow
|
### No follow
|
||||||
|
|
||||||
If indexing is allowed, crawlers will also attempt to follow any links on your page to further "discover" new parts of the Internet and on your website.
|
If indexing is allowed, crawlers will also attempt to follow any links on your page to further "discover" new parts of the Internet and on your website.
|
||||||
By default, this setting is enabled and will ask crawlers to not follow any links.
|
By default, this setting is enabled and will ask crawlers to not follow any links.
|
||||||
Crawler of different companies may behave differently when indexing is prohibited and following is allowed.
|
Crawler of different companies may behave differently when indexing is prohibited and following is allowed.
|
||||||
|
|
||||||
### No translate
|
### No translate
|
||||||
|
|
||||||
Google and Chrome on Android will prompt users to translate pages that are not in their device language.
|
Google and Chrome on Android will prompt users to translate pages that are not in their device language.
|
||||||
This can lead to some shifting and can be undesired in some cases. By enabling this,
|
This can lead to some shifting and can be undesired in some cases. By enabling this,
|
||||||
you ask crawlers to never translate and never prompt users for translation.
|
you ask crawlers to never translate and never prompt users for translation.
|
||||||
It should be noted that some browsers will ignore this and translate regardless.
|
It should be noted that some browsers will ignore this and translate regardless.
|
||||||
|
|
||||||
### No site links search box
|
### No site links search box
|
||||||
|
|
||||||
This setting is exclusive to Google.
|
This setting is exclusive to Google.
|
||||||
[Google will create a box below your domain](https://developers.google.com/search/docs/appearance/structured-data/sitelinks-searchbox) that lists the paths that were discovered by the "folowing".
|
[Google will create a box below your domain](https://developers.google.com/search/docs/appearance/structured-data/sitelinks-searchbox) that lists the paths that were discovered by the "folowing".
|
||||||
The user can search them directly in Google.
|
The user can search them directly in Google.
|
||||||
@@ -72,7 +82,8 @@ This setting is disabled by default.
|
|||||||
## Boards
|
## Boards
|
||||||
|
|
||||||
### Global home board
|
### Global home board
|
||||||
You can set a global home board that will be used for all users that have not set a home board themselves.
|
|
||||||
|
You can set a global home board that will be used for all users that have not set a home board themselves.
|
||||||
It will also be used for anonymous users.
|
It will also be used for anonymous users.
|
||||||
Note that the board must be public to be used as a global home board.
|
Note that the board must be public to be used as a global home board.
|
||||||
|
|
||||||
@@ -82,6 +93,15 @@ You can set a global mobile board. It will be shown instead of the global home b
|
|||||||
It will similar to the global home board be as fallback for normal users and for any anonymous users.
|
It will similar to the global home board be as fallback for normal users and for any anonymous users.
|
||||||
It also has to be public.
|
It also has to be public.
|
||||||
|
|
||||||
|
### Automatic mobile layout
|
||||||
|
|
||||||
|
**Use automatic mobile layout** controls how every board is rendered on phones and small tablets:
|
||||||
|
|
||||||
|
- Enabled: Homarr squeezes the normal widgets into a generated, read-only two-column grid. Widget content is not replaced or simplified.
|
||||||
|
- Disabled: Homarr uses each board's saved responsive layouts and permits layout editing on mobile.
|
||||||
|
|
||||||
|
The setting is enabled by default for new instances. During upgrade, Homarr leaves it disabled when existing custom responsive layouts are detected. Saved responsive layouts are preserved while automatic mode is enabled.
|
||||||
|
|
||||||
### App status
|
### App status
|
||||||
|
|
||||||
#### Enable status by default
|
#### Enable status by default
|
||||||
@@ -97,9 +117,11 @@ You can decide if the app status should be disabled for all boards.
|
|||||||
## Appearance
|
## Appearance
|
||||||
|
|
||||||
### Default color scheme
|
### Default color scheme
|
||||||
|
|
||||||
You can set the default color scheme for all users that have not set a color scheme themselves.
|
You can set the default color scheme for all users that have not set a color scheme themselves.
|
||||||
|
|
||||||
## Culture
|
## Culture
|
||||||
|
|
||||||
### Default language
|
### Default language
|
||||||
You can set the default language for all users that have not set a language themselves.
|
|
||||||
|
You can set the default language for all users that have not set a language themselves.
|
||||||
@@ -1,19 +1,42 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Button, Fieldset, Group, Input, Slider, Stack, Text } from "@mantine/core";
|
import { Button, Fieldset, Grid, Group, Input, NumberInput, Slider, Stack, Text, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { getDesktopLayout } from "@homarr/boards/context";
|
import { getDesktopLayout } from "@homarr/boards/context";
|
||||||
|
import { createId } from "@homarr/common";
|
||||||
import { useZodForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import { boardSaveLayoutSchema } from "@homarr/validation/board";
|
import { boardSaveLayoutSchema, boardSaveLayoutsSchema } from "@homarr/validation/board";
|
||||||
|
|
||||||
import type { Board } from "../../_types";
|
import type { Board } from "../../_types";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
board: Board;
|
board: Board;
|
||||||
|
enableAutomaticMobileLayout: boolean;
|
||||||
}
|
}
|
||||||
export const LayoutSettingsContent = ({ board }: Props) => {
|
|
||||||
|
const getNextAvailableBreakpoint = (layouts: Array<{ breakpoint: number }>) => {
|
||||||
|
const breakpoints = new Set(layouts.map((layout) => layout.breakpoint));
|
||||||
|
const commonBreakpoints = [0, 480, 768, 1024, 1200, 1440, 1920];
|
||||||
|
const commonBreakpoint = commonBreakpoints.find((breakpoint) => !breakpoints.has(breakpoint));
|
||||||
|
if (commonBreakpoint !== undefined) return commonBreakpoint;
|
||||||
|
|
||||||
|
for (let breakpoint = 0; breakpoint <= 32767; breakpoint++) {
|
||||||
|
if (!breakpoints.has(breakpoint)) return breakpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("No responsive layout breakpoints are available");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LayoutSettingsContent = ({ board, enableAutomaticMobileLayout }: Props) =>
|
||||||
|
enableAutomaticMobileLayout ? (
|
||||||
|
<AutomaticLayoutSettingsContent board={board} />
|
||||||
|
) : (
|
||||||
|
<ResponsiveLayoutSettingsContent board={board} />
|
||||||
|
);
|
||||||
|
|
||||||
|
const AutomaticLayoutSettingsContent = ({ board }: Pick<Props, "board">) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
const desktopLayout = getDesktopLayout(board);
|
const desktopLayout = getDesktopLayout(board);
|
||||||
@@ -45,13 +68,20 @@ export const LayoutSettingsContent = ({ board }: Props) => {
|
|||||||
{t("board.setting.section.layout.desktop.description")}
|
{t("board.setting.section.layout.desktop.description")}
|
||||||
</Text>
|
</Text>
|
||||||
<Input.Wrapper label={t("layout.field.columnCount.label")}>
|
<Input.Wrapper label={t("layout.field.columnCount.label")}>
|
||||||
<Slider mt="xs" min={1} max={24} step={1} {...form.getInputProps("columnCount")} />
|
<Slider
|
||||||
|
mt="xs"
|
||||||
|
min={1}
|
||||||
|
max={24}
|
||||||
|
step={1}
|
||||||
|
thumbLabel={t("layout.field.columnCount.label")}
|
||||||
|
{...form.getInputProps("columnCount")}
|
||||||
|
/>
|
||||||
</Input.Wrapper>
|
</Input.Wrapper>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
|
|
||||||
<Text c="dimmed" size="sm">
|
<Text c="dimmed" size="sm">
|
||||||
{t("board.setting.section.layout.mobile.description")}
|
{t("board.setting.section.layout.mobile.automaticDescription")}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Group justify="end">
|
<Group justify="end">
|
||||||
@@ -63,3 +93,124 @@ export const LayoutSettingsContent = ({ board }: Props) => {
|
|||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ResponsiveLayoutSettingsContent = ({ board }: Pick<Props, "board">) => {
|
||||||
|
const t = useI18n();
|
||||||
|
const utils = clientApi.useUtils();
|
||||||
|
const form = useZodForm(boardSaveLayoutsSchema.omit({ id: true }).required(), {
|
||||||
|
initialValues: {
|
||||||
|
layouts: board.layouts,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { mutate: saveLayouts, isPending } = clientApi.board.saveLayouts.useMutation({
|
||||||
|
onSuccess(layouts) {
|
||||||
|
const values = { layouts };
|
||||||
|
form.setValues(values);
|
||||||
|
form.resetDirty(values);
|
||||||
|
},
|
||||||
|
onSettled() {
|
||||||
|
void utils.board.getBoardByName.invalidate({ name: board.name });
|
||||||
|
void utils.board.getHomeBoard.invalidate();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
onSubmit={form.onSubmit((values) => {
|
||||||
|
saveLayouts({
|
||||||
|
id: board.id,
|
||||||
|
...values,
|
||||||
|
});
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Stack>
|
||||||
|
<Text c="dimmed" size="sm">
|
||||||
|
{t("board.setting.section.layout.responsive.description")}
|
||||||
|
</Text>
|
||||||
|
<Stack gap="sm">
|
||||||
|
<Group justify="space-between" align="center">
|
||||||
|
<Text fw={500}>{t("board.setting.section.layout.responsive.title")}</Text>
|
||||||
|
<Button
|
||||||
|
variant="subtle"
|
||||||
|
onClick={() => {
|
||||||
|
form.setValues({
|
||||||
|
layouts: [
|
||||||
|
...form.values.layouts,
|
||||||
|
{
|
||||||
|
id: createId(),
|
||||||
|
name: t("board.setting.section.layout.responsive.defaultName"),
|
||||||
|
columnCount: 10,
|
||||||
|
breakpoint: getNextAvailableBreakpoint(form.values.layouts),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("board.setting.section.layout.responsive.action.add")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
{form.values.layouts.map((layout, index) => (
|
||||||
|
<Fieldset key={layout.id} legend={layout.name} bg="transparent">
|
||||||
|
<Grid>
|
||||||
|
<Grid.Col span={{ sm: 12, md: 6 }}>
|
||||||
|
<TextInput {...form.getInputProps(`layouts.${index}.name`)} label={t("layout.field.name.label")} />
|
||||||
|
</Grid.Col>
|
||||||
|
|
||||||
|
<Grid.Col span={{ sm: 12, md: 6 }}>
|
||||||
|
<Input.Wrapper label={t("layout.field.columnCount.label")}>
|
||||||
|
<Slider
|
||||||
|
mt="xs"
|
||||||
|
min={1}
|
||||||
|
max={24}
|
||||||
|
step={1}
|
||||||
|
thumbLabel={t("layout.field.columnCount.label")}
|
||||||
|
{...form.getInputProps(`layouts.${index}.columnCount`)}
|
||||||
|
/>
|
||||||
|
</Input.Wrapper>
|
||||||
|
</Grid.Col>
|
||||||
|
|
||||||
|
<Grid.Col span={{ sm: 12, md: 6 }}>
|
||||||
|
<NumberInput
|
||||||
|
{...form.getInputProps(`layouts.${index}.breakpoint`)}
|
||||||
|
label={t("layout.field.breakpoint.label")}
|
||||||
|
description={t("layout.field.breakpoint.description")}
|
||||||
|
min={0}
|
||||||
|
max={32767}
|
||||||
|
allowDecimal={false}
|
||||||
|
allowNegative={false}
|
||||||
|
/>
|
||||||
|
</Grid.Col>
|
||||||
|
</Grid>
|
||||||
|
{form.values.layouts.length >= 2 && (
|
||||||
|
<Group justify="end">
|
||||||
|
<Button
|
||||||
|
variant="subtle"
|
||||||
|
onClick={() => {
|
||||||
|
form.setValues((previous) => {
|
||||||
|
const previousLayouts = previous.layouts ?? [];
|
||||||
|
return previousLayouts.length >= 2
|
||||||
|
? {
|
||||||
|
layouts: previousLayouts.filter((filteredLayout) => filteredLayout.id !== layout.id),
|
||||||
|
}
|
||||||
|
: previous;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("common.action.remove")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</Fieldset>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Group justify="end">
|
||||||
|
<Button type="submit" loading={isPending}>
|
||||||
|
{t("common.action.saveChanges")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -90,7 +90,10 @@ export default async function BoardSettingsPage(props: Props) {
|
|||||||
<GeneralSettingsContent board={board} />
|
<GeneralSettingsContent board={board} />
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
<AccordionItemFor value="layout" icon={IconLayout}>
|
<AccordionItemFor value="layout" icon={IconLayout}>
|
||||||
<LayoutSettingsContent board={board} />
|
<LayoutSettingsContent
|
||||||
|
board={board}
|
||||||
|
enableAutomaticMobileLayout={boardSettings.enableAutomaticMobileLayout}
|
||||||
|
/>
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
<AccordionItemFor value="background" icon={IconPhoto}>
|
<AccordionItemFor value="background" icon={IconPhoto}>
|
||||||
<BackgroundSettingsContent board={board} />
|
<BackgroundSettingsContent board={board} />
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export default async function Layout(props: {
|
|||||||
board: {
|
board: {
|
||||||
homeBoardId: serverSettings.board.homeBoardId,
|
homeBoardId: serverSettings.board.homeBoardId,
|
||||||
mobileHomeBoardId: serverSettings.board.mobileHomeBoardId,
|
mobileHomeBoardId: serverSettings.board.mobileHomeBoardId,
|
||||||
|
enableAutomaticMobileLayout: serverSettings.board.enableAutomaticMobileLayout,
|
||||||
enableStatusByDefault: serverSettings.board.enableStatusByDefault,
|
enableStatusByDefault: serverSettings.board.enableStatusByDefault,
|
||||||
forceDisableStatus: serverSettings.board.forceDisableStatus,
|
forceDisableStatus: serverSettings.board.forceDisableStatus,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ export const BoardSettingsForm = ({ defaultValues }: { defaultValues: ServerSett
|
|||||||
{...form.getInputProps("mobileHomeBoardId")}
|
{...form.getInputProps("mobileHomeBoardId")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Text fw={500}>{tBoard("mobileLayout.title")}</Text>
|
||||||
|
<Switch
|
||||||
|
{...form.getInputProps("enableAutomaticMobileLayout", { type: "checkbox" })}
|
||||||
|
label={tBoard("mobileLayout.enable.label")}
|
||||||
|
description={tBoard("mobileLayout.enable.description")}
|
||||||
|
/>
|
||||||
|
|
||||||
<Text fw={500}>{tBoard("status.title")}</Text>
|
<Text fw={500}>{tBoard("status.title")}</Text>
|
||||||
<Switch
|
<Switch
|
||||||
{...form.getInputProps("enableStatusByDefault", { type: "checkbox" })}
|
{...form.getInputProps("enableStatusByDefault", { type: "checkbox" })}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Button, Group, Stack } from "@mantine/core";
|
import { Button, Group, Stack } from "@mantine/core";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm } from "@homarr/form";
|
import { useForm } from "@homarr/form";
|
||||||
@@ -17,6 +18,7 @@ export const CommonSettingsForm = <TKey extends keyof ServerSettings>({
|
|||||||
defaultValues: ServerSettings[TKey];
|
defaultValues: ServerSettings[TKey];
|
||||||
children: (form: ReturnType<typeof useForm<ServerSettings[TKey]>>) => React.ReactNode;
|
children: (form: ReturnType<typeof useForm<ServerSettings[TKey]>>) => React.ReactNode;
|
||||||
}) => {
|
}) => {
|
||||||
|
const router = useRouter();
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const tSettings = useScopedI18n("management.page.settings");
|
const tSettings = useScopedI18n("management.page.settings");
|
||||||
const { mutateAsync, isPending } = clientApi.serverSettings.saveSettings.useMutation({
|
const { mutateAsync, isPending } = clientApi.serverSettings.saveSettings.useMutation({
|
||||||
@@ -24,6 +26,7 @@ export const CommonSettingsForm = <TKey extends keyof ServerSettings>({
|
|||||||
showSuccessNotification({
|
showSuccessNotification({
|
||||||
message: tSettings("notification.success.message"),
|
message: tSettings("notification.success.message"),
|
||||||
});
|
});
|
||||||
|
router.refresh();
|
||||||
},
|
},
|
||||||
onError() {
|
onError() {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
|
|||||||
@@ -60,9 +60,15 @@ const createItemLayouts = (board: Board, currentSection: EmptySection, kind: Wid
|
|||||||
return layouts.map((layoutId) => {
|
return layouts.map((layoutId) => {
|
||||||
const boardLayout = board.layouts.find((layout) => layout.id === layoutId);
|
const boardLayout = board.layouts.find((layout) => layout.id === layoutId);
|
||||||
const elements = getSectionElements(board, { sectionId: currentSection.id, layoutId });
|
const elements = getSectionElements(board, { sectionId: currentSection.id, layoutId });
|
||||||
|
const layoutItemSize = boardLayout
|
||||||
|
? {
|
||||||
|
...itemSize,
|
||||||
|
width: Math.min(itemSize.width, boardLayout.columnCount),
|
||||||
|
}
|
||||||
|
: itemSize;
|
||||||
|
|
||||||
const emptyPosition = boardLayout
|
const emptyPosition = boardLayout
|
||||||
? getFirstEmptyPosition(elements, boardLayout.columnCount, 9999, itemSize)
|
? getFirstEmptyPosition(elements, boardLayout.columnCount, 9999, layoutItemSize)
|
||||||
: { xOffset: 0, yOffset: 0 };
|
: { xOffset: 0, yOffset: 0 };
|
||||||
|
|
||||||
if (!emptyPosition) {
|
if (!emptyPosition) {
|
||||||
@@ -70,8 +76,8 @@ const createItemLayouts = (board: Board, currentSection: EmptySection, kind: Wid
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
width: itemSize.width,
|
width: layoutItemSize.width,
|
||||||
height: itemSize.height,
|
height: layoutItemSize.height,
|
||||||
...emptyPosition,
|
...emptyPosition,
|
||||||
sectionId: currentSection.id,
|
sectionId: currentSection.id,
|
||||||
layoutId,
|
layoutId,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const getFirstEmptyPosition = (
|
|||||||
size: { width: number; height: number } = { width: 1, height: 1 },
|
size: { width: number; height: number } = { width: 1, height: 1 },
|
||||||
) => {
|
) => {
|
||||||
for (let yOffset = 0; yOffset < rowCount + 1 - size.height; yOffset++) {
|
for (let yOffset = 0; yOffset < rowCount + 1 - size.height; yOffset++) {
|
||||||
for (let xOffset = 0; xOffset < columnCount; xOffset++) {
|
for (let xOffset = 0; xOffset < columnCount + 1 - size.width; xOffset++) {
|
||||||
const isOccupied = elements.some(
|
const isOccupied = elements.some(
|
||||||
(element) =>
|
(element) =>
|
||||||
element.yOffset < yOffset + size.height &&
|
element.yOffset < yOffset + size.height &&
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { getCurrentLayout } from "@homarr/boards/context";
|
|
||||||
|
|
||||||
import type { Board } from "~/app/[locale]/boards/_types";
|
import type { Board } from "~/app/[locale]/boards/_types";
|
||||||
|
|
||||||
export interface MoveAndResizeItemInput {
|
export interface MoveAndResizeItemInput {
|
||||||
itemId: string;
|
itemId: string;
|
||||||
|
layoutId: string;
|
||||||
xOffset: number;
|
xOffset: number;
|
||||||
yOffset: number;
|
yOffset: number;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -11,10 +10,8 @@ export interface MoveAndResizeItemInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const moveAndResizeItemCallback =
|
export const moveAndResizeItemCallback =
|
||||||
({ itemId, ...layoutInput }: MoveAndResizeItemInput) =>
|
({ itemId, layoutId, ...layoutInput }: MoveAndResizeItemInput) =>
|
||||||
(previous: Board): Board => {
|
(previous: Board): Board => {
|
||||||
const currentLayout = getCurrentLayout(previous);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...previous,
|
...previous,
|
||||||
items: previous.items.map((item) =>
|
items: previous.items.map((item) =>
|
||||||
@@ -23,7 +20,7 @@ export const moveAndResizeItemCallback =
|
|||||||
: {
|
: {
|
||||||
...item,
|
...item,
|
||||||
layouts: item.layouts.map((layout) =>
|
layouts: item.layouts.map((layout) =>
|
||||||
layout.layoutId !== currentLayout
|
layout.layoutId !== layoutId
|
||||||
? layout
|
? layout
|
||||||
: {
|
: {
|
||||||
...layout,
|
...layout,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { getCurrentLayout } from "@homarr/boards/context";
|
|
||||||
|
|
||||||
import type { Board } from "~/app/[locale]/boards/_types";
|
import type { Board } from "~/app/[locale]/boards/_types";
|
||||||
|
|
||||||
export interface MoveItemToSectionInput {
|
export interface MoveItemToSectionInput {
|
||||||
itemId: string;
|
itemId: string;
|
||||||
|
layoutId: string;
|
||||||
sectionId: string;
|
sectionId: string;
|
||||||
xOffset: number;
|
xOffset: number;
|
||||||
yOffset: number;
|
yOffset: number;
|
||||||
@@ -12,10 +11,8 @@ export interface MoveItemToSectionInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const moveItemToSectionCallback =
|
export const moveItemToSectionCallback =
|
||||||
({ itemId, ...layoutInput }: MoveItemToSectionInput) =>
|
({ itemId, layoutId, ...layoutInput }: MoveItemToSectionInput) =>
|
||||||
(board: Board): Board => {
|
(board: Board): Board => {
|
||||||
const currentLayout = getCurrentLayout(board);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...board,
|
...board,
|
||||||
items: board.items.map((item) =>
|
items: board.items.map((item) =>
|
||||||
@@ -24,7 +21,7 @@ export const moveItemToSectionCallback =
|
|||||||
: {
|
: {
|
||||||
...item,
|
...item,
|
||||||
layouts: item.layouts.map((layout) =>
|
layouts: item.layouts.map((layout) =>
|
||||||
layout.layoutId !== currentLayout
|
layout.layoutId !== layoutId
|
||||||
? layout
|
? layout
|
||||||
: {
|
: {
|
||||||
...layout,
|
...layout,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, test, vi } from "vitest";
|
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
import * as boardContext from "@homarr/boards/context";
|
import * as boardContext from "@homarr/boards/context";
|
||||||
|
|
||||||
@@ -10,6 +10,10 @@ import { ItemMockBuilder } from "./mocks/item-mock";
|
|||||||
import { LayoutMockBuilder } from "./mocks/layout-mock";
|
import { LayoutMockBuilder } from "./mocks/layout-mock";
|
||||||
|
|
||||||
describe("item actions create-item", () => {
|
describe("item actions create-item", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
test("should add it to first section", () => {
|
test("should add it to first section", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const itemKind = "clock";
|
const itemKind = "clock";
|
||||||
@@ -108,4 +112,24 @@ describe("item actions create-item", () => {
|
|||||||
{ height: 1, width: 1 },
|
{ height: 1, width: 1 },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("clamps wide widgets to each retained layout", () => {
|
||||||
|
const desktopLayout = new LayoutMockBuilder({ id: "desktop", columnCount: 12 }).build();
|
||||||
|
const mobileLayout = new LayoutMockBuilder({ id: "mobile", columnCount: 1 }).build();
|
||||||
|
const board = new BoardMockBuilder()
|
||||||
|
.addLayout(desktopLayout)
|
||||||
|
.addLayout(mobileLayout)
|
||||||
|
.addEmptySection({ id: "root", yOffset: 0 })
|
||||||
|
.build();
|
||||||
|
|
||||||
|
const result = createItemCallback({ kind: "mediaMissing" })(board);
|
||||||
|
const item = result.items.at(0);
|
||||||
|
|
||||||
|
expect(item?.layouts).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({ layoutId: desktopLayout.id, width: 4 }),
|
||||||
|
expect.objectContaining({ layoutId: mobileLayout.id, width: 1 }),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -106,6 +106,10 @@ describe("get first empty position", () => {
|
|||||||
|
|
||||||
expect(result).toEqual(expectedX !== undefined ? { xOffset: expectedX, yOffset: expectedY } : undefined);
|
expect(result).toEqual(expectedX !== undefined ? { xOffset: expectedX, yOffset: expectedY } : undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("does not place an item wider than the layout", () => {
|
||||||
|
expect(getFirstEmptyPosition([], 1, undefined, { width: 2, height: 1 })).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const createElementsFromLayout = (layout: string[][]) => {
|
const createElementsFromLayout = (layout: string[][]) => {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { describe, expect, test, vi } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
import * as boardContext from "@homarr/boards/context";
|
|
||||||
|
|
||||||
import { moveAndResizeItemCallback } from "../move-and-resize-item";
|
import { moveAndResizeItemCallback } from "../move-and-resize-item";
|
||||||
import { BoardMockBuilder } from "./mocks/board-mock";
|
import { BoardMockBuilder } from "./mocks/board-mock";
|
||||||
@@ -11,8 +9,6 @@ describe("moveItemToSectionCallback should move item in section", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const itemToMove = "2";
|
const itemToMove = "2";
|
||||||
const layoutId = "1";
|
const layoutId = "1";
|
||||||
const spy = vi.spyOn(boardContext, "getCurrentLayout");
|
|
||||||
spy.mockReturnValue(layoutId);
|
|
||||||
const newPosition = {
|
const newPosition = {
|
||||||
xOffset: 20,
|
xOffset: 20,
|
||||||
yOffset: 30,
|
yOffset: 30,
|
||||||
@@ -25,7 +21,7 @@ describe("moveItemToSectionCallback should move item in section", () => {
|
|||||||
const board = new BoardMockBuilder().addItem(itemA).addItem(itemB).addItem(itemC).build();
|
const board = new BoardMockBuilder().addItem(itemA).addItem(itemB).addItem(itemC).build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const updatedBoard = moveAndResizeItemCallback({ itemId: itemToMove, ...newPosition })(board);
|
const updatedBoard = moveAndResizeItemCallback({ itemId: itemToMove, layoutId, ...newPosition })(board);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(updatedBoard.items).toHaveLength(3);
|
expect(updatedBoard.items).toHaveLength(3);
|
||||||
@@ -43,8 +39,6 @@ describe("moveItemToSectionCallback should move item in section", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const itemToMove = "2";
|
const itemToMove = "2";
|
||||||
const layoutId = "1";
|
const layoutId = "1";
|
||||||
const spy = vi.spyOn(boardContext, "getCurrentLayout");
|
|
||||||
spy.mockReturnValue(layoutId);
|
|
||||||
const newPosition = {
|
const newPosition = {
|
||||||
xOffset: 20,
|
xOffset: 20,
|
||||||
yOffset: 30,
|
yOffset: 30,
|
||||||
@@ -56,7 +50,7 @@ describe("moveItemToSectionCallback should move item in section", () => {
|
|||||||
const board = new BoardMockBuilder().addItem(itemA).addItem(itemC).build();
|
const board = new BoardMockBuilder().addItem(itemA).addItem(itemC).build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const updatedBoard = moveAndResizeItemCallback({ itemId: itemToMove, ...newPosition })(board);
|
const updatedBoard = moveAndResizeItemCallback({ itemId: itemToMove, layoutId, ...newPosition })(board);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(updatedBoard.items).toHaveLength(2);
|
expect(updatedBoard.items).toHaveLength(2);
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { describe, expect, test, vi } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
import * as boardContext from "@homarr/boards/context";
|
|
||||||
|
|
||||||
import { moveItemToSectionCallback } from "../move-item-to-section";
|
import { moveItemToSectionCallback } from "../move-item-to-section";
|
||||||
import { BoardMockBuilder } from "./mocks/board-mock";
|
import { BoardMockBuilder } from "./mocks/board-mock";
|
||||||
@@ -11,8 +9,6 @@ describe("moveItemToSectionCallback should move item to section", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const itemToMove = "2";
|
const itemToMove = "2";
|
||||||
const layoutId = "1";
|
const layoutId = "1";
|
||||||
const spy = vi.spyOn(boardContext, "getCurrentLayout");
|
|
||||||
spy.mockReturnValue(layoutId);
|
|
||||||
const newPosition = {
|
const newPosition = {
|
||||||
sectionId: "3",
|
sectionId: "3",
|
||||||
xOffset: 20,
|
xOffset: 20,
|
||||||
@@ -26,7 +22,7 @@ describe("moveItemToSectionCallback should move item to section", () => {
|
|||||||
const board = new BoardMockBuilder().addItem(itemA).addItem(itemB).addItem(itemC).build();
|
const board = new BoardMockBuilder().addItem(itemA).addItem(itemB).addItem(itemC).build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const updatedBoard = moveItemToSectionCallback({ itemId: itemToMove, ...newPosition })(board);
|
const updatedBoard = moveItemToSectionCallback({ itemId: itemToMove, layoutId, ...newPosition })(board);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(updatedBoard.items).toHaveLength(3);
|
expect(updatedBoard.items).toHaveLength(3);
|
||||||
@@ -44,8 +40,6 @@ describe("moveItemToSectionCallback should move item to section", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const itemToMove = "2";
|
const itemToMove = "2";
|
||||||
const layoutId = "1";
|
const layoutId = "1";
|
||||||
const spy = vi.spyOn(boardContext, "getCurrentLayout");
|
|
||||||
spy.mockReturnValue(layoutId);
|
|
||||||
const newPosition = {
|
const newPosition = {
|
||||||
sectionId: "3",
|
sectionId: "3",
|
||||||
xOffset: 20,
|
xOffset: 20,
|
||||||
@@ -58,7 +52,7 @@ describe("moveItemToSectionCallback should move item to section", () => {
|
|||||||
const board = new BoardMockBuilder().addItem(itemA).addItem(itemC).build();
|
const board = new BoardMockBuilder().addItem(itemA).addItem(itemC).build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const updatedBoard = moveItemToSectionCallback({ itemId: itemToMove, ...newPosition })(board);
|
const updatedBoard = moveItemToSectionCallback({ itemId: itemToMove, layoutId, ...newPosition })(board);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(updatedBoard.items).toHaveLength(2);
|
expect(updatedBoard.items).toHaveLength(2);
|
||||||
|
|||||||
@@ -16,5 +16,4 @@
|
|||||||
.item > :global(.grid-stack-item-content) {
|
.item > :global(.grid-stack-item-content) {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: auto;
|
|
||||||
}
|
}
|
||||||
@@ -93,4 +93,25 @@ describe("createMobileBoardItems", () => {
|
|||||||
expect(result.map((item) => item.id)).toEqual(["second", "first"]);
|
expect(result.map((item) => item.id)).toEqual(["second", "first"]);
|
||||||
expect(result[1]).toMatchObject({ width: 1, height: 1 });
|
expect(result[1]).toMatchObject({ width: 1, height: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("keeps useful desktop footprints within the two-by-three mobile limit", () => {
|
||||||
|
const board = new BoardMockBuilder().build();
|
||||||
|
const desktopLayoutId = board.layouts.at(0)?.id;
|
||||||
|
if (!desktopLayoutId) throw new Error("Expected a desktop layout");
|
||||||
|
const rootSection = new EmptySectionMockBuilder({ id: "root" }).build();
|
||||||
|
board.sections.push(rootSection);
|
||||||
|
board.items.push(
|
||||||
|
new ItemMockBuilder({ id: "two-by-two" })
|
||||||
|
.addLayout({ layoutId: desktopLayoutId, sectionId: rootSection.id, width: 2, height: 2 })
|
||||||
|
.build(),
|
||||||
|
new ItemMockBuilder({ id: "one-by-one" })
|
||||||
|
.addLayout({ layoutId: desktopLayoutId, sectionId: rootSection.id, xOffset: 2, width: 1, height: 1 })
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(createMobileBoardItems(board, desktopLayoutId)).toMatchObject([
|
||||||
|
{ id: "two-by-two", width: 2, height: 2 },
|
||||||
|
{ id: "one-by-one", width: 1, height: 1 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import { fetchApi } from "@homarr/api/client";
|
import { fetchApi } from "@homarr/api/client";
|
||||||
import { getCurrentLayout, useRequiredBoard } from "@homarr/boards/context";
|
import { useCurrentLayout, useRequiredBoard } from "@homarr/boards/context";
|
||||||
import { createId } from "@homarr/common";
|
import { createId } from "@homarr/common";
|
||||||
import { useConfirmModal, useModalAction } from "@homarr/modals";
|
import { useConfirmModal, useModalAction } from "@homarr/modals";
|
||||||
import { useSettings } from "@homarr/settings";
|
import { useSettings } from "@homarr/settings";
|
||||||
@@ -18,6 +18,7 @@ export const useCategoryMenuActions = (category: CategorySection) => {
|
|||||||
const { addCategory, moveCategory, removeCategory, renameCategory } = useCategoryActions();
|
const { addCategory, moveCategory, removeCategory, renameCategory } = useCategoryActions();
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
|
const currentLayoutId = useCurrentLayout();
|
||||||
|
|
||||||
const createCategoryAtYOffset = useCallback(
|
const createCategoryAtYOffset = useCallback(
|
||||||
(position: number) => {
|
(position: number) => {
|
||||||
@@ -104,7 +105,6 @@ export const useCategoryMenuActions = (category: CategorySection) => {
|
|||||||
|
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const openAllInNewTabs = useCallback(async () => {
|
const openAllInNewTabs = useCallback(async () => {
|
||||||
const currentLayoutId = getCurrentLayout(board);
|
|
||||||
const appIds = filterByItemKind(
|
const appIds = filterByItemKind(
|
||||||
board.items.filter(
|
board.items.filter(
|
||||||
(item) => item.layouts.find((layout) => layout.layoutId === currentLayoutId)?.sectionId === category.id,
|
(item) => item.layouts.find((layout) => layout.layoutId === currentLayoutId)?.sectionId === category.id,
|
||||||
@@ -130,7 +130,7 @@ export const useCategoryMenuActions = (category: CategorySection) => {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}, [category, board, t, openConfirmModal, settings]);
|
}, [category, board, currentLayoutId, t, openConfirmModal, settings]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addCategoryAbove,
|
addCategoryAbove,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Badge, Box, Card } from "@mantine/core";
|
import { Badge, Box, Card } from "@mantine/core";
|
||||||
import combineClasses from "clsx";
|
import combineClasses from "clsx";
|
||||||
|
|
||||||
import { useCurrentLayout, useRequiredBoard } from "@homarr/boards/context";
|
import { useRequiredBoard } from "@homarr/boards/context";
|
||||||
|
|
||||||
import type { DynamicSectionItem } from "~/app/[locale]/boards/_types";
|
import type { DynamicSectionItem } from "~/app/[locale]/boards/_types";
|
||||||
import { BoardDynamicSectionMenu } from "./dynamic/dynamic-menu";
|
import { BoardDynamicSectionMenu } from "./dynamic/dynamic-menu";
|
||||||
@@ -14,7 +14,6 @@ interface Props {
|
|||||||
|
|
||||||
export const BoardDynamicSection = ({ section }: Props) => {
|
export const BoardDynamicSection = ({ section }: Props) => {
|
||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
const currentLayoutId = useCurrentLayout();
|
|
||||||
const options = section.options;
|
const options = section.options;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -52,8 +51,7 @@ export const BoardDynamicSection = ({ section }: Props) => {
|
|||||||
{options.title}
|
{options.title}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{/* Use unique key by layout to reinitialize gridstack */}
|
<GridStack section={section} className="min-row" />
|
||||||
<GridStack key={`${currentLayoutId}-${section.id}`} section={section} className="min-row" />
|
|
||||||
</Card>
|
</Card>
|
||||||
<BoardDynamicSectionMenu section={section} />
|
<BoardDynamicSectionMenu section={section} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import type { BoxProps } from "@mantine/core";
|
|||||||
import { Box } from "@mantine/core";
|
import { Box } from "@mantine/core";
|
||||||
import combineClasses from "clsx";
|
import combineClasses from "clsx";
|
||||||
|
|
||||||
|
import { useCurrentLayout } from "@homarr/boards/context";
|
||||||
|
|
||||||
import type { DynamicSectionItem, Section } from "~/app/[locale]/boards/_types";
|
import type { DynamicSectionItem, Section } from "~/app/[locale]/boards/_types";
|
||||||
import { SectionContent } from "../content";
|
import { SectionContent } from "../content";
|
||||||
import { SectionProvider } from "../section-context";
|
import { SectionProvider } from "../section-context";
|
||||||
@@ -15,6 +17,12 @@ interface Props extends BoxProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const GridStack = ({ section, ...props }: Props) => {
|
export const GridStack = ({ section, ...props }: Props) => {
|
||||||
|
const currentLayoutId = useCurrentLayout();
|
||||||
|
|
||||||
|
return <GridStackForLayout key={currentLayoutId} section={section} {...props} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
const GridStackForLayout = ({ section, ...props }: Props) => {
|
||||||
const { items, innerSections } = useSectionItems(section.id);
|
const { items, innerSections } = useSectionItems(section.id);
|
||||||
const itemIds = [...items, ...innerSections].map((item) => item.id);
|
const itemIds = [...items, ...innerSections].map((item) => item.id);
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
// Updates the react-query state
|
// Updates the react-query state
|
||||||
moveAndResizeItem({
|
moveAndResizeItem({
|
||||||
itemId: id,
|
itemId: id,
|
||||||
|
layoutId: currentLayoutId,
|
||||||
// We want the following properties to be null by default
|
// We want the following properties to be null by default
|
||||||
// so the next free position is used from the gridstack
|
// so the next free position is used from the gridstack
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
@@ -120,6 +121,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
if (type === "section") {
|
if (type === "section") {
|
||||||
moveAndResizeInnerSection({
|
moveAndResizeInnerSection({
|
||||||
innerSectionId: id,
|
innerSectionId: id,
|
||||||
|
layoutId: currentLayoutId,
|
||||||
// We want the following properties to be null by default
|
// We want the following properties to be null by default
|
||||||
// so the next free position is used from the gridstack
|
// so the next free position is used from the gridstack
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
@@ -136,7 +138,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
|
|
||||||
console.error(`Unknown grid-stack-item type to move. type='${type}' id='${id}'`);
|
console.error(`Unknown grid-stack-item type to move. type='${type}' id='${id}'`);
|
||||||
},
|
},
|
||||||
[moveAndResizeItem, moveAndResizeInnerSection],
|
[currentLayoutId, moveAndResizeItem, moveAndResizeInnerSection],
|
||||||
);
|
);
|
||||||
const onAdd = useCallback(
|
const onAdd = useCallback(
|
||||||
(addedNode: GridStackNode) => {
|
(addedNode: GridStackNode) => {
|
||||||
@@ -149,6 +151,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
// Updates the react-query state
|
// Updates the react-query state
|
||||||
moveItemToSection({
|
moveItemToSection({
|
||||||
itemId: id,
|
itemId: id,
|
||||||
|
layoutId: currentLayoutId,
|
||||||
sectionId: section.id,
|
sectionId: section.id,
|
||||||
// We want the following properties to be null by default
|
// We want the following properties to be null by default
|
||||||
// so the next free position is used from the gridstack
|
// so the next free position is used from the gridstack
|
||||||
@@ -167,6 +170,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
if (type === "section") {
|
if (type === "section") {
|
||||||
moveInnerSectionToSection({
|
moveInnerSectionToSection({
|
||||||
innerSectionId: id,
|
innerSectionId: id,
|
||||||
|
layoutId: currentLayoutId,
|
||||||
sectionId: section.id,
|
sectionId: section.id,
|
||||||
// We want the following properties to be null by default
|
// We want the following properties to be null by default
|
||||||
// so the next free position is used from the gridstack
|
// so the next free position is used from the gridstack
|
||||||
@@ -184,7 +188,7 @@ export const useGridstack = (section: Omit<Section, "items">, itemIds: string[])
|
|||||||
|
|
||||||
console.error(`Unknown grid-stack-item type to add. type='${type}' id='${id}'`);
|
console.error(`Unknown grid-stack-item type to add. type='${type}' id='${id}'`);
|
||||||
},
|
},
|
||||||
[moveItemToSection, moveInnerSectionToSection, section.id],
|
[currentLayoutId, moveItemToSection, moveInnerSectionToSection, section.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
// initialize the gridstack
|
// initialize the gridstack
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import { getCurrentLayout } from "@homarr/boards/context";
|
|
||||||
import { useUpdateBoard } from "@homarr/boards/updater";
|
import { useUpdateBoard } from "@homarr/boards/updater";
|
||||||
|
|
||||||
interface MoveAndResizeInnerSection {
|
interface MoveAndResizeInnerSection {
|
||||||
innerSectionId: string;
|
innerSectionId: string;
|
||||||
|
layoutId: string;
|
||||||
xOffset: number;
|
xOffset: number;
|
||||||
yOffset: number;
|
yOffset: number;
|
||||||
width: number;
|
width: number;
|
||||||
@@ -12,6 +12,7 @@ interface MoveAndResizeInnerSection {
|
|||||||
}
|
}
|
||||||
interface MoveInnerSectionToSection {
|
interface MoveInnerSectionToSection {
|
||||||
innerSectionId: string;
|
innerSectionId: string;
|
||||||
|
layoutId: string;
|
||||||
sectionId: string;
|
sectionId: string;
|
||||||
xOffset: number;
|
xOffset: number;
|
||||||
yOffset: number;
|
yOffset: number;
|
||||||
@@ -23,7 +24,7 @@ export const useSectionActions = () => {
|
|||||||
const { updateBoard } = useUpdateBoard();
|
const { updateBoard } = useUpdateBoard();
|
||||||
|
|
||||||
const moveAndResizeInnerSection = useCallback(
|
const moveAndResizeInnerSection = useCallback(
|
||||||
({ innerSectionId, ...positionProps }: MoveAndResizeInnerSection) => {
|
({ innerSectionId, layoutId, ...positionProps }: MoveAndResizeInnerSection) => {
|
||||||
updateBoard((previous) => ({
|
updateBoard((previous) => ({
|
||||||
...previous,
|
...previous,
|
||||||
sections: previous.sections.map((section) => {
|
sections: previous.sections.map((section) => {
|
||||||
@@ -31,12 +32,10 @@ export const useSectionActions = () => {
|
|||||||
if (section.id !== innerSectionId) return section;
|
if (section.id !== innerSectionId) return section;
|
||||||
if (section.kind !== "dynamic") return section;
|
if (section.kind !== "dynamic") return section;
|
||||||
|
|
||||||
const currentLayout = getCurrentLayout(previous);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...section,
|
...section,
|
||||||
layouts: section.layouts.map((layout) => {
|
layouts: section.layouts.map((layout) => {
|
||||||
if (layout.layoutId !== currentLayout) return layout;
|
if (layout.layoutId !== layoutId) return layout;
|
||||||
return {
|
return {
|
||||||
...layout,
|
...layout,
|
||||||
...positionProps,
|
...positionProps,
|
||||||
@@ -50,7 +49,7 @@ export const useSectionActions = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const moveInnerSectionToSection = useCallback(
|
const moveInnerSectionToSection = useCallback(
|
||||||
({ innerSectionId, sectionId, ...positionProps }: MoveInnerSectionToSection) => {
|
({ innerSectionId, layoutId, sectionId, ...positionProps }: MoveInnerSectionToSection) => {
|
||||||
updateBoard((previous) => {
|
updateBoard((previous) => {
|
||||||
return {
|
return {
|
||||||
...previous,
|
...previous,
|
||||||
@@ -59,12 +58,10 @@ export const useSectionActions = () => {
|
|||||||
if (section.id !== innerSectionId) return section;
|
if (section.id !== innerSectionId) return section;
|
||||||
if (section.kind !== "dynamic") return section;
|
if (section.kind !== "dynamic") return section;
|
||||||
|
|
||||||
const currentLayout = getCurrentLayout(previous);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...section,
|
...section,
|
||||||
layouts: section.layouts.map((layout) => {
|
layouts: section.layouts.map((layout) => {
|
||||||
if (layout.layoutId !== currentLayout) return layout;
|
if (layout.layoutId !== layoutId) return layout;
|
||||||
return {
|
return {
|
||||||
...layout,
|
...layout,
|
||||||
...positionProps,
|
...positionProps,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import type { PropsWithChildren } from "react";
|
|||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
import { useMediaQuery } from "@mantine/hooks";
|
import { useMediaQuery } from "@mantine/hooks";
|
||||||
|
|
||||||
|
import { useSettings } from "@homarr/settings";
|
||||||
|
|
||||||
export const mobileBoardMediaQuery = "(max-width: 48em)";
|
export const mobileBoardMediaQuery = "(max-width: 48em)";
|
||||||
|
|
||||||
const InitialMobileBoardContext = createContext<boolean | undefined>(undefined);
|
const InitialMobileBoardContext = createContext<boolean | undefined>(undefined);
|
||||||
@@ -17,5 +19,8 @@ export const MobileBoardViewportProvider = ({
|
|||||||
|
|
||||||
export const useIsMobileBoard = () => {
|
export const useIsMobileBoard = () => {
|
||||||
const initialIsMobile = useContext(InitialMobileBoardContext);
|
const initialIsMobile = useContext(InitialMobileBoardContext);
|
||||||
return useMediaQuery(mobileBoardMediaQuery, initialIsMobile, { getInitialValueInEffect: true });
|
const { enableAutomaticMobileLayout } = useSettings();
|
||||||
|
const isMobileViewport = useMediaQuery(mobileBoardMediaQuery, initialIsMobile, { getInitialValueInEffect: true });
|
||||||
|
|
||||||
|
return enableAutomaticMobileLayout && isMobileViewport;
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,229 @@
|
|||||||
|
import type { Page } from "@playwright/test";
|
||||||
|
import { chromium, devices, expect } from "@playwright/test";
|
||||||
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
|
import { stringify } from "superjson";
|
||||||
|
import { describe, test } from "vitest";
|
||||||
|
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import * as sqliteSchema from "../packages/db/schema/sqlite";
|
||||||
|
|
||||||
|
import { createHomarrContainer } from "./shared/create-homarr-container";
|
||||||
|
import { createSqliteDbFileAsync } from "./shared/e2e-db";
|
||||||
|
import type { SqliteDatabase } from "./shared/e2e-db";
|
||||||
|
import { seedAdminUserAsync } from "./shared/seed-admin-user";
|
||||||
|
|
||||||
|
const credentials = {
|
||||||
|
username: "admin",
|
||||||
|
password: "Comp(exP4sswOrd",
|
||||||
|
};
|
||||||
|
|
||||||
|
const boardName = "mobile-e2e";
|
||||||
|
|
||||||
|
const setAutomaticMobileLayoutAsync = async (page: Page, enabled: boolean) => {
|
||||||
|
await page.goto(new URL("/manage/settings", page.url()).toString());
|
||||||
|
const toggle = page.getByRole("switch", { name: "Use automatic mobile layout" });
|
||||||
|
await expect(toggle).toBeVisible();
|
||||||
|
|
||||||
|
if ((await toggle.isChecked()) !== enabled) {
|
||||||
|
await toggle.setChecked(enabled);
|
||||||
|
await toggle.locator("xpath=ancestor::form").getByRole("button", { name: "Save", exact: true }).click();
|
||||||
|
await expect(page.getByText("Settings saved successfully")).toBeVisible();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const seedBoardAsync = async (db: SqliteDatabase, userId: string) => {
|
||||||
|
const boardId = createId();
|
||||||
|
const desktopLayoutId = createId();
|
||||||
|
const mobileLayoutId = createId();
|
||||||
|
const sectionId = createId();
|
||||||
|
const notebookId = createId();
|
||||||
|
const clockId = createId();
|
||||||
|
|
||||||
|
await db.insert(sqliteSchema.boards).values({
|
||||||
|
id: boardId,
|
||||||
|
name: boardName,
|
||||||
|
creatorId: userId,
|
||||||
|
});
|
||||||
|
await db.insert(sqliteSchema.layouts).values([
|
||||||
|
{
|
||||||
|
id: desktopLayoutId,
|
||||||
|
name: "Desktop",
|
||||||
|
boardId,
|
||||||
|
columnCount: 12,
|
||||||
|
breakpoint: 1200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: mobileLayoutId,
|
||||||
|
name: "Mobile",
|
||||||
|
boardId,
|
||||||
|
columnCount: 4,
|
||||||
|
breakpoint: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await db.insert(sqliteSchema.sections).values({
|
||||||
|
id: sectionId,
|
||||||
|
boardId,
|
||||||
|
kind: "category",
|
||||||
|
name: "Dashboard",
|
||||||
|
xOffset: 0,
|
||||||
|
yOffset: 0,
|
||||||
|
});
|
||||||
|
await db.insert(sqliteSchema.items).values([
|
||||||
|
{
|
||||||
|
id: notebookId,
|
||||||
|
boardId,
|
||||||
|
kind: "notebook",
|
||||||
|
options: stringify({ content: "<p>Normal notebook content</p>" }),
|
||||||
|
advancedOptions: stringify({}),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: clockId,
|
||||||
|
boardId,
|
||||||
|
kind: "clock",
|
||||||
|
options: stringify({}),
|
||||||
|
advancedOptions: stringify({}),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await db.insert(sqliteSchema.itemLayouts).values([
|
||||||
|
{
|
||||||
|
itemId: notebookId,
|
||||||
|
layoutId: desktopLayoutId,
|
||||||
|
sectionId,
|
||||||
|
xOffset: 0,
|
||||||
|
yOffset: 0,
|
||||||
|
width: 2,
|
||||||
|
height: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
itemId: clockId,
|
||||||
|
layoutId: desktopLayoutId,
|
||||||
|
sectionId,
|
||||||
|
xOffset: 2,
|
||||||
|
yOffset: 0,
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
itemId: notebookId,
|
||||||
|
layoutId: mobileLayoutId,
|
||||||
|
sectionId,
|
||||||
|
xOffset: 0,
|
||||||
|
yOffset: 0,
|
||||||
|
width: 4,
|
||||||
|
height: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
itemId: clockId,
|
||||||
|
layoutId: mobileLayoutId,
|
||||||
|
sectionId,
|
||||||
|
xOffset: 0,
|
||||||
|
yOffset: 4,
|
||||||
|
width: 2,
|
||||||
|
height: 2,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await db
|
||||||
|
.update(sqliteSchema.users)
|
||||||
|
.set({
|
||||||
|
homeBoardId: boardId,
|
||||||
|
mobileHomeBoardId: boardId,
|
||||||
|
completedBoardTour: true,
|
||||||
|
})
|
||||||
|
.where(eq(sqliteSchema.users.id, userId));
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("Automatic mobile board", () => {
|
||||||
|
test("squeezes unchanged widgets into a read-only two-column grid", async () => {
|
||||||
|
const { db, localMountPath } = await createSqliteDbFileAsync();
|
||||||
|
const { userId } = await seedAdminUserAsync(db, credentials);
|
||||||
|
await seedBoardAsync(db, userId);
|
||||||
|
|
||||||
|
const container = await createHomarrContainer({
|
||||||
|
environment: {
|
||||||
|
AUTH_PROVIDERS: "credentials",
|
||||||
|
},
|
||||||
|
mounts: {
|
||||||
|
"/appdata": localMountPath,
|
||||||
|
},
|
||||||
|
}).start();
|
||||||
|
const baseUrl = `http://${container.getHost()}:${container.getMappedPort(7575)}`;
|
||||||
|
const browser = await chromium.launch();
|
||||||
|
const loginContext = await browser.newContext();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const loginPage = await loginContext.newPage();
|
||||||
|
await loginPage.goto(`${baseUrl}/auth/login`);
|
||||||
|
await loginPage.getByLabel("Username").fill(credentials.username);
|
||||||
|
await loginPage.locator("#password").fill(credentials.password);
|
||||||
|
await loginPage.locator("button[type='submit']").click();
|
||||||
|
await loginPage.waitForURL((url) => !url.pathname.includes("/auth/login"), { timeout: 15_000 });
|
||||||
|
await setAutomaticMobileLayoutAsync(loginPage, true);
|
||||||
|
const storageState = await loginContext.storageState();
|
||||||
|
|
||||||
|
const mobileContext = await browser.newContext({
|
||||||
|
storageState,
|
||||||
|
viewport: { width: 390, height: 844 },
|
||||||
|
userAgent: devices["iPhone 13"].userAgent,
|
||||||
|
hasTouch: true,
|
||||||
|
isMobile: true,
|
||||||
|
});
|
||||||
|
const mobilePage = await mobileContext.newPage();
|
||||||
|
await mobilePage.goto(`${baseUrl}/boards/${boardName}`);
|
||||||
|
|
||||||
|
const mobileBoard = mobilePage.locator("[data-mobile-board]");
|
||||||
|
const items = mobilePage.locator("[data-mobile-board-item]");
|
||||||
|
await expect(mobileBoard).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(items).toHaveCount(2);
|
||||||
|
await expect(mobilePage.locator(".grid-stack-item")).toHaveCount(0);
|
||||||
|
await expect(mobilePage.getByText("Normal notebook content")).toBeVisible();
|
||||||
|
await expect(mobilePage.getByRole("button", { name: "Edit item", exact: true })).toHaveCount(0);
|
||||||
|
await expect(mobilePage.getByRole("button", { name: /open widget details/i })).toHaveCount(0);
|
||||||
|
await expect(mobilePage.getByRole("button", { name: /actions for/i })).toHaveCount(0);
|
||||||
|
await expect(mobilePage.locator("[data-mobile-generic-summary], [data-mobile-display-mode]")).toHaveCount(0);
|
||||||
|
|
||||||
|
const metrics = await mobilePage.evaluate(() => {
|
||||||
|
const grid = document.querySelector<HTMLElement>("[data-mobile-board]");
|
||||||
|
const itemElements = Array.from(document.querySelectorAll<HTMLElement>("[data-mobile-board-item]"));
|
||||||
|
if (!grid || itemElements.length !== 2) throw new Error("Expected mobile grid and two items");
|
||||||
|
|
||||||
|
const gridStyle = getComputedStyle(grid);
|
||||||
|
const first = itemElements[0]?.getBoundingClientRect();
|
||||||
|
const second = itemElements[1]?.getBoundingClientRect();
|
||||||
|
if (!first || !second) throw new Error("Expected item bounds");
|
||||||
|
|
||||||
|
return {
|
||||||
|
columnCount: gridStyle.gridTemplateColumns.split(" ").filter(Boolean).length,
|
||||||
|
firstToSecondWidthRatio: first.width / second.width,
|
||||||
|
firstToSecondHeightRatio: first.height / second.height,
|
||||||
|
horizontalOverflow: document.documentElement.scrollWidth - document.documentElement.clientWidth,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(metrics.columnCount).toBe(2);
|
||||||
|
expect(metrics.firstToSecondWidthRatio).toBeGreaterThan(1.8);
|
||||||
|
expect(metrics.firstToSecondHeightRatio).toBeGreaterThan(1.8);
|
||||||
|
expect(metrics.horizontalOverflow).toBeLessThanOrEqual(0);
|
||||||
|
await mobileContext.close();
|
||||||
|
|
||||||
|
await setAutomaticMobileLayoutAsync(loginPage, false);
|
||||||
|
|
||||||
|
const legacyContext = await browser.newContext({
|
||||||
|
storageState: await loginContext.storageState(),
|
||||||
|
viewport: { width: 390, height: 844 },
|
||||||
|
userAgent: devices["iPhone 13"].userAgent,
|
||||||
|
hasTouch: true,
|
||||||
|
isMobile: true,
|
||||||
|
});
|
||||||
|
const legacyPage = await legacyContext.newPage();
|
||||||
|
await legacyPage.goto(`${baseUrl}/boards/${boardName}`);
|
||||||
|
await expect(legacyPage.locator("[data-mobile-board]")).toHaveCount(0);
|
||||||
|
await expect(legacyPage.locator(".grid-stack-item")).toHaveCount(2);
|
||||||
|
await expect(legacyPage.getByRole("button", { name: "Edit item", exact: true })).toBeVisible();
|
||||||
|
await legacyContext.close();
|
||||||
|
} finally {
|
||||||
|
await loginContext.close();
|
||||||
|
await browser.close();
|
||||||
|
await container.stop();
|
||||||
|
}
|
||||||
|
}, 180_000);
|
||||||
|
});
|
||||||
@@ -49,6 +49,7 @@ import {
|
|||||||
boardDuplicateSchema,
|
boardDuplicateSchema,
|
||||||
boardRenameSchema,
|
boardRenameSchema,
|
||||||
boardSaveLayoutSchema,
|
boardSaveLayoutSchema,
|
||||||
|
boardSaveLayoutsSchema,
|
||||||
boardSavePartialSettingsSchema,
|
boardSavePartialSettingsSchema,
|
||||||
boardSavePermissionsSchema,
|
boardSavePermissionsSchema,
|
||||||
boardSaveSchema,
|
boardSaveSchema,
|
||||||
@@ -687,7 +688,7 @@ export const boardRouter = createTRPCRouter({
|
|||||||
mcp: {
|
mcp: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
description:
|
description:
|
||||||
"Set a board's desktop column count and remove legacy responsive layouts. Requires modify permission. REQUIRED: id (board ID), columnCount (1-24)",
|
"Set a board's desktop column count while preserving saved responsive layouts. Requires modify permission. REQUIRED: id (board ID), columnCount (1-24)",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(boardSaveLayoutSchema)
|
.input(boardSaveLayoutSchema)
|
||||||
@@ -761,12 +762,8 @@ export const boardRouter = createTRPCRouter({
|
|||||||
|
|
||||||
await transaction
|
await transaction
|
||||||
.update(schema.layouts)
|
.update(schema.layouts)
|
||||||
.set({ name: "Base", columnCount: input.columnCount, breakpoint: 0 })
|
.set({ columnCount: input.columnCount })
|
||||||
.where(eq(schema.layouts.id, desktopLayout.id));
|
.where(eq(schema.layouts.id, desktopLayout.id));
|
||||||
|
|
||||||
await transaction
|
|
||||||
.delete(schema.layouts)
|
|
||||||
.where(and(eq(schema.layouts.boardId, board.id), not(eq(schema.layouts.id, desktopLayout.id))));
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleSync(db) {
|
handleSync(db) {
|
||||||
@@ -811,18 +808,230 @@ export const boardRouter = createTRPCRouter({
|
|||||||
|
|
||||||
transaction
|
transaction
|
||||||
.update(layouts)
|
.update(layouts)
|
||||||
.set({ name: "Base", columnCount: input.columnCount, breakpoint: 0 })
|
.set({ columnCount: input.columnCount })
|
||||||
.where(eq(layouts.id, desktopLayout.id))
|
.where(eq(layouts.id, desktopLayout.id))
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
transaction
|
|
||||||
.delete(layouts)
|
|
||||||
.where(and(eq(layouts.boardId, board.id), not(eq(layouts.id, desktopLayout.id))))
|
|
||||||
.run();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
saveLayouts: protectedProcedure
|
||||||
|
.input(boardSaveLayoutsSchema)
|
||||||
|
.output(boardSaveLayoutsSchema.shape.layouts)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.id), "modify");
|
||||||
|
|
||||||
|
const board = await getFullBoardWithWhereAsync(ctx.db, eq(boards.id, input.id), ctx.session.user.id);
|
||||||
|
const addedLayouts = filterAddedItems(input.layouts, board.layouts);
|
||||||
|
const layoutsToInsert: InferInsertModel<typeof layouts>[] = [];
|
||||||
|
const itemSectionLayoutsToInsert: InferInsertModel<typeof itemLayouts>[] = [];
|
||||||
|
const sectionLayoutsToInsert: InferInsertModel<typeof sectionLayouts>[] = [];
|
||||||
|
const savedLayoutIds = new Map<string, string>();
|
||||||
|
|
||||||
|
for (const addedLayout of addedLayouts) {
|
||||||
|
const layoutId = createId();
|
||||||
|
savedLayoutIds.set(addedLayout.id, layoutId);
|
||||||
|
|
||||||
|
layoutsToInsert.push({
|
||||||
|
id: layoutId,
|
||||||
|
name: addedLayout.name,
|
||||||
|
columnCount: addedLayout.columnCount,
|
||||||
|
breakpoint: addedLayout.breakpoint,
|
||||||
|
boardId: board.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const sortedLayouts = board.layouts.toSorted((layoutA, layoutB) => layoutA.columnCount - layoutB.columnCount);
|
||||||
|
const layoutToClone =
|
||||||
|
sortedLayouts.find((layout) => layout.columnCount >= addedLayout.columnCount) ?? sortedLayouts.at(-1);
|
||||||
|
|
||||||
|
if (!layoutToClone) {
|
||||||
|
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR", message: "Board must have a layout" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedBoardLayout = getUpdatedBoardLayout(board, {
|
||||||
|
previous: {
|
||||||
|
layoutId: layoutToClone.id,
|
||||||
|
columnCount: layoutToClone.columnCount,
|
||||||
|
},
|
||||||
|
current: {
|
||||||
|
layoutId,
|
||||||
|
columnCount: addedLayout.columnCount,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
itemSectionLayoutsToInsert.push(...updatedBoardLayout.itemSectionLayouts);
|
||||||
|
sectionLayoutsToInsert.push(...updatedBoardLayout.sectionLayouts);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedLayouts = filterUpdatedItems(input.layouts, board.layouts);
|
||||||
|
const itemSectionLayoutsToUpdate: InferInsertModel<typeof itemLayouts>[] = [];
|
||||||
|
const sectionLayoutsToUpdate: InferInsertModel<typeof sectionLayouts>[] = [];
|
||||||
|
const layoutsToUpdate: typeof input.layouts = [];
|
||||||
|
|
||||||
|
for (const updatedLayout of updatedLayouts) {
|
||||||
|
const dbLayout = board.layouts.find((layout) => layout.id === updatedLayout.id);
|
||||||
|
if (!dbLayout) continue;
|
||||||
|
|
||||||
|
if (dbLayout.columnCount !== updatedLayout.columnCount) {
|
||||||
|
const updatedBoardLayout = getUpdatedBoardLayout(board, {
|
||||||
|
previous: {
|
||||||
|
layoutId: dbLayout.id,
|
||||||
|
columnCount: dbLayout.columnCount,
|
||||||
|
},
|
||||||
|
current: {
|
||||||
|
layoutId: dbLayout.id,
|
||||||
|
columnCount: updatedLayout.columnCount,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
itemSectionLayoutsToUpdate.push(...updatedBoardLayout.itemSectionLayouts);
|
||||||
|
sectionLayoutsToUpdate.push(...updatedBoardLayout.sectionLayouts);
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutsToUpdate.push(updatedLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedLayoutIds = filterRemovedItems(input.layouts, board.layouts).map((layout) => layout.id);
|
||||||
|
|
||||||
|
await handleTransactionsAsync(ctx.db, {
|
||||||
|
async handleAsync(db, schema) {
|
||||||
|
await db.transaction(async (transaction) => {
|
||||||
|
if (layoutsToInsert.length > 0) {
|
||||||
|
await transaction.insert(schema.layouts).values(layoutsToInsert);
|
||||||
|
}
|
||||||
|
if (itemSectionLayoutsToInsert.length > 0) {
|
||||||
|
await transaction.insert(schema.itemLayouts).values(itemSectionLayoutsToInsert);
|
||||||
|
}
|
||||||
|
if (sectionLayoutsToInsert.length > 0) {
|
||||||
|
await transaction.insert(schema.sectionLayouts).values(sectionLayoutsToInsert);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const itemSectionLayout of itemSectionLayoutsToUpdate) {
|
||||||
|
await transaction
|
||||||
|
.update(schema.itemLayouts)
|
||||||
|
.set({
|
||||||
|
height: itemSectionLayout.height,
|
||||||
|
width: itemSectionLayout.width,
|
||||||
|
xOffset: itemSectionLayout.xOffset,
|
||||||
|
yOffset: itemSectionLayout.yOffset,
|
||||||
|
sectionId: itemSectionLayout.sectionId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(schema.itemLayouts.itemId, itemSectionLayout.itemId),
|
||||||
|
eq(schema.itemLayouts.layoutId, itemSectionLayout.layoutId),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const sectionLayout of sectionLayoutsToUpdate) {
|
||||||
|
await transaction
|
||||||
|
.update(schema.sectionLayouts)
|
||||||
|
.set({
|
||||||
|
height: sectionLayout.height,
|
||||||
|
width: sectionLayout.width,
|
||||||
|
xOffset: sectionLayout.xOffset,
|
||||||
|
yOffset: sectionLayout.yOffset,
|
||||||
|
parentSectionId: sectionLayout.parentSectionId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(schema.sectionLayouts.sectionId, sectionLayout.sectionId),
|
||||||
|
eq(schema.sectionLayouts.layoutId, sectionLayout.layoutId),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const layout of layoutsToUpdate) {
|
||||||
|
await transaction
|
||||||
|
.update(schema.layouts)
|
||||||
|
.set({
|
||||||
|
name: layout.name,
|
||||||
|
columnCount: layout.columnCount,
|
||||||
|
breakpoint: layout.breakpoint,
|
||||||
|
})
|
||||||
|
.where(eq(schema.layouts.id, layout.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removedLayoutIds.length > 0) {
|
||||||
|
await transaction.delete(schema.layouts).where(inArray(schema.layouts.id, removedLayoutIds));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
if (layoutsToInsert.length > 0) {
|
||||||
|
transaction.insert(layouts).values(layoutsToInsert).run();
|
||||||
|
}
|
||||||
|
if (itemSectionLayoutsToInsert.length > 0) {
|
||||||
|
transaction.insert(itemLayouts).values(itemSectionLayoutsToInsert).run();
|
||||||
|
}
|
||||||
|
if (sectionLayoutsToInsert.length > 0) {
|
||||||
|
transaction.insert(sectionLayouts).values(sectionLayoutsToInsert).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const itemSectionLayout of itemSectionLayoutsToUpdate) {
|
||||||
|
transaction
|
||||||
|
.update(itemLayouts)
|
||||||
|
.set({
|
||||||
|
height: itemSectionLayout.height,
|
||||||
|
width: itemSectionLayout.width,
|
||||||
|
xOffset: itemSectionLayout.xOffset,
|
||||||
|
yOffset: itemSectionLayout.yOffset,
|
||||||
|
sectionId: itemSectionLayout.sectionId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(itemLayouts.itemId, itemSectionLayout.itemId),
|
||||||
|
eq(itemLayouts.layoutId, itemSectionLayout.layoutId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const sectionLayout of sectionLayoutsToUpdate) {
|
||||||
|
transaction
|
||||||
|
.update(sectionLayouts)
|
||||||
|
.set({
|
||||||
|
height: sectionLayout.height,
|
||||||
|
width: sectionLayout.width,
|
||||||
|
xOffset: sectionLayout.xOffset,
|
||||||
|
yOffset: sectionLayout.yOffset,
|
||||||
|
parentSectionId: sectionLayout.parentSectionId,
|
||||||
|
})
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(sectionLayouts.sectionId, sectionLayout.sectionId),
|
||||||
|
eq(sectionLayouts.layoutId, sectionLayout.layoutId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const layout of layoutsToUpdate) {
|
||||||
|
transaction
|
||||||
|
.update(layouts)
|
||||||
|
.set({
|
||||||
|
name: layout.name,
|
||||||
|
columnCount: layout.columnCount,
|
||||||
|
breakpoint: layout.breakpoint,
|
||||||
|
})
|
||||||
|
.where(eq(layouts.id, layout.id))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removedLayoutIds.length > 0) {
|
||||||
|
transaction.delete(layouts).where(inArray(layouts.id, removedLayoutIds)).run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return input.layouts.map((layout) => ({
|
||||||
|
...layout,
|
||||||
|
id: savedLayoutIds.get(layout.id) ?? layout.id,
|
||||||
|
}));
|
||||||
|
}),
|
||||||
savePartialBoardSettings: protectedProcedure
|
savePartialBoardSettings: protectedProcedure
|
||||||
.meta({
|
.meta({
|
||||||
openapi: { method: "PATCH", path: "/api/boards/{id}/settings", tags: ["boards"], protect: true },
|
openapi: { method: "PATCH", path: "/api/boards/{id}/settings", tags: ["boards"], protect: true },
|
||||||
@@ -1491,16 +1700,16 @@ export const boardRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const itemId = createId();
|
const itemId = createId();
|
||||||
|
const itemRow = {
|
||||||
await ctx.db.insert(items).values({
|
|
||||||
id: itemId,
|
id: itemId,
|
||||||
boardId: input.boardId,
|
boardId: input.boardId,
|
||||||
kind: input.kind,
|
kind: input.kind,
|
||||||
options: superjson.stringify(input.options),
|
options: superjson.stringify(input.options),
|
||||||
advancedOptions: emptySuperJSON,
|
advancedOptions: emptySuperJSON,
|
||||||
});
|
};
|
||||||
|
|
||||||
const layoutRows: (typeof itemLayouts.$inferInsert)[] = [];
|
const layoutRows: (typeof itemLayouts.$inferInsert)[] = [];
|
||||||
|
const defaultSize = widgetDefaultSizes[input.kind as WidgetKind] ?? { width: 1, height: 1 };
|
||||||
|
|
||||||
for (const layout of board.layouts) {
|
for (const layout of board.layouts) {
|
||||||
const existingInSection = board.items
|
const existingInSection = board.items
|
||||||
@@ -1519,14 +1728,17 @@ export const boardRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSize = widgetDefaultSizes[input.kind as WidgetKind] ?? { width: 1, height: 1 };
|
const layoutItemSize = {
|
||||||
|
...defaultSize,
|
||||||
|
width: Math.min(defaultSize.width, layout.columnCount),
|
||||||
|
};
|
||||||
|
|
||||||
const fitsAt = (x: number, y: number) => {
|
const fitsAt = (x: number, y: number) => {
|
||||||
if (x + defaultSize.width > layout.columnCount) return false;
|
if (x + layoutItemSize.width > layout.columnCount) return false;
|
||||||
for (let dy = 0; dy < defaultSize.height; dy++) {
|
for (let dy = 0; dy < layoutItemSize.height; dy++) {
|
||||||
const row = occupied[y + dy];
|
const row = occupied[y + dy];
|
||||||
if (!row) continue;
|
if (!row) continue;
|
||||||
for (let dx = 0; dx < defaultSize.width; dx++) {
|
for (let dx = 0; dx < layoutItemSize.width; dx++) {
|
||||||
if (row[x + dx]) return false;
|
if (row[x + dx]) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1544,8 +1756,8 @@ export const boardRouter = createTRPCRouter({
|
|||||||
layoutId: layout.id,
|
layoutId: layout.id,
|
||||||
xOffset: x,
|
xOffset: x,
|
||||||
yOffset: y,
|
yOffset: y,
|
||||||
width: defaultSize.width,
|
width: layoutItemSize.width,
|
||||||
height: defaultSize.height,
|
height: layoutItemSize.height,
|
||||||
});
|
});
|
||||||
placed = true;
|
placed = true;
|
||||||
}
|
}
|
||||||
@@ -1560,15 +1772,32 @@ export const boardRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layoutRows.length > 0) {
|
const integrationRows = input.integrationIds.map((integrationId) => ({ itemId, integrationId }));
|
||||||
await ctx.db.insert(itemLayouts).values(layoutRows);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.integrationIds.length > 0) {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await ctx.db
|
async handleAsync(db, schema) {
|
||||||
.insert(integrationItems)
|
await db.transaction(async (transaction) => {
|
||||||
.values(input.integrationIds.map((integrationId) => ({ itemId, integrationId })));
|
await transaction.insert(schema.items).values(itemRow);
|
||||||
}
|
if (layoutRows.length > 0) {
|
||||||
|
await transaction.insert(schema.itemLayouts).values(layoutRows);
|
||||||
|
}
|
||||||
|
if (integrationRows.length > 0) {
|
||||||
|
await transaction.insert(schema.integrationItems).values(integrationRows);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction.insert(items).values(itemRow).run();
|
||||||
|
if (layoutRows.length > 0) {
|
||||||
|
transaction.insert(itemLayouts).values(layoutRows).run();
|
||||||
|
}
|
||||||
|
if (integrationRows.length > 0) {
|
||||||
|
transaction.insert(integrationItems).values(integrationRows).run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return { itemId };
|
return { itemId };
|
||||||
}),
|
}),
|
||||||
@@ -1592,6 +1821,9 @@ const getHomeIdBoardAsync = async (
|
|||||||
user: InferSelectModel<typeof users> | null,
|
user: InferSelectModel<typeof users> | null,
|
||||||
deviceType: DeviceType,
|
deviceType: DeviceType,
|
||||||
) => {
|
) => {
|
||||||
|
// Mobile home-board selection remains device-based because the server does
|
||||||
|
// not know the resolved CSS viewport. Tablet rendering is resolved against
|
||||||
|
// 48em on the client and must not be guessed here.
|
||||||
const settingKey = deviceType === "mobile" ? "mobileHomeBoardId" : "homeBoardId";
|
const settingKey = deviceType === "mobile" ? "mobileHomeBoardId" : "homeBoardId";
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -1613,8 +1845,7 @@ const getHomeIdBoardAsync = async (
|
|||||||
and(
|
and(
|
||||||
eq(groupMembers.userId, user.id),
|
eq(groupMembers.userId, user.id),
|
||||||
not(eq(groups.name, everyoneGroup)),
|
not(eq(groups.name, everyoneGroup)),
|
||||||
not(isNull(groups[settingKey])),
|
or(not(isNull(groups[settingKey])), not(isNull(groups.homeBoardId))),
|
||||||
not(isNull(groups.homeBoardId)),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.orderBy(asc(groups.position))
|
.orderBy(asc(groups.position))
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import { and, eq, inArray } from "@homarr/db";
|
|||||||
import {
|
import {
|
||||||
getServerSettingByKeyAsync,
|
getServerSettingByKeyAsync,
|
||||||
getServerSettingsAsync,
|
getServerSettingsAsync,
|
||||||
insertServerSettingByKeyAsync,
|
mergeServerSettingByKeyAsync,
|
||||||
updateServerSettingByKeyAsync,
|
updateServerSettingByKeyAsync,
|
||||||
} from "@homarr/db/queries";
|
} from "@homarr/db/queries";
|
||||||
import { boards, serverSettings } from "@homarr/db/schema";
|
import { boards } from "@homarr/db/schema";
|
||||||
import type { ServerSettings } from "@homarr/server-settings";
|
import type { ServerSettings } from "@homarr/server-settings";
|
||||||
import { defaultServerSettingsKeys } from "@homarr/server-settings";
|
import { defaultServerSettingsKeys } from "@homarr/server-settings";
|
||||||
import { settingsInitSchema } from "@homarr/validation/settings";
|
import { settingsInitSchema } from "@homarr/validation/settings";
|
||||||
@@ -19,6 +19,7 @@ import { nextOnboardingStepAsync } from "./onboard/onboard-queries";
|
|||||||
const boardServerSettingsSchema = z.object({
|
const boardServerSettingsSchema = z.object({
|
||||||
homeBoardId: z.string().nullable(),
|
homeBoardId: z.string().nullable(),
|
||||||
mobileHomeBoardId: z.string().nullable(),
|
mobileHomeBoardId: z.string().nullable(),
|
||||||
|
enableAutomaticMobileLayout: z.boolean(),
|
||||||
enableStatusByDefault: z.boolean(),
|
enableStatusByDefault: z.boolean(),
|
||||||
forceDisableStatus: z.boolean(),
|
forceDisableStatus: z.boolean(),
|
||||||
}) satisfies z.ZodType<ServerSettings["board"]>;
|
}) satisfies z.ZodType<ServerSettings["board"]>;
|
||||||
@@ -39,7 +40,7 @@ export const serverSettingsRouter = createTRPCRouter({
|
|||||||
mcp: {
|
mcp: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
description:
|
description:
|
||||||
"Get global board defaults, including desktop/mobile home board IDs and status behavior. Requires admin permission",
|
"Get global board defaults, including desktop/mobile home board IDs, automatic mobile layout mode, and status behavior. Requires admin permission",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(z.void())
|
.input(z.void())
|
||||||
@@ -54,7 +55,7 @@ export const serverSettingsRouter = createTRPCRouter({
|
|||||||
mcp: {
|
mcp: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
description:
|
description:
|
||||||
"Update global board defaults. Requires admin permission. Optional fields: homeBoardId, mobileHomeBoardId, enableStatusByDefault, forceDisableStatus. Home board IDs must reference public boards or be null",
|
"Update global board defaults. Requires admin permission. Optional fields: homeBoardId, mobileHomeBoardId, enableAutomaticMobileLayout, enableStatusByDefault, forceDisableStatus. Home board IDs must reference public boards or be null",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.input(boardServerSettingsUpdateSchema)
|
.input(boardServerSettingsUpdateSchema)
|
||||||
@@ -81,17 +82,9 @@ export const serverSettingsRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const current = await getServerSettingByKeyAsync(ctx.db, "board");
|
const current = await getServerSettingByKeyAsync(ctx.db, "board");
|
||||||
const next = { ...current, ...input };
|
const next = { ...current, ...input };
|
||||||
const existing = await ctx.db.query.serverSettings.findFirst({
|
await mergeServerSettingByKeyAsync(ctx.db, "board", next, input);
|
||||||
where: eq(serverSettings.settingKey, "board"),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing) {
|
return await getServerSettingByKeyAsync(ctx.db, "board");
|
||||||
await updateServerSettingByKeyAsync(ctx.db, "board", next);
|
|
||||||
} else {
|
|
||||||
await insertServerSettingByKeyAsync(ctx.db, "board", next);
|
|
||||||
}
|
|
||||||
|
|
||||||
return next;
|
|
||||||
}),
|
}),
|
||||||
saveSettings: permissionRequiredProcedure
|
saveSettings: permissionRequiredProcedure
|
||||||
.requiresPermission("admin")
|
.requiresPermission("admin")
|
||||||
@@ -103,10 +96,11 @@ export const serverSettingsRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const current = await getServerSettingByKeyAsync(ctx.db, input.settingsKey);
|
const current = await getServerSettingByKeyAsync(ctx.db, input.settingsKey);
|
||||||
await updateServerSettingByKeyAsync(ctx.db, input.settingsKey, {
|
const next = {
|
||||||
...current,
|
...current,
|
||||||
...input.value,
|
...input.value,
|
||||||
} as ServerSettings[keyof ServerSettings]);
|
} as ServerSettings[keyof ServerSettings];
|
||||||
|
await mergeServerSettingByKeyAsync(ctx.db, input.settingsKey, next, input.value);
|
||||||
}),
|
}),
|
||||||
initSettings: onboardingProcedure
|
initSettings: onboardingProcedure
|
||||||
.requiresStep("settings")
|
.requiresStep("settings")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { describe, expect, it, test, vi } from "vitest";
|
|||||||
import type { Session } from "@homarr/auth";
|
import type { Session } from "@homarr/auth";
|
||||||
import { createId } from "@homarr/common";
|
import { createId } from "@homarr/common";
|
||||||
import type { Database, InferInsertModel } from "@homarr/db";
|
import type { Database, InferInsertModel } from "@homarr/db";
|
||||||
import { and, eq } from "@homarr/db";
|
import { and, eq, not } from "@homarr/db";
|
||||||
import {
|
import {
|
||||||
boardGroupPermissions,
|
boardGroupPermissions,
|
||||||
boards,
|
boards,
|
||||||
@@ -516,6 +516,64 @@ describe("getHomeBoard should return home board", () => {
|
|||||||
});
|
});
|
||||||
expect(spy).toHaveBeenCalledWith(expect.anything(), expect.anything(), "view");
|
expect(spy).toHaveBeenCalledWith(expect.anything(), expect.anything(), "view");
|
||||||
});
|
});
|
||||||
|
test.each([
|
||||||
|
{ deviceType: "mobile", expectedBoard: "mobile-home" },
|
||||||
|
{ deviceType: "tablet", expectedBoard: "desktop-home" },
|
||||||
|
] as const)(
|
||||||
|
"should use the $expectedBoard preference for a $deviceType device",
|
||||||
|
async ({ deviceType, expectedBoard }) => {
|
||||||
|
// Arrange
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType, session: defaultSession });
|
||||||
|
|
||||||
|
const mobileBoardProps = await createFullBoardAsync(db, "mobile-home");
|
||||||
|
const desktopBoardProps = await createFullBoardAsync(db, "desktop-home");
|
||||||
|
await db
|
||||||
|
.update(users)
|
||||||
|
.set({
|
||||||
|
homeBoardId: desktopBoardProps.boardId,
|
||||||
|
mobileHomeBoardId: mobileBoardProps.boardId,
|
||||||
|
})
|
||||||
|
.where(eq(users.id, defaultCreatorId));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = await caller.getHomeBoard();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expectInputToBeFullBoardWithName(result, {
|
||||||
|
...(expectedBoard === "mobile-home" ? mobileBoardProps : desktopBoardProps),
|
||||||
|
name: expectedBoard,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
test("should return a mobile-only group home board", async () => {
|
||||||
|
// Arrange
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: "mobile", session: defaultSession });
|
||||||
|
|
||||||
|
const mobileBoardProps = await createFullBoardAsync(db, "group-mobile-home");
|
||||||
|
const groupId = createId();
|
||||||
|
await db.insert(groups).values({
|
||||||
|
id: groupId,
|
||||||
|
name: "mobile group",
|
||||||
|
position: 1,
|
||||||
|
homeBoardId: null,
|
||||||
|
mobileHomeBoardId: mobileBoardProps.boardId,
|
||||||
|
});
|
||||||
|
await db.insert(groupMembers).values({
|
||||||
|
userId: defaultCreatorId,
|
||||||
|
groupId,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = await caller.getHomeBoard();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expectInputToBeFullBoardWithName(result, {
|
||||||
|
name: "group-mobile-home",
|
||||||
|
...mobileBoardProps,
|
||||||
|
});
|
||||||
|
});
|
||||||
test("should return global home board when user doesn't have one", async () => {
|
test("should return global home board when user doesn't have one", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const spy = vi.spyOn(boardAccess, "throwIfActionForbiddenAsync");
|
const spy = vi.spyOn(boardAccess, "throwIfActionForbiddenAsync");
|
||||||
@@ -1324,6 +1382,187 @@ describe("saveGroupBoardPermissions should save group board permissions", () =>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createExistingLayout = (id: string) => ({
|
||||||
|
id,
|
||||||
|
name: "Base",
|
||||||
|
columnCount: 10,
|
||||||
|
breakpoint: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const createNewLayout = (columnCount: number) => ({
|
||||||
|
id: createId(),
|
||||||
|
name: "New layout",
|
||||||
|
columnCount,
|
||||||
|
breakpoint: 1400,
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("saveLayouts should preserve legacy responsive layout editing", () => {
|
||||||
|
test("should add a layout and clone item and dynamic-section placements", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId, sectionId, itemId } = await createFullBoardAsync(db, "default");
|
||||||
|
const assignments = await createItemsAndSectionsAsync(db, {
|
||||||
|
boardId,
|
||||||
|
layoutId,
|
||||||
|
sectionId,
|
||||||
|
});
|
||||||
|
const newLayout = createNewLayout(3);
|
||||||
|
|
||||||
|
const savedLayouts = await caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [createExistingLayout(layoutId), newLayout],
|
||||||
|
});
|
||||||
|
|
||||||
|
const layout = expectToBeDefined(
|
||||||
|
await db.query.layouts.findFirst({
|
||||||
|
where: not(eq(layouts.id, layoutId)),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(layout).toMatchObject({
|
||||||
|
name: newLayout.name,
|
||||||
|
columnCount: newLayout.columnCount,
|
||||||
|
breakpoint: newLayout.breakpoint,
|
||||||
|
});
|
||||||
|
expect(savedLayouts).toEqual([createExistingLayout(layoutId), { ...newLayout, id: layout.id }]);
|
||||||
|
await expectLayoutForRootLayoutAsync(db, sectionId, layout.id, {
|
||||||
|
...assignments.inRoot,
|
||||||
|
a: itemId,
|
||||||
|
});
|
||||||
|
await expectLayoutForDynamicSectionAsync(db, assignments.inRoot.f, layout.id, assignments.inDynamicSection);
|
||||||
|
|
||||||
|
await caller.saveLayouts({ id: boardId, layouts: savedLayouts });
|
||||||
|
await expect(db.query.layouts.findMany({ where: eq(layouts.boardId, boardId) })).resolves.toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should update layout metadata and positions", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId, sectionId, itemId } = await createFullBoardAsync(db, "default");
|
||||||
|
const assignments = await createItemsAndSectionsAsync(db, {
|
||||||
|
boardId,
|
||||||
|
layoutId,
|
||||||
|
sectionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
await caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [
|
||||||
|
{
|
||||||
|
id: layoutId,
|
||||||
|
name: "Phone",
|
||||||
|
columnCount: 3,
|
||||||
|
breakpoint: 480,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(db.query.layouts.findFirst({ where: eq(layouts.id, layoutId) })).resolves.toMatchObject({
|
||||||
|
name: "Phone",
|
||||||
|
columnCount: 3,
|
||||||
|
breakpoint: 480,
|
||||||
|
});
|
||||||
|
await expectLayoutForRootLayoutAsync(db, sectionId, layoutId, {
|
||||||
|
...assignments.inRoot,
|
||||||
|
a: itemId,
|
||||||
|
});
|
||||||
|
await expectLayoutForDynamicSectionAsync(db, assignments.inRoot.f, layoutId, assignments.inDynamicSection);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should remove layouts omitted from the saved responsive configuration", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId } = await createFullBoardAsync(db, "default");
|
||||||
|
|
||||||
|
await caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [createNewLayout(12)],
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(db.query.layouts.findFirst({ where: eq(layouts.id, layoutId) })).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should reject duplicate responsive breakpoints", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId } = await createFullBoardAsync(db, "default");
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [
|
||||||
|
createExistingLayout(layoutId),
|
||||||
|
{
|
||||||
|
...createNewLayout(4),
|
||||||
|
breakpoint: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({ code: "BAD_REQUEST" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should reject duplicate responsive layout IDs", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId } = await createFullBoardAsync(db, "default");
|
||||||
|
const existingLayout = createExistingLayout(layoutId);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [existingLayout, { ...existingLayout, name: "Phone", breakpoint: 480 }],
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({ code: "BAD_REQUEST" });
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should reject fractional responsive layout values", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId } = await createFullBoardAsync(db, "default");
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [{ ...createExistingLayout(layoutId), breakpoint: 480.5 }],
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({ code: "BAD_REQUEST" });
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
caller.saveLayouts({
|
||||||
|
id: boardId,
|
||||||
|
layouts: [{ ...createExistingLayout(layoutId), columnCount: 3.5 }],
|
||||||
|
}),
|
||||||
|
).rejects.toMatchObject({ code: "BAD_REQUEST" });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addItem should preserve every saved layout", () => {
|
||||||
|
test("should clamp wide widgets to a retained narrow layout", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
|
const { boardId, layoutId } = await createFullBoardAsync(db, "default");
|
||||||
|
const mobileLayoutId = createId();
|
||||||
|
await db.insert(layouts).values({
|
||||||
|
id: mobileLayoutId,
|
||||||
|
name: "Mobile",
|
||||||
|
columnCount: 1,
|
||||||
|
breakpoint: 480,
|
||||||
|
boardId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { itemId } = await caller.addItem({
|
||||||
|
boardId,
|
||||||
|
kind: "mediaMissing",
|
||||||
|
});
|
||||||
|
|
||||||
|
const savedItemLayouts = await db.query.itemLayouts.findMany({
|
||||||
|
where: eq(itemLayouts.itemId, itemId),
|
||||||
|
});
|
||||||
|
expect(savedItemLayouts).toHaveLength(2);
|
||||||
|
expect(savedItemLayouts).toContainEqual(expect.objectContaining({ layoutId, width: 4 }));
|
||||||
|
expect(savedItemLayouts).toContainEqual(expect.objectContaining({ layoutId: mobileLayoutId, width: 1 }));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("saveLayout should save the desktop layout", () => {
|
describe("saveLayout should save the desktop layout", () => {
|
||||||
test("should update position of items when column count changes", async () => {
|
test("should update position of items when column count changes", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -1349,7 +1588,7 @@ describe("saveLayout should save the desktop layout", () => {
|
|||||||
});
|
});
|
||||||
await expectLayoutForDynamicSectionAsync(db, assignments.inRoot.f, layoutId, assignments.inDynamicSection);
|
await expectLayoutForDynamicSectionAsync(db, assignments.inRoot.f, layoutId, assignments.inDynamicSection);
|
||||||
});
|
});
|
||||||
test("should keep the desktop layout and remove legacy responsive layouts", async () => {
|
test("should preserve legacy layouts and desktop metadata", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const db = createDb();
|
const db = createDb();
|
||||||
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
const caller = boardRouter.createCaller({ db, deviceType: undefined, session: defaultSession });
|
||||||
@@ -1376,15 +1615,18 @@ describe("saveLayout should save the desktop layout", () => {
|
|||||||
// Act
|
// Act
|
||||||
await caller.saveLayout({
|
await caller.saveLayout({
|
||||||
id: boardId,
|
id: boardId,
|
||||||
columnCount: 16,
|
columnCount: 14,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
const savedLayouts = await db.query.layouts.findMany({ where: eq(layouts.boardId, boardId) });
|
const savedLayouts = await db.query.layouts.findMany({ where: eq(layouts.boardId, boardId) });
|
||||||
expect(savedLayouts).toEqual([
|
expect(savedLayouts).toHaveLength(2);
|
||||||
expect.objectContaining({ id: desktopLayoutId, name: "Base", columnCount: 16, breakpoint: 0 }),
|
expect(savedLayouts).toContainEqual(
|
||||||
]);
|
expect.objectContaining({ id: layoutId, name: "Base", columnCount: 10, breakpoint: 0 }),
|
||||||
expect(savedLayouts.some((layout) => layout.id === layoutId)).toBe(false);
|
);
|
||||||
|
expect(savedLayouts).toContainEqual(
|
||||||
|
expect.objectContaining({ id: desktopLayoutId, name: "Large", columnCount: 14, breakpoint: 1200 }),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test("should fail when board not found", async () => {
|
test("should fail when board not found", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -1427,9 +1669,12 @@ const expectInputToBeFullBoardWithName = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createFullBoardAsync = async (db: Database, name: string) => {
|
const createFullBoardAsync = async (db: Database, name: string) => {
|
||||||
await db.insert(users).values({
|
await db
|
||||||
id: defaultCreatorId,
|
.insert(users)
|
||||||
});
|
.values({
|
||||||
|
id: defaultCreatorId,
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
|
|
||||||
const boardId = createId();
|
const boardId = createId();
|
||||||
await db.insert(boards).values({
|
await db.insert(boards).values({
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { describe, expect, test, vi } from "vitest";
|
|||||||
|
|
||||||
import type { Session } from "@homarr/auth";
|
import type { Session } from "@homarr/auth";
|
||||||
import { createId } from "@homarr/common";
|
import { createId } from "@homarr/common";
|
||||||
import { boards, serverSettings } from "@homarr/db/schema";
|
import { boards, layouts, serverSettings } from "@homarr/db/schema";
|
||||||
import { createDb } from "@homarr/db/test";
|
import { createDb } from "@homarr/db/test";
|
||||||
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
|
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
|
||||||
|
|
||||||
@@ -56,6 +56,33 @@ describe("getAll server settings", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("saveSettings", () => {
|
describe("saveSettings", () => {
|
||||||
|
test("saveSettings should persist settings when defaults are not seeded", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = serverSettingsRouter.createCaller({
|
||||||
|
db,
|
||||||
|
deviceType: undefined,
|
||||||
|
session: defaultSession,
|
||||||
|
});
|
||||||
|
|
||||||
|
await caller.saveSettings({
|
||||||
|
settingsKey: "board",
|
||||||
|
value: {
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const dbSettings = await db.select().from(serverSettings);
|
||||||
|
expect(dbSettings).toStrictEqual([
|
||||||
|
{
|
||||||
|
settingKey: "board",
|
||||||
|
value: stringify({
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test("saveSettings should update settings and return true when it updated only one", async () => {
|
test("saveSettings should update settings and return true when it updated only one", async () => {
|
||||||
const db = createDb();
|
const db = createDb();
|
||||||
const caller = serverSettingsRouter.createCaller({
|
const caller = serverSettingsRouter.createCaller({
|
||||||
@@ -89,6 +116,33 @@ describe("saveSettings", () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("saveSettings should preserve concurrent partial updates", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = serverSettingsRouter.createCaller({
|
||||||
|
db,
|
||||||
|
deviceType: undefined,
|
||||||
|
session: defaultSession,
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
caller.saveSettings({
|
||||||
|
settingsKey: "analytics",
|
||||||
|
value: { enableGeneral: false },
|
||||||
|
}),
|
||||||
|
caller.saveSettings({
|
||||||
|
settingsKey: "analytics",
|
||||||
|
value: { instanceId: "concurrent-instance" },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await expect(caller.getAll()).resolves.toMatchObject({
|
||||||
|
analytics: {
|
||||||
|
enableGeneral: false,
|
||||||
|
instanceId: "concurrent-instance",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("board settings API", () => {
|
describe("board settings API", () => {
|
||||||
@@ -103,6 +157,36 @@ describe("board settings API", () => {
|
|||||||
await expect(caller.getBoardSettings()).resolves.toStrictEqual(defaultServerSettings.board);
|
await expect(caller.getBoardSettings()).resolves.toStrictEqual(defaultServerSettings.board);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getBoardSettings should backfill the automatic layout default for legacy values", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = serverSettingsRouter.createCaller({
|
||||||
|
db,
|
||||||
|
deviceType: undefined,
|
||||||
|
session: defaultSession,
|
||||||
|
});
|
||||||
|
const boardId = createId();
|
||||||
|
await db.insert(boards).values({ id: boardId, name: "legacy", isPublic: false });
|
||||||
|
await db.insert(layouts).values([
|
||||||
|
{ id: createId(), boardId, name: "Base", columnCount: 12, breakpoint: 0 },
|
||||||
|
{ id: createId(), boardId, name: "Mobile", columnCount: 4, breakpoint: 480 },
|
||||||
|
]);
|
||||||
|
const legacyBoardSettings = {
|
||||||
|
homeBoardId: defaultServerSettings.board.homeBoardId,
|
||||||
|
mobileHomeBoardId: defaultServerSettings.board.mobileHomeBoardId,
|
||||||
|
enableStatusByDefault: defaultServerSettings.board.enableStatusByDefault,
|
||||||
|
forceDisableStatus: defaultServerSettings.board.forceDisableStatus,
|
||||||
|
};
|
||||||
|
await db.insert(serverSettings).values({
|
||||||
|
settingKey: "board",
|
||||||
|
value: stringify(legacyBoardSettings),
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(caller.getBoardSettings()).resolves.toStrictEqual({
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("updateBoardSettings should insert settings when defaults are not persisted", async () => {
|
test("updateBoardSettings should insert settings when defaults are not persisted", async () => {
|
||||||
const db = createDb();
|
const db = createDb();
|
||||||
const caller = serverSettingsRouter.createCaller({
|
const caller = serverSettingsRouter.createCaller({
|
||||||
@@ -145,6 +229,7 @@ describe("board settings API", () => {
|
|||||||
await caller.updateBoardSettings({ homeBoardId: boardId });
|
await caller.updateBoardSettings({ homeBoardId: boardId });
|
||||||
const result = await caller.updateBoardSettings({
|
const result = await caller.updateBoardSettings({
|
||||||
mobileHomeBoardId: boardId,
|
mobileHomeBoardId: boardId,
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
enableStatusByDefault: false,
|
enableStatusByDefault: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -152,6 +237,7 @@ describe("board settings API", () => {
|
|||||||
...defaultServerSettings.board,
|
...defaultServerSettings.board,
|
||||||
homeBoardId: boardId,
|
homeBoardId: boardId,
|
||||||
mobileHomeBoardId: boardId,
|
mobileHomeBoardId: boardId,
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
enableStatusByDefault: false,
|
enableStatusByDefault: false,
|
||||||
});
|
});
|
||||||
const dbSettings = await db.select().from(serverSettings);
|
const dbSettings = await db.select().from(serverSettings);
|
||||||
@@ -163,6 +249,25 @@ describe("board settings API", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("updateBoardSettings should preserve concurrent partial updates", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const caller = serverSettingsRouter.createCaller({
|
||||||
|
db,
|
||||||
|
deviceType: undefined,
|
||||||
|
session: defaultSession,
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
caller.updateBoardSettings({ forceDisableStatus: true }),
|
||||||
|
caller.updateBoardSettings({ enableStatusByDefault: false }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await expect(caller.getBoardSettings()).resolves.toMatchObject({
|
||||||
|
forceDisableStatus: true,
|
||||||
|
enableStatusByDefault: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("updateBoardSettings should reject private home boards", async () => {
|
test("updateBoardSettings should reject private home boards", async () => {
|
||||||
const db = createDb();
|
const db = createDb();
|
||||||
const caller = serverSettingsRouter.createCaller({
|
const caller = serverSettingsRouter.createCaller({
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ test("MCP tools should contain expected procedures", () => {
|
|||||||
expect(toolNames).toContain("app_byId");
|
expect(toolNames).toContain("app_byId");
|
||||||
expect(toolNames).toContain("app_create");
|
expect(toolNames).toContain("app_create");
|
||||||
expect(toolNames).toContain("board_savePartialBoardSettings");
|
expect(toolNames).toContain("board_savePartialBoardSettings");
|
||||||
|
expect(toolNames).toContain("board_saveLayout");
|
||||||
expect(toolNames).toContain("board_duplicateBoard");
|
expect(toolNames).toContain("board_duplicateBoard");
|
||||||
expect(toolNames).toContain("info_getInfo");
|
expect(toolNames).toContain("info_getInfo");
|
||||||
expect(toolNames).toContain("invite_getAll");
|
expect(toolNames).toContain("invite_getAll");
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@homarr/api": "workspace:^0.1.0",
|
"@homarr/api": "workspace:^0.1.0",
|
||||||
|
"@homarr/settings": "workspace:^0.1.0",
|
||||||
"react": "catalog:",
|
"react": "catalog:",
|
||||||
"react-dom": "catalog:"
|
"react-dom": "catalog:"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
|
|
||||||
|
import { getBoardLayouts, getCurrentLayout, getDesktopLayout } from "./context";
|
||||||
|
|
||||||
|
const createBoard = () =>
|
||||||
|
({
|
||||||
|
layouts: [
|
||||||
|
{ id: "small", name: "Small", columnCount: 4, breakpoint: 0 },
|
||||||
|
{ id: "medium", name: "Medium", columnCount: 8, breakpoint: 768 },
|
||||||
|
{ id: "large", name: "Large", columnCount: 12, breakpoint: 1200 },
|
||||||
|
],
|
||||||
|
}) as RouterOutputs["board"]["getBoardByName"];
|
||||||
|
|
||||||
|
describe("board layout selection", () => {
|
||||||
|
test("automatic mode always uses the desktop layout", () => {
|
||||||
|
const board = createBoard();
|
||||||
|
|
||||||
|
expect(getDesktopLayout(board).id).toBe("large");
|
||||||
|
expect(getCurrentLayout(board, true, 390)).toBe("large");
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
[390, "small"],
|
||||||
|
[768, "medium"],
|
||||||
|
[1024, "medium"],
|
||||||
|
[1440, "large"],
|
||||||
|
])("legacy mode selects the matching responsive layout at %spx", (viewportWidth, expectedLayoutId) => {
|
||||||
|
expect(getCurrentLayout(createBoard(), false, viewportWidth)).toBe(expectedLayoutId);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("legacy mode falls back to the desktop layout before the client viewport is known", () => {
|
||||||
|
expect(getCurrentLayout(createBoard(), false, undefined)).toBe("large");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("rejects boards without a layout", () => {
|
||||||
|
const board = { ...createBoard(), layouts: [] };
|
||||||
|
|
||||||
|
expect(() => getDesktopLayout(board)).toThrow("Board must have a layout");
|
||||||
|
expect(() => getCurrentLayout(board, false, 390)).toThrow("Board must have a layout");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps every saved layout available for reversible mutations", () => {
|
||||||
|
expect(getBoardLayouts(createBoard())).toEqual(["small", "medium", "large"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import { createContext, useContext, useEffect } from "react";
|
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { getActiveQueryCacheBoardId, setActiveQueryCacheBoardId } from "@homarr/api/query-cache";
|
import { getActiveQueryCacheBoardId, setActiveQueryCacheBoardId } from "@homarr/api/query-cache";
|
||||||
|
import { useSettings } from "@homarr/settings";
|
||||||
|
|
||||||
import { updateBoardName } from "./updater";
|
import { updateBoardName } from "./updater";
|
||||||
|
|
||||||
@@ -73,10 +74,6 @@ export const useOptionalBoard = () => {
|
|||||||
return context?.board ?? null;
|
return context?.board ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCurrentLayout = (board: RouterOutputs["board"]["getBoardByName"]) => {
|
|
||||||
return getDesktopLayout(board).id;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDesktopLayout = (board: RouterOutputs["board"]["getBoardByName"]) => {
|
export const getDesktopLayout = (board: RouterOutputs["board"]["getBoardByName"]) => {
|
||||||
const layout = board.layouts
|
const layout = board.layouts
|
||||||
.toSorted(
|
.toSorted(
|
||||||
@@ -91,9 +88,57 @@ export const getDesktopLayout = (board: RouterOutputs["board"]["getBoardByName"]
|
|||||||
return layout;
|
return layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCurrentLayout = () => getCurrentLayout(useRequiredBoard());
|
export const getCurrentLayout = (
|
||||||
|
board: RouterOutputs["board"]["getBoardByName"],
|
||||||
|
enableAutomaticMobileLayout: boolean,
|
||||||
|
viewportWidth?: number,
|
||||||
|
) => {
|
||||||
|
if (enableAutomaticMobileLayout || viewportWidth === undefined) {
|
||||||
|
return getDesktopLayout(board).id;
|
||||||
|
}
|
||||||
|
|
||||||
export const getBoardLayouts = (board: RouterOutputs["board"]["getBoardByName"]) => [getCurrentLayout(board)];
|
const sortedLayouts = board.layouts.toSorted((layoutA, layoutB) => layoutB.breakpoint - layoutA.breakpoint);
|
||||||
|
const layout = sortedLayouts.find((candidate) => candidate.breakpoint <= viewportWidth) ?? sortedLayouts.at(-1);
|
||||||
|
|
||||||
|
if (!layout) {
|
||||||
|
throw new Error("Board must have a layout");
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCurrentLayout = () => {
|
||||||
|
const board = useRequiredBoard();
|
||||||
|
const { enableAutomaticMobileLayout } = useSettings();
|
||||||
|
const [currentLayout, setCurrentLayout] = useState(() =>
|
||||||
|
getCurrentLayout(
|
||||||
|
board,
|
||||||
|
enableAutomaticMobileLayout,
|
||||||
|
!enableAutomaticMobileLayout && typeof window !== "undefined" ? window.innerWidth : undefined,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateCurrentLayout = useCallback(() => {
|
||||||
|
setCurrentLayout(getCurrentLayout(board, enableAutomaticMobileLayout, window.innerWidth));
|
||||||
|
}, [board, enableAutomaticMobileLayout]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
updateCurrentLayout();
|
||||||
|
|
||||||
|
if (enableAutomaticMobileLayout) return;
|
||||||
|
|
||||||
|
window.addEventListener("resize", updateCurrentLayout);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("resize", updateCurrentLayout);
|
||||||
|
};
|
||||||
|
}, [enableAutomaticMobileLayout, updateCurrentLayout]);
|
||||||
|
|
||||||
|
return currentLayout;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBoardLayouts = (board: RouterOutputs["board"]["getBoardByName"]) =>
|
||||||
|
board.layouts.map((layout) => layout.id);
|
||||||
|
|
||||||
export const useLayouts = () => {
|
export const useLayouts = () => {
|
||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { objectEntries } from "@homarr/common";
|
|||||||
import { dbEnv } from "@homarr/core/infrastructure/db/env";
|
import { dbEnv } from "@homarr/core/infrastructure/db/env";
|
||||||
|
|
||||||
import type { HomarrDatabase, HomarrDatabaseMysql, HomarrDatabasePostgresql } from "./driver";
|
import type { HomarrDatabase, HomarrDatabaseMysql, HomarrDatabasePostgresql } from "./driver";
|
||||||
import * as schema from "./schema";
|
import { schema } from "./schema";
|
||||||
|
|
||||||
type TableKey = {
|
type TableKey = {
|
||||||
[K in keyof typeof schema]: (typeof schema)[K] extends { _: { brand: "Table" } } ? K : never;
|
[K in keyof typeof schema]: (typeof schema)[K] extends { _: { brand: "Table" } } ? K : never;
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import { stringify } from "superjson";
|
||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { createId } from "@homarr/common";
|
||||||
|
import { eq } from "@homarr/db";
|
||||||
|
import {
|
||||||
|
getServerSettingByKeyAsync,
|
||||||
|
getServerSettingsAsync,
|
||||||
|
shouldEnableAutomaticMobileLayoutForUpgrade,
|
||||||
|
} from "@homarr/db/queries";
|
||||||
|
import { boards, layouts, serverSettings } from "@homarr/db/schema";
|
||||||
|
import { createDb } from "@homarr/db/test";
|
||||||
|
import { defaultServerSettings } from "@homarr/server-settings";
|
||||||
|
|
||||||
|
import { seedServerSettingsAsync } from "./seed";
|
||||||
|
|
||||||
|
describe("automatic mobile layout upgrade default", () => {
|
||||||
|
test("enables automatic mode for a new instance", () => {
|
||||||
|
expect(shouldEnableAutomaticMobileLayoutForUpgrade([])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("enables automatic mode when every existing board has only its canonical layout", () => {
|
||||||
|
expect(
|
||||||
|
shouldEnableAutomaticMobileLayoutForUpgrade([
|
||||||
|
{ boardId: "first", name: "Base", breakpoint: 0 },
|
||||||
|
{ boardId: "second", name: "Base", breakpoint: 0 },
|
||||||
|
]),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("preserves legacy mode when a board has multiple responsive layouts", () => {
|
||||||
|
expect(
|
||||||
|
shouldEnableAutomaticMobileLayoutForUpgrade([
|
||||||
|
{ boardId: "board", name: "Base", breakpoint: 0 },
|
||||||
|
{ boardId: "board", name: "Mobile", breakpoint: 480 },
|
||||||
|
]),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("preserves legacy mode when a board has duplicate canonical layouts", () => {
|
||||||
|
expect(
|
||||||
|
shouldEnableAutomaticMobileLayoutForUpgrade([
|
||||||
|
{ boardId: "board", name: "Base", breakpoint: 0 },
|
||||||
|
{ boardId: "board", name: "Base", breakpoint: 0 },
|
||||||
|
]),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
{ boardId: "board", name: "Phone", breakpoint: 0 },
|
||||||
|
{ boardId: "board", name: "Base", breakpoint: 480 },
|
||||||
|
])("preserves legacy mode for a noncanonical saved layout", (existingLayout) => {
|
||||||
|
expect(shouldEnableAutomaticMobileLayoutForUpgrade([existingLayout])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("uses the upgrade heuristic when migrations and seeding are skipped", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const boardId = createId();
|
||||||
|
await db.insert(boards).values({ id: boardId, name: "dashboard", isPublic: false });
|
||||||
|
await db.insert(layouts).values([
|
||||||
|
{ id: createId(), boardId, name: "Base", columnCount: 12, breakpoint: 0 },
|
||||||
|
{ id: createId(), boardId, name: "Phone", columnCount: 4, breakpoint: 480 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
await expect(getServerSettingByKeyAsync(db, "board")).resolves.toMatchObject({
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
});
|
||||||
|
await expect(getServerSettingsAsync(db)).resolves.toMatchObject({
|
||||||
|
board: {
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("backfills legacy responsive instances once without overriding an explicit choice", async () => {
|
||||||
|
const db = createDb();
|
||||||
|
const boardId = createId();
|
||||||
|
await db.insert(boards).values({ id: boardId, name: "dashboard", isPublic: false });
|
||||||
|
await db.insert(layouts).values([
|
||||||
|
{ id: createId(), boardId, name: "Base", columnCount: 12, breakpoint: 0 },
|
||||||
|
{ id: createId(), boardId, name: "Phone", columnCount: 4, breakpoint: 480 },
|
||||||
|
]);
|
||||||
|
await db.insert(serverSettings).values({
|
||||||
|
settingKey: "board",
|
||||||
|
value: stringify({
|
||||||
|
homeBoardId: null,
|
||||||
|
mobileHomeBoardId: null,
|
||||||
|
enableStatusByDefault: true,
|
||||||
|
forceDisableStatus: false,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
await seedServerSettingsAsync(db);
|
||||||
|
await seedServerSettingsAsync(db);
|
||||||
|
|
||||||
|
await expect(getServerSettingByKeyAsync(db, "board")).resolves.toStrictEqual({
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
await db
|
||||||
|
.update(serverSettings)
|
||||||
|
.set({
|
||||||
|
value: stringify({
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: true,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.where(eq(serverSettings.settingKey, "board"));
|
||||||
|
|
||||||
|
await seedServerSettingsAsync(db);
|
||||||
|
|
||||||
|
await expect(getServerSettingByKeyAsync(db, "board")).resolves.toStrictEqual(defaultServerSettings.board);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -21,6 +21,7 @@ import { getMaxGroupPositionAsync, placeAllWidgetsAsync } from "../queries";
|
|||||||
import {
|
import {
|
||||||
getServerSettingByKeyAsync,
|
getServerSettingByKeyAsync,
|
||||||
insertServerSettingByKeyAsync,
|
insertServerSettingByKeyAsync,
|
||||||
|
shouldEnableAutomaticMobileLayoutForUpgrade,
|
||||||
updateServerSettingByKeyAsync,
|
updateServerSettingByKeyAsync,
|
||||||
} from "../queries/server-setting";
|
} from "../queries/server-setting";
|
||||||
|
|
||||||
@@ -245,19 +246,33 @@ const seedDefaultSearchEnginesAsync = async (db: Database) => {
|
|||||||
console.log("Set Homarr docs as the default search engine");
|
console.log("Set Homarr docs as the default search engine");
|
||||||
};
|
};
|
||||||
|
|
||||||
const seedServerSettingsAsync = async (db: Database) => {
|
export const seedServerSettingsAsync = async (db: Database) => {
|
||||||
const serverSettingsData = await db.query.serverSettings.findMany();
|
const serverSettingsData = await db.query.serverSettings.findMany();
|
||||||
|
const existingLayouts = await db.query.layouts.findMany({
|
||||||
|
columns: {
|
||||||
|
boardId: true,
|
||||||
|
name: true,
|
||||||
|
breakpoint: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const defaultsForThisInstance = {
|
||||||
|
...defaultServerSettings,
|
||||||
|
board: {
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: shouldEnableAutomaticMobileLayoutForUpgrade(existingLayouts),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
for (const settingsKey of defaultServerSettingsKeys) {
|
for (const settingsKey of defaultServerSettingsKeys) {
|
||||||
const currentDbEntry = serverSettingsData.find((setting) => setting.settingKey === settingsKey);
|
const currentDbEntry = serverSettingsData.find((setting) => setting.settingKey === settingsKey);
|
||||||
if (!currentDbEntry) {
|
if (!currentDbEntry) {
|
||||||
await insertServerSettingByKeyAsync(db, settingsKey, defaultServerSettings[settingsKey]);
|
await insertServerSettingByKeyAsync(db, settingsKey, defaultsForThisInstance[settingsKey]);
|
||||||
console.log(`Created serverSetting through seed key=${settingsKey}`);
|
console.log(`Created serverSetting through seed key=${settingsKey}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentSettings = await getServerSettingByKeyAsync(db, settingsKey);
|
const currentSettings = SuperJSON.parse<(typeof defaultServerSettings)[typeof settingsKey]>(currentDbEntry.value);
|
||||||
const defaultSettings = defaultServerSettings[settingsKey];
|
const defaultSettings = defaultsForThisInstance[settingsKey];
|
||||||
const missingKeys = objectKeys(defaultSettings).filter((key) => !(key in currentSettings));
|
const missingKeys = objectKeys(defaultSettings).filter((key) => !(key in currentSettings));
|
||||||
|
|
||||||
if (missingKeys.length === 0) {
|
if (missingKeys.length === 0) {
|
||||||
|
|||||||
@@ -1,29 +1,80 @@
|
|||||||
import SuperJSON from "superjson";
|
import { parse, stringify } from "superjson";
|
||||||
|
|
||||||
import type { ServerSettings } from "@homarr/server-settings";
|
import type { ServerSettings } from "@homarr/server-settings";
|
||||||
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
|
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
|
||||||
|
|
||||||
import type { Database } from "..";
|
import type { Database } from "..";
|
||||||
import { eq } from "..";
|
import { eq, sql } from "..";
|
||||||
|
import { isMysql, isPostgresql } from "../collection";
|
||||||
|
import type { HomarrDatabaseMysql, HomarrDatabasePostgresql } from "../driver";
|
||||||
import { serverSettings } from "../schema";
|
import { serverSettings } from "../schema";
|
||||||
|
import { serverSettings as mysqlServerSettings } from "../schema/mysql";
|
||||||
|
import { serverSettings as postgresqlServerSettings } from "../schema/postgresql";
|
||||||
|
|
||||||
|
interface ExistingBoardLayout {
|
||||||
|
boardId: string;
|
||||||
|
name: string;
|
||||||
|
breakpoint: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const shouldEnableAutomaticMobileLayoutForUpgrade = (existingLayouts: ExistingBoardLayout[]) => {
|
||||||
|
const layoutCounts = new Map<string, number>();
|
||||||
|
|
||||||
|
for (const layout of existingLayouts) {
|
||||||
|
if (layout.name !== "Base" || layout.breakpoint !== 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextCount = (layoutCounts.get(layout.boardId) ?? 0) + 1;
|
||||||
|
if (nextCount > 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
layoutCounts.set(layout.boardId, nextCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAutomaticMobileLayoutUpgradeDefaultAsync = async (db: Database) => {
|
||||||
|
const existingLayouts = await db.query.layouts.findMany({
|
||||||
|
columns: {
|
||||||
|
boardId: true,
|
||||||
|
name: true,
|
||||||
|
breakpoint: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return shouldEnableAutomaticMobileLayoutForUpgrade(existingLayouts);
|
||||||
|
};
|
||||||
|
|
||||||
export const getServerSettingsAsync = async (db: Database) => {
|
export const getServerSettingsAsync = async (db: Database) => {
|
||||||
const settings = await db.query.serverSettings.findMany();
|
const settings = await db.query.serverSettings.findMany();
|
||||||
|
let parsedBoardSettings: Partial<ServerSettings["board"]> = {};
|
||||||
|
|
||||||
return defaultServerSettingsKeys.reduce((acc, settingKey) => {
|
const mergedSettings = defaultServerSettingsKeys.reduce((acc, settingKey) => {
|
||||||
const setting = settings.find((setting) => setting.settingKey === settingKey);
|
const setting = settings.find((candidate) => candidate.settingKey === settingKey);
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
// Typescript is not happy because the key is a union and it does not know that they are the same
|
// Typescript is not happy because the key is a union and it does not know that they are the same
|
||||||
acc[settingKey] = defaultServerSettings[settingKey] as never;
|
acc[settingKey] = { ...defaultServerSettings[settingKey] } as never;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const persistedSettings = parse<Record<string, unknown>>(setting.value);
|
||||||
|
if (settingKey === "board") {
|
||||||
|
parsedBoardSettings = persistedSettings as Partial<ServerSettings["board"]>;
|
||||||
|
}
|
||||||
acc[settingKey] = {
|
acc[settingKey] = {
|
||||||
...defaultServerSettings[settingKey],
|
...defaultServerSettings[settingKey],
|
||||||
...SuperJSON.parse(setting.value),
|
...persistedSettings,
|
||||||
};
|
} as never;
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as ServerSettings);
|
}, {} as ServerSettings);
|
||||||
|
|
||||||
|
if (typeof parsedBoardSettings.enableAutomaticMobileLayout !== "boolean") {
|
||||||
|
mergedSettings.board.enableAutomaticMobileLayout = await getAutomaticMobileLayoutUpgradeDefaultAsync(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergedSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(db: Database, key: TKey) => {
|
export const getServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(db: Database, key: TKey) => {
|
||||||
@@ -32,10 +83,31 @@ export const getServerSettingByKeyAsync = async <TKey extends keyof ServerSettin
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!dbSettings) {
|
if (!dbSettings) {
|
||||||
|
if (key === "board") {
|
||||||
|
return {
|
||||||
|
...defaultServerSettings.board,
|
||||||
|
enableAutomaticMobileLayout: await getAutomaticMobileLayoutUpgradeDefaultAsync(db),
|
||||||
|
} as ServerSettings[TKey];
|
||||||
|
}
|
||||||
|
|
||||||
return defaultServerSettings[key];
|
return defaultServerSettings[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
return SuperJSON.parse<ServerSettings[TKey]>(dbSettings.value);
|
const persistedSettings = parse<Partial<ServerSettings[TKey]>>(dbSettings.value);
|
||||||
|
const mergedSettings = {
|
||||||
|
...defaultServerSettings[key],
|
||||||
|
...persistedSettings,
|
||||||
|
} as ServerSettings[TKey];
|
||||||
|
|
||||||
|
if (
|
||||||
|
key === "board" &&
|
||||||
|
typeof (persistedSettings as Partial<ServerSettings["board"]>).enableAutomaticMobileLayout !== "boolean"
|
||||||
|
) {
|
||||||
|
(mergedSettings as ServerSettings["board"]).enableAutomaticMobileLayout =
|
||||||
|
await getAutomaticMobileLayoutUpgradeDefaultAsync(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergedSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(
|
export const updateServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(
|
||||||
@@ -46,7 +118,7 @@ export const updateServerSettingByKeyAsync = async <TKey extends keyof ServerSet
|
|||||||
await db
|
await db
|
||||||
.update(serverSettings)
|
.update(serverSettings)
|
||||||
.set({
|
.set({
|
||||||
value: SuperJSON.stringify(value),
|
value: stringify(value),
|
||||||
})
|
})
|
||||||
.where(eq(serverSettings.settingKey, key));
|
.where(eq(serverSettings.settingKey, key));
|
||||||
};
|
};
|
||||||
@@ -58,6 +130,56 @@ export const insertServerSettingByKeyAsync = async <TKey extends keyof ServerSet
|
|||||||
) => {
|
) => {
|
||||||
await db.insert(serverSettings).values({
|
await db.insert(serverSettings).values({
|
||||||
settingKey: key,
|
settingKey: key,
|
||||||
value: SuperJSON.stringify(value),
|
value: stringify(value),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const mergeServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(
|
||||||
|
db: Database,
|
||||||
|
key: TKey,
|
||||||
|
value: ServerSettings[TKey],
|
||||||
|
patch: Partial<ServerSettings[TKey]>,
|
||||||
|
) => {
|
||||||
|
const serializedValue = stringify(value);
|
||||||
|
const serializedPatch = stringify(patch);
|
||||||
|
|
||||||
|
if (isMysql()) {
|
||||||
|
await (db as unknown as HomarrDatabaseMysql)
|
||||||
|
.insert(mysqlServerSettings)
|
||||||
|
.values({ settingKey: key, value: serializedValue })
|
||||||
|
.onDuplicateKeyUpdate({
|
||||||
|
set: {
|
||||||
|
value: sql`JSON_MERGE_PATCH(${mysqlServerSettings.value}, ${serializedPatch})`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPostgresql()) {
|
||||||
|
await (db as unknown as HomarrDatabasePostgresql)
|
||||||
|
.insert(postgresqlServerSettings)
|
||||||
|
.values({ settingKey: key, value: serializedValue })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: postgresqlServerSettings.settingKey,
|
||||||
|
set: {
|
||||||
|
value: sql`jsonb_set(
|
||||||
|
${postgresqlServerSettings.value}::jsonb,
|
||||||
|
'{json}',
|
||||||
|
(${postgresqlServerSettings.value}::jsonb -> 'json') || (${serializedPatch}::jsonb -> 'json'),
|
||||||
|
true
|
||||||
|
)::text`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.insert(serverSettings)
|
||||||
|
.values({ settingKey: key, value: serializedValue })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: serverSettings.settingKey,
|
||||||
|
set: {
|
||||||
|
value: sql`json_patch(${serverSettings.value}, ${serializedPatch})`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -11,6 +11,9 @@ import * as mysqlSchema from "../schema/mysql";
|
|||||||
import * as postgresqlSchema from "../schema/postgresql";
|
import * as postgresqlSchema from "../schema/postgresql";
|
||||||
import * as sqliteSchema from "../schema/sqlite";
|
import * as sqliteSchema from "../schema/sqlite";
|
||||||
|
|
||||||
|
const mysqlTables = { ...mysqlSchema };
|
||||||
|
const postgresqlTables = { ...postgresqlSchema };
|
||||||
|
|
||||||
// We need the following three types as there is currently no support for Buffer in mysql & pg and
|
// We need the following three types as there is currently no support for Buffer in mysql & pg and
|
||||||
// so we use a custom type which results in the config beeing different
|
// so we use a custom type which results in the config beeing different
|
||||||
type FixedMysqlConfig = {
|
type FixedMysqlConfig = {
|
||||||
@@ -63,7 +66,7 @@ test("schemas should match", () => {
|
|||||||
if (!("uniqueName" in sqliteColumn)) return;
|
if (!("uniqueName" in sqliteColumn)) return;
|
||||||
if (!("primary" in sqliteColumn)) return;
|
if (!("primary" in sqliteColumn)) return;
|
||||||
|
|
||||||
const mysqlTable = mysqlSchema[tableName];
|
const mysqlTable = mysqlTables[tableName];
|
||||||
|
|
||||||
const mysqlColumn = mysqlTable[columnName as keyof typeof mysqlTable] as object;
|
const mysqlColumn = mysqlTable[columnName as keyof typeof mysqlTable] as object;
|
||||||
if (!("isUnique" in mysqlColumn)) return;
|
if (!("isUnique" in mysqlColumn)) return;
|
||||||
@@ -84,7 +87,7 @@ test("schemas should match", () => {
|
|||||||
).toEqual(mysqlColumn.primary);
|
).toEqual(mysqlColumn.primary);
|
||||||
});
|
});
|
||||||
|
|
||||||
const mysqlTable = mysqlSchema[tableName];
|
const mysqlTable = mysqlTables[tableName];
|
||||||
const sqliteForeignKeys = sqliteTable[Symbol.for("drizzle:SQLiteInlineForeignKeys") as keyof typeof sqliteTable] as
|
const sqliteForeignKeys = sqliteTable[Symbol.for("drizzle:SQLiteInlineForeignKeys") as keyof typeof sqliteTable] as
|
||||||
| SqliteForeignKey[]
|
| SqliteForeignKey[]
|
||||||
| undefined;
|
| undefined;
|
||||||
@@ -144,7 +147,7 @@ test("schemas should match for postgresql", () => {
|
|||||||
objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => {
|
objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => {
|
||||||
// keys of sqliteSchema and postgresqlSchema are the same, so we can safely use tableName as key
|
// keys of sqliteSchema and postgresqlSchema are the same, so we can safely use tableName as key
|
||||||
// skipcq: JS-E1007
|
// skipcq: JS-E1007
|
||||||
const postgresqlTable = postgresqlSchema[tableName];
|
const postgresqlTable = postgresqlTables[tableName];
|
||||||
Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => {
|
Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => {
|
||||||
if (!("isUnique" in sqliteColumn)) return;
|
if (!("isUnique" in sqliteColumn)) return;
|
||||||
if (!("uniqueName" in sqliteColumn)) return;
|
if (!("uniqueName" in sqliteColumn)) return;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export const defaultServerSettings = {
|
|||||||
board: {
|
board: {
|
||||||
homeBoardId: null as string | null,
|
homeBoardId: null as string | null,
|
||||||
mobileHomeBoardId: null as string | null,
|
mobileHomeBoardId: null as string | null,
|
||||||
|
enableAutomaticMobileLayout: true,
|
||||||
enableStatusByDefault: true,
|
enableStatusByDefault: true,
|
||||||
forceDisableStatus: false,
|
forceDisableStatus: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ export type SettingsContextProps = Pick<
|
|||||||
| "pingIconsEnabled"
|
| "pingIconsEnabled"
|
||||||
| "enableRightClickOnWidgets"
|
| "enableRightClickOnWidgets"
|
||||||
> &
|
> &
|
||||||
Pick<ServerSettings["board"], "enableStatusByDefault" | "forceDisableStatus"> &
|
Pick<ServerSettings["board"], "enableAutomaticMobileLayout" | "enableStatusByDefault" | "forceDisableStatus"> &
|
||||||
Pick<ServerSettings["user"], "enableGravatar">;
|
Pick<ServerSettings["user"], "enableGravatar">;
|
||||||
|
|
||||||
export interface PublicServerSettings {
|
export interface PublicServerSettings {
|
||||||
search: Pick<ServerSettings["search"], "defaultSearchEngineId">;
|
search: Pick<ServerSettings["search"], "defaultSearchEngineId">;
|
||||||
board: Pick<
|
board: Pick<
|
||||||
ServerSettings["board"],
|
ServerSettings["board"],
|
||||||
"homeBoardId" | "mobileHomeBoardId" | "enableStatusByDefault" | "forceDisableStatus"
|
"homeBoardId" | "mobileHomeBoardId" | "enableAutomaticMobileLayout" | "enableStatusByDefault" | "forceDisableStatus"
|
||||||
>;
|
>;
|
||||||
user: Pick<ServerSettings["user"], "enableGravatar">;
|
user: Pick<ServerSettings["user"], "enableGravatar">;
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,7 @@ export const createSettings = ({
|
|||||||
mobileHomeBoardId: user?.mobileHomeBoardId ?? serverSettings.board.mobileHomeBoardId,
|
mobileHomeBoardId: user?.mobileHomeBoardId ?? serverSettings.board.mobileHomeBoardId,
|
||||||
pingIconsEnabled: user?.pingIconsEnabled ?? false,
|
pingIconsEnabled: user?.pingIconsEnabled ?? false,
|
||||||
enableRightClickOnWidgets: user?.enableRightClickOnWidgets ?? true,
|
enableRightClickOnWidgets: user?.enableRightClickOnWidgets ?? true,
|
||||||
|
enableAutomaticMobileLayout: serverSettings.board.enableAutomaticMobileLayout,
|
||||||
enableStatusByDefault: serverSettings.board.enableStatusByDefault,
|
enableStatusByDefault: serverSettings.board.enableStatusByDefault,
|
||||||
forceDisableStatus: serverSettings.board.forceDisableStatus,
|
forceDisableStatus: serverSettings.board.forceDisableStatus,
|
||||||
enableGravatar: serverSettings.user.enableGravatar,
|
enableGravatar: serverSettings.user.enableGravatar,
|
||||||
|
|||||||
@@ -4391,7 +4391,15 @@
|
|||||||
"description": "Configure the layout used on desktop and larger screens."
|
"description": "Configure the layout used on desktop and larger screens."
|
||||||
},
|
},
|
||||||
"mobile": {
|
"mobile": {
|
||||||
"description": "On mobile, items are automatically arranged in two columns and cannot be moved or resized. Categories and dynamic sections are flattened into the item list."
|
"automaticDescription": "On mobile, the normal widgets are arranged in two columns and cannot be moved or resized. Categories and dynamic sections are flattened into the item list."
|
||||||
|
},
|
||||||
|
"responsive": {
|
||||||
|
"title": "Responsive layouts",
|
||||||
|
"description": "Automatic mobile layout is disabled for this server. Configure the saved layouts selected at each viewport breakpoint; these layouts can also be edited directly on mobile.",
|
||||||
|
"defaultName": "New layout",
|
||||||
|
"action": {
|
||||||
|
"add": "Add layout"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
@@ -4841,6 +4849,13 @@
|
|||||||
"mobileLabel": "Global mobile board",
|
"mobileLabel": "Global mobile board",
|
||||||
"description": "Only public boards are available for selection"
|
"description": "Only public boards are available for selection"
|
||||||
},
|
},
|
||||||
|
"mobileLayout": {
|
||||||
|
"title": "Mobile layout",
|
||||||
|
"enable": {
|
||||||
|
"label": "Use automatic mobile layout",
|
||||||
|
"description": "Squeeze every board into a read-only two-column grid on phones and small tablets without changing widget content. Turn this off to use saved responsive layouts and mobile layout editing. Saved layouts are kept while automatic mode is enabled."
|
||||||
|
}
|
||||||
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"title": "App status",
|
"title": "App status",
|
||||||
"enableStatusByDefault": {
|
"enableStatusByDefault": {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const boardNameSchema = z
|
|||||||
.min(1)
|
.min(1)
|
||||||
.max(255)
|
.max(255)
|
||||||
.regex(/^[A-Za-z0-9-_]*$/);
|
.regex(/^[A-Za-z0-9-_]*$/);
|
||||||
export const boardColumnCountSchema = z.number().min(1).max(24);
|
export const boardColumnCountSchema = z.number().int().min(1).max(24);
|
||||||
|
|
||||||
export const boardByNameSchema = z.object({
|
export const boardByNameSchema = z.object({
|
||||||
name: boardNameSchema,
|
name: boardNameSchema,
|
||||||
@@ -75,6 +75,46 @@ export const boardSaveLayoutSchema = z.object({
|
|||||||
columnCount: boardColumnCountSchema,
|
columnCount: boardColumnCountSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const responsiveBoardLayoutsSchema = z
|
||||||
|
.array(
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
name: z.string().trim().nonempty().max(32),
|
||||||
|
columnCount: boardColumnCountSchema,
|
||||||
|
breakpoint: z.number().int().min(0).max(32767),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.min(1)
|
||||||
|
.superRefine((layouts, context) => {
|
||||||
|
const seenBreakpoints = new Set<number>();
|
||||||
|
const seenIds = new Set<string>();
|
||||||
|
|
||||||
|
layouts.forEach((layout, index) => {
|
||||||
|
if (seenIds.has(layout.id)) {
|
||||||
|
context.addIssue({
|
||||||
|
code: "custom",
|
||||||
|
message: "Each responsive layout must have a unique ID",
|
||||||
|
path: [index, "id"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
seenIds.add(layout.id);
|
||||||
|
|
||||||
|
if (seenBreakpoints.has(layout.breakpoint)) {
|
||||||
|
context.addIssue({
|
||||||
|
code: "custom",
|
||||||
|
message: "Each responsive layout must have a unique breakpoint",
|
||||||
|
path: [index, "breakpoint"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
seenBreakpoints.add(layout.breakpoint);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export const boardSaveLayoutsSchema = z.object({
|
||||||
|
id: z.string(),
|
||||||
|
layouts: responsiveBoardLayoutsSchema,
|
||||||
|
});
|
||||||
|
|
||||||
export const boardSaveSchema = z.object({
|
export const boardSaveSchema = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
sections: z.array(sectionSchema),
|
sections: z.array(sectionSchema),
|
||||||
|
|||||||
Generated
+3
@@ -1427,6 +1427,9 @@ importers:
|
|||||||
'@homarr/api':
|
'@homarr/api':
|
||||||
specifier: workspace:^0.1.0
|
specifier: workspace:^0.1.0
|
||||||
version: link:../api
|
version: link:../api
|
||||||
|
'@homarr/settings':
|
||||||
|
specifier: workspace:^0.1.0
|
||||||
|
version: link:../settings
|
||||||
react:
|
react:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 19.2.7
|
version: 19.2.7
|
||||||
|
|||||||
Reference in new issue
Block a user