chore: Make active apps initial state consistent with OCS API

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/46370/head
Ferdinand Thiessen 10 months ago
parent 4fc77eca47
commit a96b5940dd
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
  1. 8
      apps/settings/src/components/AppStoreDiscover/AppLink.vue
  2. 23
      apps/theming/src/components/UserAppMenuSection.vue
  3. 7
      apps/theming/src/components/admin/AppMenuSection.vue
  4. 9
      apps/updatenotification/src/init.ts
  5. 30
      core/src/types/navigation.d.ts
  6. 2
      lib/private/TemplateLayout.php

@ -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

@ -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 }))

@ -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

@ -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
}
}
},

@ -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
}

@ -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));

Loading…
Cancel
Save