From 3d06e44517dcf75ed367f2268f44de362df7b63c Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Fri, 9 Jun 2023 00:42:00 +0700 Subject: [PATCH] UBER-438: Use tracker as default for new users/workspaces (#3403) --- dev/prod/src/platform.ts | 5 ++- packages/ui/src/location.ts | 4 ++- plugins/view-resources/src/middleware.ts | 2 +- .../src/components/Workbench.svelte | 31 +++++++++++++++++-- plugins/workbench/src/index.ts | 5 ++- tests/sanity/tests/tracker.spec.ts | 22 +++++++++---- tests/sanity/tests/tracker.utils.ts | 1 - 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index dddf20a59b..d431fcb08c 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -39,7 +39,7 @@ import { tagsId } from '@hcengineering/tags' import { taskId } from '@hcengineering/task' import telegram, { telegramId } from '@hcengineering/telegram' import { templatesId } from '@hcengineering/templates' -import { trackerId } from '@hcengineering/tracker' +import tracker, { trackerId } from '@hcengineering/tracker' import uiPlugin from '@hcengineering/ui' import { viewId } from '@hcengineering/view' import workbench, { workbenchId } from '@hcengineering/workbench' @@ -166,4 +166,7 @@ export async function configurePlatform() { setMetadata(workbench.metadata.PlatformTitle, config.TITLE ?? 'Platform') setDefaultLanguage(config.DEFAULT_LANGUAGE ?? 'en') + setMetadata(workbench.metadata.DefaultApplication, 'tracker') + setMetadata(workbench.metadata.DefaultSpace, tracker.project.DefaultProject) + setMetadata(workbench.metadata.DefaultSpecial, 'issues') } diff --git a/packages/ui/src/location.ts b/packages/ui/src/location.ts index ec1e47dac7..97385dad09 100644 --- a/packages/ui/src/location.ts +++ b/packages/ui/src/location.ts @@ -122,7 +122,7 @@ export function setResolvedLocation (location: PlatformLocation): void { resolvedLocationStore.set(justClone(location)) } -export function navigate (location: PlatformLocation, store = true): void { +export function navigate (location: PlatformLocation, store = true): boolean { closePopup() const url = locationToUrl(location) if (locationToUrl(getCurrentLocation()) !== url) { @@ -134,5 +134,7 @@ export function navigate (location: PlatformLocation, store = true): void { } } locationWritable.set(location) + return true } + return false } diff --git a/plugins/view-resources/src/middleware.ts b/plugins/view-resources/src/middleware.ts index 4303513d63..ba440680ac 100644 --- a/plugins/view-resources/src/middleware.ts +++ b/plugins/view-resources/src/middleware.ts @@ -123,7 +123,7 @@ export class AggregationMiddleware extends BasePresentationMiddleware implements const mixin = h.classHierarchyMixin(_class, view.mixin.Aggregation) if (mixin?.createAggregationManager !== undefined) { const f = await getResource(mixin.createAggregationManager) - mgr = f(this.client, this.refreshSubscribers) + mgr = f(this.client, () => this.refreshSubscribers()) this.mgrs.set(_class, mgr) } } diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index eebd2c998a..2875a23b53 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -273,11 +273,38 @@ let space = loc.path[3] as Ref let special = loc.path[4] const fragment = loc.fragment - + let navigateDone = false if (app === undefined) { const last = localStorage.getItem(`platform_last_loc_${loc.path[1]}`) if (last != null) { - navigate(JSON.parse(last)) + const lastValue = JSON.parse(last) + navigateDone = navigate(lastValue) + if (navigateDone) { + return + } + } + if (app === undefined && !navigateDone) { + const appShort = getMetadata(workbench.metadata.DefaultApplication) as Ref + const spaceRef = getMetadata(workbench.metadata.DefaultSpace) as Ref + const specialRef = getMetadata(workbench.metadata.DefaultSpecial) as Ref + const loc = getCurrentLocation() + // Be sure URI is not yet changed + if (loc.path[2] === undefined) { + loc.path[2] = appShort + let len = 3 + if (spaceRef !== undefined && specialRef !== undefined) { + const spaceObj = await client.findOne(core.class.Space, { _id: spaceRef }) + if (spaceObj !== undefined) { + loc.path[3] = spaceRef + loc.path[4] = specialRef + len = 5 + } + } + loc.path.length = len + if (navigate(loc)) { + return + } + } } } diff --git a/plugins/workbench/src/index.ts b/plugins/workbench/src/index.ts index 1cbb3db872..635a179a69 100644 --- a/plugins/workbench/src/index.ts +++ b/plugins/workbench/src/index.ts @@ -130,7 +130,10 @@ export default plugin(workbenchId, { }, metadata: { PlatformTitle: '' as Metadata, - ExcludedApplications: '' as Metadata[]> + ExcludedApplications: '' as Metadata[]>, + DefaultApplication: '' as Metadata, + DefaultSpace: '' as Metadata>, + DefaultSpecial: '' as Metadata }, actionImpl: { Navigate: '' as ViewAction<{ diff --git a/tests/sanity/tests/tracker.spec.ts b/tests/sanity/tests/tracker.spec.ts index 8562db5511..9c6b56cd21 100644 --- a/tests/sanity/tests/tracker.spec.ts +++ b/tests/sanity/tests/tracker.spec.ts @@ -44,9 +44,9 @@ test.use({ const getIssueName = (postfix: string = generateId(5)): string => `issue-${postfix}` const panelStatusMap = new Map([ - ['Issues', DEFAULT_STATUSES], - ['Active', ['Todo', 'In Progress']], - ['Backlog', ['Backlog']] + ['Issues/All', DEFAULT_STATUSES], + ['Issues/Active', ['Todo', 'In Progress']], + ['Issues/Backlog', ['Backlog']] ]) test('issues-status-display', async ({ page }) => { @@ -56,14 +56,24 @@ test('issues-status-display', async ({ page }) => { await createIssue(page, { name: getIssueName(status), status }) } for (const [panel, statuses] of panelStatusMap) { + const pPage = panel.split('/') + await performPanelTest(statuses, pPage[0], pPage[1]) + } + + async function performPanelTest (statuses: string[], panel: string, mode: string): Promise { const excluded = DEFAULT_STATUSES.filter((status) => !statuses.includes(status)) - await page.locator(`text="${panel}"`).click() + await page.locator(`.antiNav-element__dropbox > a > .antiNav-element:has-text("${panel}")`).click() + await page.locator(`.ac-header .overflow-label:has-text("${mode}")`).click() await page.click(ViewletSelectors.Table) await expect(locator).toContainText(statuses) - if (excluded.length > 0) await expect(locator).not.toContainText(excluded) + if (excluded.length > 0) { + await expect(locator).not.toContainText(excluded) + } await page.click(ViewletSelectors.Board) - if (excluded.length > 0) await expect(locator).not.toContainText(excluded) + if (excluded.length > 0) { + await expect(locator).not.toContainText(excluded) + } for (const status of statuses) { await expect( page.locator('.panel-container', { diff --git a/tests/sanity/tests/tracker.utils.ts b/tests/sanity/tests/tracker.utils.ts index d84572f1a4..480148c006 100644 --- a/tests/sanity/tests/tracker.utils.ts +++ b/tests/sanity/tests/tracker.utils.ts @@ -26,7 +26,6 @@ export const DEFAULT_USER = 'Appleseed John' export async function navigate (page: Page): Promise { await (await page.goto(`${PlatformURI}/workbench/sanity-ws`))?.finished() await page.click('[id="app-tracker\\:string\\:TrackerApplication"]') - await expect(page).toHaveURL(`${PlatformURI}/workbench/sanity-ws/tracker`) } export async function setViewGroup (page: Page, groupName: string): Promise {