mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
feat(maps): start new installations with MapLibre Liberty
This commit is contained in:
@@ -31,7 +31,7 @@ test('#1432 iPad: the places list scrolls under a swipe', async ({ page }) => {
|
||||
|
||||
await page.getByText(title).first().click()
|
||||
await expect(page).toHaveURL(/\/trips\/\d+/)
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 })
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({ timeout: 20_000 })
|
||||
|
||||
const tripId = page.url().match(/\/trips\/(\d+)/)![1]
|
||||
|
||||
@@ -43,7 +43,7 @@ test('#1432 iPad: the places list scrolls under a swipe', async ({ page }) => {
|
||||
expect(res.ok(), `seed place ${i}`).toBeTruthy()
|
||||
}
|
||||
await page.reload()
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 })
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({ timeout: 20_000 })
|
||||
|
||||
// An iPad is inside the 768-1023px band, where only one side panel is open at a
|
||||
// time so the map keeps a usable width (#2247). The places list is one tap away.
|
||||
@@ -88,7 +88,7 @@ test('#1432 iPad: the places list scrolls under a swipe', async ({ page }) => {
|
||||
// 3. The iPad must still get the desktop shell — isMobile stayed width-based. One
|
||||
// panel at a time (#2247), so opening Places closed the day plan and left its
|
||||
// tab as the way back.
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible()
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible()
|
||||
// The top tab bar has a button named Plan as well; the way back is the panel's
|
||||
// own tab, which is accented while its panel is closed.
|
||||
await expect(page.locator('button[aria-label="Plan"].bg-accent')).toBeVisible()
|
||||
|
||||
@@ -22,7 +22,7 @@ test('desktop: reorder arrows are hidden-and-inert until the row is hovered', as
|
||||
|
||||
await page.getByText(title).first().click()
|
||||
await expect(page).toHaveURL(/\/trips\/\d+/)
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 })
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({ timeout: 20_000 })
|
||||
|
||||
// Two places on day 1, so the day plan renders rows carrying reorder arrows.
|
||||
const tripId = page.url().match(/\/trips\/(\d+)/)![1]
|
||||
@@ -38,7 +38,7 @@ test('desktop: reorder arrows are hidden-and-inert until the row is hovered', as
|
||||
})
|
||||
}
|
||||
await page.reload()
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 })
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({ timeout: 20_000 })
|
||||
|
||||
const row = page.locator('.dp-row').filter({ hasText: 'Alpha' }).first()
|
||||
await expect(row).toBeVisible({ timeout: 20_000 })
|
||||
|
||||
@@ -58,7 +58,9 @@ test('desktop: a stay booked in another session shows in the day plan without a
|
||||
const hotel = `Mercure Hotel ${Date.now()}`;
|
||||
const { tripId, dayIds } = await seedTrip(page.request, `Stay live ${Date.now()}`);
|
||||
await openPlanner(page, tripId);
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 });
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({
|
||||
timeout: 20_000,
|
||||
});
|
||||
|
||||
await bookElsewhere(browser, tripId, dayIds, hotel);
|
||||
|
||||
|
||||
@@ -24,6 +24,6 @@ test('open a trip and land in the planner with a map', async ({ page }) => {
|
||||
await page.getByText(title).first().click()
|
||||
|
||||
await expect(page).toHaveURL(/\/trips\/\d+/)
|
||||
// The planner shows a Leaflet map once mounted (past the splash screen).
|
||||
await expect(page.locator('.leaflet-container')).toBeVisible({ timeout: 20_000 })
|
||||
// The planner shows its configured map once mounted.
|
||||
await expect(page.locator('.leaflet-container, .maplibregl-canvas, .mapboxgl-canvas').first()).toBeVisible({ timeout: 20_000 })
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { AddonSeeder } from './AddonSeeder';
|
||||
import { AdminSeeder } from './AdminSeeder';
|
||||
import { CategorySeeder } from './CategorySeeder';
|
||||
import { DocumentProviderSeeder } from './DocumentProviderSeeder';
|
||||
import { MapDefaultsSeeder } from './MapDefaultsSeeder';
|
||||
import { PhotoProviderSeeder } from './PhotoProviderSeeder';
|
||||
import { SchemaVersionSeeder } from './SchemaVersionSeeder';
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
@@ -10,13 +11,13 @@ import { Seeder } from '@mikro-orm/seeder';
|
||||
/**
|
||||
* The default seeder, replacing `db/seeds.ts::runSeeds()`.
|
||||
*
|
||||
* Order matters in one place only: `AdminSeeder` runs first because it is the
|
||||
* one that keys off an empty `users` table, and the provider seeders run after
|
||||
* `AddonSeeder` so the shelf exists before anything hangs off it.
|
||||
* Map defaults are set before the first admin is created. The provider seeders
|
||||
* run after `AddonSeeder` so their addon already exists.
|
||||
*/
|
||||
export class DatabaseSeeder extends Seeder {
|
||||
async run(em: EntityManager): Promise<void> {
|
||||
await this.call(em, [
|
||||
MapDefaultsSeeder,
|
||||
AdminSeeder,
|
||||
CategorySeeder,
|
||||
AddonSeeder,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { DB } from '../kysely/db';
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { Seeder } from '@mikro-orm/seeder';
|
||||
import type { SqlEntityManager } from '@mikro-orm/sql';
|
||||
import { OPENFREEMAP_DEFAULT_STYLE } from '@trek/shared';
|
||||
|
||||
const PROVIDER = 'default_user_setting_map_provider';
|
||||
const STYLE = 'default_user_setting_maplibre_style';
|
||||
|
||||
/** Give a new installation a starting basemap before its first user is created. */
|
||||
export class MapDefaultsSeeder extends Seeder {
|
||||
async run(em: EntityManager): Promise<void> {
|
||||
await em.transactional(async (tx) => {
|
||||
const db = (tx as SqlEntityManager).getKysely<Pick<DB, 'app_settings' | 'schema_version' | 'users'>>();
|
||||
// SchemaVersionSeeder writes this marker after the first bootstrap even on
|
||||
// SSO-only installations that are still waiting for their first account.
|
||||
const initialized = await db.selectFrom('schema_version').select('id').limit(1).executeTakeFirst();
|
||||
if (initialized) return;
|
||||
const user = await db.selectFrom('users').select('id').limit(1).executeTakeFirst();
|
||||
if (user) return;
|
||||
|
||||
const provider = await db
|
||||
.insertInto('app_settings')
|
||||
.values({ key: PROVIDER, value: JSON.stringify('maplibre-gl') })
|
||||
.onConflict((conflict) => conflict.column('key').doNothing())
|
||||
.returning('key')
|
||||
.executeTakeFirst();
|
||||
if (!provider) return;
|
||||
await db
|
||||
.insertInto('app_settings')
|
||||
.values({ key: STYLE, value: JSON.stringify(OPENFREEMAP_DEFAULT_STYLE) })
|
||||
.onConflict((conflict) => conflict.column('key').doNothing())
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,10 @@ async function main(): Promise<void> {
|
||||
fs.rmSync(schemaSnapshotPath(), { force: true });
|
||||
|
||||
const { getRawConnection } = await import('../src/db/database');
|
||||
const { AppSettings } = await import('../src/db/entities/AppSettings.entity');
|
||||
const { runSchemaBootstrap } = await import('../src/db/orm');
|
||||
const { createStandaloneOrm } = await import('../src/db/standalone-orm');
|
||||
const { deleteRows } = await import('./helpers/factories/rows');
|
||||
|
||||
// The shared driver binds to the connection database.ts opens on the ORM's
|
||||
// first connect, so this migrates that in-memory database and it can be
|
||||
@@ -27,6 +29,10 @@ async function main(): Promise<void> {
|
||||
const orm = await createStandaloneOrm();
|
||||
try {
|
||||
await runSchemaBootstrap(orm, { snapshot: true });
|
||||
// Suites using the historical snapshot opt into admin defaults themselves.
|
||||
await deleteRows(orm, AppSettings, {
|
||||
key: { $in: ['default_user_setting_map_provider', 'default_user_setting_maplibre_style'] },
|
||||
});
|
||||
writeSchemaSnapshot(getRawConnection().serialize());
|
||||
console.log(`[test-db] schema snapshot written to ${schemaSnapshotPath()}`);
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { buildApp } from '../../src/bootstrap';
|
||||
import { AppSettings } from '../../src/db/entities/AppSettings.entity';
|
||||
import { SchemaVersion } from '../../src/db/entities/SchemaVersion.entity';
|
||||
import { Users } from '../../src/db/entities/Users.entity';
|
||||
import { MapDefaultsSeeder } from '../../src/db/seeders/MapDefaultsSeeder';
|
||||
import { deleteRows, insertRow } from '../helpers/factories/rows';
|
||||
import { readAppSetting, setAppSetting } from '../helpers/factories/settings';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { MikroORM } from '@mikro-orm/core';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import { OPENFREEMAP_DEFAULT_STYLE } from '@trek/shared';
|
||||
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
const PROVIDER = 'default_user_setting_map_provider';
|
||||
const STYLE = 'default_user_setting_maplibre_style';
|
||||
|
||||
let app: INestApplication;
|
||||
let orm: MikroORM;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = await buildApp();
|
||||
orm = app.get(MikroORM);
|
||||
}, 60_000);
|
||||
|
||||
beforeEach(async () => {
|
||||
await deleteRows(orm, AppSettings, { key: { $in: [PROVIDER, STYLE] } });
|
||||
await deleteRows(orm, SchemaVersion, {});
|
||||
await deleteRows(orm, Users, {});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app?.close();
|
||||
});
|
||||
|
||||
const seed = () => new MapDefaultsSeeder().run(orm.em.fork());
|
||||
|
||||
describe('fresh-install map defaults', () => {
|
||||
it('sets MapLibre Liberty once and keeps a style explicitly chosen later', async () => {
|
||||
await seed();
|
||||
expect(await readAppSetting(orm, PROVIDER)).toBe(JSON.stringify('maplibre-gl'));
|
||||
expect(await readAppSetting(orm, STYLE)).toBe(JSON.stringify(OPENFREEMAP_DEFAULT_STYLE));
|
||||
await setAppSetting(orm, STYLE, JSON.stringify('trek:ofm-auto'));
|
||||
await seed();
|
||||
expect(await readAppSetting(orm, STYLE)).toBe(JSON.stringify('trek:ofm-auto'));
|
||||
});
|
||||
|
||||
it('keeps the provider and style of an install with an explicit default', async () => {
|
||||
await setAppSetting(orm, PROVIDER, JSON.stringify('leaflet'));
|
||||
await seed();
|
||||
expect(await readAppSetting(orm, PROVIDER)).toBe(JSON.stringify('leaflet'));
|
||||
expect(await readAppSetting(orm, STYLE)).toBeNull();
|
||||
});
|
||||
|
||||
it('leaves an existing installation waiting for its first SSO user alone', async () => {
|
||||
await insertRow(orm, SchemaVersion, { version: 258 });
|
||||
await seed();
|
||||
expect(await readAppSetting(orm, PROVIDER)).toBeNull();
|
||||
expect(await readAppSetting(orm, STYLE)).toBeNull();
|
||||
});
|
||||
|
||||
it('leaves an install with users alone even if the legacy marker is missing', async () => {
|
||||
await makeUser(orm);
|
||||
await seed();
|
||||
expect(await readAppSetting(orm, PROVIDER)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -77,7 +77,7 @@ The default map for everyone on this instance; each user can still override it i
|
||||
|
||||
- **Standard (free)**: the Leaflet map, using the **Map Template** above. This is the built-in default.
|
||||
- **Mapbox (3D)**: Mapbox GL with 3D buildings and terrain. Needs a Mapbox token.
|
||||
- **MapLibre (OpenFreeMap)**: MapLibre GL with OpenFreeMap vector tiles. No token needed.
|
||||
- **MapLibre (OpenFreeMap)**: MapLibre GL with OpenFreeMap vector tiles or a compatible map template. New installations from 5.3 start with OpenFreeMap Liberty.
|
||||
|
||||
Depending on the engine, more rows appear below it:
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ Choose the rendering engine:
|
||||
|
||||
Each GL provider stores its style in its own slot (`mapbox_style` for Mapbox GL, `maplibre_style` for MapLibre GL), so switching providers never clobbers the other one's style.
|
||||
|
||||
New TREK installations from 5.3 use MapLibre GL with OpenFreeMap Liberty by default. An upgraded installation keeps its existing provider and styles. The administrator can set the starting provider for users, and users can still choose their own.
|
||||
|
||||
## Leaflet — tile source
|
||||
|
||||
When Leaflet is selected, pick a preset or enter a custom tile URL.
|
||||
@@ -139,7 +141,7 @@ Enables antialiasing and globe projection for sharper edges. May impact performa
|
||||
|
||||
## MapLibre GL — style
|
||||
|
||||
MapLibre GL renders OpenFreeMap vector tiles and needs **no token at all**, so there is no token field on this provider — just a style.
|
||||
MapLibre GL can draw an OpenFreeMap style, follow the light or dark theme, or draw the tile template in **Map settings**. A template that requires a different projection or that MapLibre cannot load opens in Leaflet with the same template. MapLibre GL needs no access token of its own.
|
||||
|
||||
**Built-in style presets:**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user