aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-07-08 16:23:52 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-07-10 01:35:24 +0200
commita96b5940dd9d80c6ea6fbb5faa6ef7d1a7cc6734 (patch)
treeb6d0368a9e25c52dfcbb28f8a816dfbfd77f4ff8
parent4fc77eca47947e833f371253d80db0cc0cad4fbf (diff)
downloadnextcloud-server-a96b5940dd9d80c6ea6fbb5faa6ef7d1a7cc6734.tar.gz
nextcloud-server-a96b5940dd9d80c6ea6fbb5faa6ef7d1a7cc6734.zip
chore: Make active apps initial state consistent with OCS API
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--apps/settings/src/components/AppStoreDiscover/AppLink.vue8
-rw-r--r--apps/theming/src/components/UserAppMenuSection.vue23
-rw-r--r--apps/theming/src/components/admin/AppMenuSection.vue7
-rw-r--r--apps/updatenotification/src/init.ts9
-rw-r--r--core/src/types/navigation.d.ts30
-rw-r--r--lib/private/TemplateLayout.php2
6 files changed, 46 insertions, 33 deletions
diff --git a/apps/settings/src/components/AppStoreDiscover/AppLink.vue b/apps/settings/src/components/AppStoreDiscover/AppLink.vue
index 1ce19ad7319..703adb9f041 100644
--- a/apps/settings/src/components/AppStoreDiscover/AppLink.vue
+++ b/apps/settings/src/components/AppStoreDiscover/AppLink.vue
@@ -18,12 +18,10 @@ import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import { defineComponent } from 'vue'
import { RouterLink } from 'vue-router'
+import type { INavigationEntry } from '../../../../../core/src/types/navigation'
-const knownRoutes = Object.fromEntries(
- Object.entries(
- loadState<Record<string, { app?: string, href: string }>>('core', 'apps'),
- ).map(([k, v]) => [v.app ?? k, v.href]),
-)
+const apps = loadState<INavigationEntry[]>('core', 'apps')
+const knownRoutes = Object.fromEntries(apps.map((app) => [app.app ?? app.id, app.href]))
/**
* This component either shows a native link to the installed app or external size - or a router link to the appstore page of the app if not installed
diff --git a/apps/theming/src/components/UserAppMenuSection.vue b/apps/theming/src/components/UserAppMenuSection.vue
index b3d9d9f7694..56abd357274 100644
--- a/apps/theming/src/components/UserAppMenuSection.vue
+++ b/apps/theming/src/components/UserAppMenuSection.vue
@@ -33,6 +33,7 @@
<script lang="ts">
import type { IApp } from './AppOrderSelector.vue'
+import type { INavigationEntry } from '../../../../core/src/types/navigation.d.ts'
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
@@ -47,26 +48,6 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
-/** See NavigationManager */
-interface INavigationEntry {
- /** Navigation id */
- id: string
- /** Order where this entry should be shown */
- order: number
- /** Target of the navigation entry */
- href: string
- /** The icon used for the naviation entry */
- icon: string
- /** Type of the navigation entry ('link' vs 'settings') */
- type: 'link' | 'settings'
- /** Localized name of the navigation entry */
- name: string
- /** Whether this is the default app */
- default?: boolean
- /** App that registered this navigation entry (not necessarly the same as the id) */
- app?: string
-}
-
/** The app order user setting */
type IAppOrder = Record<string, { order: number, app?: string }>
@@ -98,7 +79,7 @@ export default defineComponent({
/**
* Array of all available apps, it is set by a core controller for the app menu, so it is always available
*/
- const initialAppOrder = Object.values(loadState<Record<string, INavigationEntry>>('core', 'apps'))
+ const initialAppOrder = loadState<INavigationEntry[]>('core', 'apps')
.filter(({ type }) => type === 'link')
.map((app) => ({ ...app, label: app.name, default: app.default && app.app === enforcedDefaultApp }))
diff --git a/apps/theming/src/components/admin/AppMenuSection.vue b/apps/theming/src/components/admin/AppMenuSection.vue
index 2bcb6903bdc..fb8fdc67f98 100644
--- a/apps/theming/src/components/admin/AppMenuSection.vue
+++ b/apps/theming/src/components/admin/AppMenuSection.vue
@@ -30,6 +30,8 @@
</template>
<script lang="ts">
+import type { INavigationEntry } from '../../../../../core/src/types/navigation'
+
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { translate as t } from '@nextcloud/l10n'
@@ -75,9 +77,8 @@ export default defineComponent({
/**
* All enabled apps which can be navigated
*/
- const allApps = Object.values(
- loadState<Record<string, { id: string, name?: string, icon: string }>>('core', 'apps'),
- ).map(({ id, name, icon }) => ({ label: name, id, icon }))
+ const allApps = loadState<INavigationEntry[]>('core', 'apps')
+ .map(({ id, name, icon }) => ({ label: name, id, icon }))
/**
* Currently selected app, wrapps the setter
diff --git a/apps/updatenotification/src/init.ts b/apps/updatenotification/src/init.ts
index ebfbf68996a..d82272bf4b2 100644
--- a/apps/updatenotification/src/init.ts
+++ b/apps/updatenotification/src/init.ts
@@ -2,13 +2,15 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+import type { INavigationEntry } from '../../../core/src/types/navigation'
+
import { subscribe } from '@nextcloud/event-bus'
import { loadState } from '@nextcloud/initial-state'
import { generateOcsUrl } from '@nextcloud/router'
import Vue, { defineAsyncComponent } from 'vue'
import axios from '@nextcloud/axios'
-const navigationEntries = loadState('core', 'apps', {})
+const navigationEntries = loadState<INavigationEntry[]>('core', 'apps', [])
const DialogVue = defineAsyncComponent(() => import('./components/AppChangelogDialog.vue'))
@@ -39,8 +41,9 @@ function showDialog(appId: string, version?: string) {
dialog.$destroy?.()
resolve(dismissed)
- if (dismissed && appId in navigationEntries) {
- window.location = navigationEntries[appId].href
+ const app = navigationEntries.find(({ app }) => app === appId)
+ if (dismissed && app !== undefined) {
+ window.location.href = app.href
}
}
},
diff --git a/core/src/types/navigation.d.ts b/core/src/types/navigation.d.ts
new file mode 100644
index 00000000000..5698aab205e
--- /dev/null
+++ b/core/src/types/navigation.d.ts
@@ -0,0 +1,30 @@
+/*!
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+/** See NavigationManager */
+export interface INavigationEntry {
+ /** Navigation id */
+ id: string
+ /** If this is the currently active app */
+ active: boolean
+ /** Order where this entry should be shown */
+ order: number
+ /** Target of the navigation entry */
+ href: string
+ /** The icon used for the naviation entry */
+ icon: string
+ /** Type of the navigation entry ('link' vs 'settings') */
+ type: 'link' | 'settings'
+ /** Localized name of the navigation entry */
+ name: string
+ /** Whether this is the default app */
+ default?: boolean
+ /** App that registered this navigation entry (not necessarly the same as the id) */
+ app?: string
+ /** If this app has unread notification */
+ unread: number
+ /** True when the link should be opened in a new tab */
+ target?: boolean
+}
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 27e988711be..2f6b0209153 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -74,7 +74,7 @@ class TemplateLayout extends \OC_Template {
}
$this->initialState->provideInitialState('core', 'active-app', $this->navigationManager->getActiveEntry());
- $this->initialState->provideInitialState('core', 'apps', $this->navigationManager->getAll());
+ $this->initialState->provideInitialState('core', 'apps', array_values($this->navigationManager->getAll()));
if ($this->config->getSystemValueBool('unified_search.enabled', false) || !$this->config->getSystemValueBool('enable_non-accessible_features', true)) {
$this->initialState->provideInitialState('unified-search', 'limit-default', (int)$this->config->getAppValue('core', 'unified-search.limit-default', (string)SearchQuery::LIMIT_DEFAULT));