-
Notifications
You must be signed in to change notification settings - Fork 5
Feat(initial view) #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat(initial view) #909
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b54e416
feat(initialView): add initial view plugin
LivMoeser aea2ee3
Merge branch 'next' of https://github.com/Dataport/polar into next
LivMoeser 396b606
feat(initialView): change to one-button application
LivMoeser 004ab9d
Merge branch 'next' of https://github.com/Dataport/polar into next
LivMoeser af11964
fix(initialView): move comment to variable in types.ts
JoselinGuevaraHoppe 6b517b4
fix(initialView): get startCenter and startResolution via core config…
JoselinGuevaraHoppe b823a80
fix(initialView): rename "initialViewStore" according ro camelCase
JoselinGuevaraHoppe 236bc0c
fix(initialView): inline function
JoselinGuevaraHoppe 949c299
fix(initialView): delete unused value
JoselinGuevaraHoppe 56b870a
fix(initialView): rename "returnToInitialView" to "initialView"
JoselinGuevaraHoppe e67cbc4
fix(initialView): comment @aplha in store
JoselinGuevaraHoppe 922d69b
fix(initialView): comment @internal in store
JoselinGuevaraHoppe 38d6aac
feat(initialView): add tests to store
LivMoeser f96fb95
Merge branch 'feat(initialView)' of https://github.com/Dataport/polar…
LivMoeser 29e7076
fix(initialView): fix comment @alpha in store
JoselinGuevaraHoppe 8a226bc
feat(core): remove readonly restriction
JoselinGuevaraHoppe c477d2c
fix(initialView): change returnToInitialView to reference to coreStor…
JoselinGuevaraHoppe ee1a583
fix: move plugin "initialView" to iconMenu
JoselinGuevaraHoppe 0399d64
fix(initialView): add tooltip-position to store
LivMoeser 80ca013
Merge branch 'feat(initialView)' of https://github.com/Dataport/polar…
LivMoeser dfe25eb
fix(initialView): remove startCenter and startView from export in store
JoselinGuevaraHoppe 19697fa
fix(initialView): fix test
JoselinGuevaraHoppe 6d70f92
fix(initialView): move mockCoreStore into test
JoselinGuevaraHoppe 6757108
Merge branch 'next' into feat(initialView)
dopenguin acabff0
fix(initialView): fix test
JoselinGuevaraHoppe 8879185
Merge branch 'feat(initialView)' of https://github.com/Dataport/polar…
JoselinGuevaraHoppe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <template> | ||
| <PolarIconButton | ||
| :hint="$t(($) => $.label.return, { ns: PluginId })" | ||
| icon="kern-icon--home" | ||
| :tooltip-position="initialViewStore.tooltipPosition" | ||
| @click="initialViewStore.returnToInitialView()" | ||
| /> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import PolarIconButton from '@/components/PolarIconButton.ce.vue' | ||
|
|
||
| import { useInitialViewStore } from '../store' | ||
| import { PluginId } from '../types' | ||
|
|
||
| const initialViewStore = useInitialViewStore() | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* eslint-disable tsdoc/syntax */ | ||
| /** | ||
| * @module @polar/polar/plugins/InitialView | ||
| */ | ||
| /* eslint-enable tsdoc/syntax */ | ||
|
|
||
| import type { PluginContainer, PolarPluginStore } from '@/core' | ||
| import type { InitialViewPluginOptions } from './types' | ||
|
|
||
| import component from './components/InitialView.ce.vue' | ||
| import locales from './locales' | ||
| import { useInitialViewStore } from './store' | ||
| import { PluginId } from './types' | ||
|
|
||
| /** | ||
| * Creates a plugin which offers a button to return to the map's start view. | ||
| * | ||
| * @returns Plugin for use with {@link addPlugin}. | ||
| */ | ||
| export default function pluginInitialView( | ||
| options: InitialViewPluginOptions = {} | ||
| ): PluginContainer { | ||
| return { | ||
| id: PluginId, | ||
| component, | ||
| locales, | ||
| storeModule: useInitialViewStore as PolarPluginStore, | ||
| options, | ||
| } | ||
| } | ||
|
|
||
| export * from './types' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* eslint-disable tsdoc/syntax */ | ||
| /** | ||
| * @module locales/plugins/InitialView | ||
| */ | ||
| /* eslint-enable tsdoc/syntax */ | ||
|
|
||
| import type { Locale } from '@/core' | ||
|
|
||
| export const resourcesDe = { | ||
| label: { | ||
| return: 'Zurück zur Startansicht', | ||
| }, | ||
| } as const | ||
|
|
||
| export const resourcesEn = { | ||
| label: { | ||
| return: 'Return to start view', | ||
| }, | ||
| } as const | ||
|
|
||
| const locales: Locale[] = [ | ||
| { | ||
| type: 'de', | ||
| resources: resourcesDe, | ||
| }, | ||
| { | ||
| type: 'en', | ||
| resources: resourcesEn, | ||
| }, | ||
| ] | ||
|
|
||
| export default locales |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import type { ComputedRef } from 'vue' | ||
| import type { InitialViewPluginOptions } from './types' | ||
|
|
||
| import { defineStore } from 'pinia' | ||
| import { computed } from 'vue' | ||
|
|
||
| import { useCoreStore } from '@/core/stores' | ||
|
|
||
| import { PluginId } from './types' | ||
|
|
||
| export const useInitialViewStore = defineStore('plugins/initialView', () => { | ||
| const coreStore = useCoreStore() | ||
|
|
||
| const configuration = computed( | ||
| () => coreStore.configuration[PluginId] as InitialViewPluginOptions | ||
| ) | ||
|
|
||
| const layoutTag = computed(() => configuration.value.layoutTag ?? '') | ||
|
|
||
| const renderType = computed( | ||
| () => configuration.value.renderType ?? 'independent' | ||
| ) | ||
|
|
||
| const tooltipPosition = computed(() => | ||
| renderType.value === 'independent' | ||
| ? layoutTag.value.includes('RIGHT') | ||
| ? 'left' | ||
| : 'right' | ||
| : coreStore.getPluginStore('iconMenu')?.layoutTag.includes('RIGHT') | ||
| ? 'left' | ||
| : 'right' | ||
| ) as ComputedRef<'left' | 'right'> | ||
|
|
||
| const startCenter = computed(() => coreStore.configuration.startCenter) | ||
|
|
||
| const startResolution = computed( | ||
| () => coreStore.configuration.startResolution | ||
| ) | ||
|
|
||
| function returnToInitialView() { | ||
| coreStore.center = startCenter.value | ||
| const zoom = coreStore.configuration.options.find( | ||
|
Check failure on line 42 in src/plugins/initialView/store.ts
|
||
| ({ resolution }) => resolution === startResolution.value | ||
| ) | ||
| if (zoom) { | ||
| coreStore.zoom = zoom.zoomLevel | ||
| } | ||
| } | ||
|
|
||
| function setupPlugin() {} | ||
|
|
||
| function teardownPlugin() {} | ||
|
|
||
| return { | ||
| startCenter, | ||
| startResolution, | ||
|
|
||
|
dopenguin marked this conversation as resolved.
Outdated
|
||
| /** @alpha */ | ||
| returnToInitialView, | ||
|
dopenguin marked this conversation as resolved.
|
||
|
|
||
| /** @internal */ | ||
| setupPlugin, | ||
|
|
||
| /** @internal */ | ||
| teardownPlugin, | ||
|
dopenguin marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Indicates in which direction of the element space is available for a tooltip. | ||
| * | ||
| * @alpha | ||
| * @readonly | ||
| */ | ||
| tooltipPosition, | ||
| } | ||
| }) | ||
|
|
||
| let mockCoreStore: unknown | ||
|
|
||
| if (import.meta.vitest) { | ||
| const { createPinia, setActivePinia } = await import('pinia') | ||
| const { describe, it, expect, vi, beforeEach } = import.meta.vitest | ||
|
|
||
| const mockView = { | ||
| setCenter: vi.fn(), | ||
| setResolution: vi.fn(), | ||
| } | ||
|
|
||
| vi.mock('@/core/stores', () => ({ | ||
| useCoreStore: () => mockCoreStore, | ||
| })) | ||
|
|
||
| const { useInitialViewStore } = await import('./store') | ||
|
|
||
| describe('InitialView Store', () => { | ||
| beforeEach(() => { | ||
| setActivePinia(createPinia()) | ||
| vi.clearAllMocks() | ||
| mockCoreStore = { | ||
| map: { | ||
| getView: vi.fn(() => mockView), | ||
| }, | ||
| configuration: { | ||
| startCenter: [10, 20], | ||
| startResolution: 2, | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| it('should call setCenter and setResolution on returnToInitialView', () => { | ||
| const store = useInitialViewStore() | ||
| store.returnToInitialView() | ||
| expect(mockView.setCenter).toHaveBeenCalledWith([10, 20]) | ||
| expect(mockView.setResolution).toHaveBeenCalledWith(2) | ||
| }) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { PluginOptions } from '@/core' | ||
|
|
||
| export const PluginId = 'initialView' as const | ||
|
|
||
| export interface InitialViewPluginOptions extends PluginOptions { | ||
| /** | ||
| * Defines if the initialView button is rendered independent or as part of the | ||
| * icon menu. | ||
| * @defaultValue `'independent'` | ||
| */ | ||
| renderType?: 'independent' | 'iconMenu' | ||
| } | ||
|
dopenguin marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.