From e7ba92c7641bc83186bb476439b82d69fdca6def Mon Sep 17 00:00:00 2001 From: Sergei Ogorelkov Date: Wed, 24 May 2023 10:29:18 +0400 Subject: [PATCH] [UBER-155] Replace "Back" button with "Breadcrumbs" (#3239) Signed-off-by: Sergei Ogorelkov --- packages/panel/src/components/Panel.svelte | 2 +- .../components/breadcrumbs/Breadcrumbs.svelte | 67 ++++++++++++++++ .../breadcrumbs/BreadcrumbsElement.svelte | 58 ++++++++------ .../src/components/breadcrumbs/types.ts | 30 ++++++++ .../src/components/breadcrumbs/utils.ts | 18 +++++ packages/presentation/src/index.ts | 2 + packages/presentation/src/types.ts | 2 + packages/theme/styles/_layouts.scss | 1 - packages/theme/styles/components.scss | 4 +- .../src/components/EditCard.svelte | 9 ++- .../src/components/PersonContent.svelte | 1 - .../src/components/EditDoc.svelte | 3 +- .../src/components/state/StatesBar.svelte | 6 +- .../components/issues/IssuePresenter.svelte | 11 +-- .../components/issues/edit/EditIssue.svelte | 12 ++- .../components/scrums/ScrumRecordPanel.svelte | 3 +- .../templates/EditIssueTemplate.svelte | 3 +- .../src/components/EditDoc.svelte | 3 +- .../src/components/ParentsNavigator.svelte | 76 +++++++++++++++++++ plugins/view-resources/src/index.ts | 1 + plugins/view-resources/src/utils.ts | 4 + tests/sanity/tests/org.members.spec.ts | 2 +- 22 files changed, 273 insertions(+), 45 deletions(-) create mode 100644 packages/presentation/src/components/breadcrumbs/Breadcrumbs.svelte rename plugins/task-resources/src/components/state/StatesBarElement.svelte => packages/presentation/src/components/breadcrumbs/BreadcrumbsElement.svelte (66%) create mode 100644 packages/presentation/src/components/breadcrumbs/types.ts create mode 100644 packages/presentation/src/components/breadcrumbs/utils.ts create mode 100644 plugins/view-resources/src/components/ParentsNavigator.svelte diff --git a/packages/panel/src/components/Panel.svelte b/packages/panel/src/components/Panel.svelte index 7769385c28..cd9d57b3b0 100644 --- a/packages/panel/src/components/Panel.svelte +++ b/packages/panel/src/components/Panel.svelte @@ -109,7 +109,7 @@ > {#if $$slots.navigator} -
+
{/if} diff --git a/packages/presentation/src/components/breadcrumbs/Breadcrumbs.svelte b/packages/presentation/src/components/breadcrumbs/Breadcrumbs.svelte new file mode 100644 index 0000000000..5eab818902 --- /dev/null +++ b/packages/presentation/src/components/breadcrumbs/Breadcrumbs.svelte @@ -0,0 +1,67 @@ + + + + + {#each models as model, i} + {@const { color } = model} + {#if hasComponent(model)} + {@const { component, props } = model} + + {#if typeof component === 'string'} + + {:else} + + {/if} + + {:else} + {@const { title, href, onClick } = model} + + + + {/if} + {/each} + diff --git a/plugins/task-resources/src/components/state/StatesBarElement.svelte b/packages/presentation/src/components/breadcrumbs/BreadcrumbsElement.svelte similarity index 66% rename from plugins/task-resources/src/components/state/StatesBarElement.svelte rename to packages/presentation/src/components/breadcrumbs/BreadcrumbsElement.svelte index 9b62d569d2..7f77dbe752 100644 --- a/plugins/task-resources/src/components/state/StatesBarElement.svelte +++ b/packages/presentation/src/components/breadcrumbs/BreadcrumbsElement.svelte @@ -1,6 +1,5 @@ -
{label}
+
(lenght = element.clientWidth + 32 > 300 ? 300 : element.clientWidth + 32)} +> + {#if $$slots.default} + + {:else} + {label} + {/if} +
{#if lenght > 0}
{/if} -
{label}
+
+
+ {#if $$slots.default} + + {:else} + {label} + {/if} +
+
{/if} diff --git a/packages/presentation/src/components/breadcrumbs/types.ts b/packages/presentation/src/components/breadcrumbs/types.ts new file mode 100644 index 0000000000..e7b7fed8ff --- /dev/null +++ b/packages/presentation/src/components/breadcrumbs/types.ts @@ -0,0 +1,30 @@ +// Copyright © 2023 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. + +import { AnyComponent, AnySvelteComponent } from '@hcengineering/ui' + +interface BreadcrumbsProps { + readonly color?: number | undefined +} + +type TextBreadcrumbsProps = { title: string } & ( + | { readonly href: string, readonly onClick?: undefined } + | { readonly href?: undefined, readonly onClick: (event: MouseEvent) => void } +) + +export interface ComponentBreadcrumbsProps { + readonly component: AnyComponent | AnySvelteComponent + readonly props: Record +} + +export type BreadcrumbsModel = BreadcrumbsProps & (TextBreadcrumbsProps | ComponentBreadcrumbsProps) diff --git a/packages/presentation/src/components/breadcrumbs/utils.ts b/packages/presentation/src/components/breadcrumbs/utils.ts new file mode 100644 index 0000000000..9267ab31bf --- /dev/null +++ b/packages/presentation/src/components/breadcrumbs/utils.ts @@ -0,0 +1,18 @@ +// Copyright © 2023 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. + +import { BreadcrumbsModel, ComponentBreadcrumbsProps } from './types' + +export function hasComponent (model: BreadcrumbsModel): model is ComponentBreadcrumbsProps { + return 'component' in model +} diff --git a/packages/presentation/src/index.ts b/packages/presentation/src/index.ts index dd48d8b1a9..e1dfe31fff 100644 --- a/packages/presentation/src/index.ts +++ b/packages/presentation/src/index.ts @@ -39,6 +39,8 @@ export { default as IndexedDocumentCompare } from './components/IndexedDocumentC export { default as DraggableList } from './components/DraggableList.svelte' export { default as NavLink } from './components/NavLink.svelte' export { default as IconForward } from './components/icons/Forward.svelte' +export { default as Breadcrumbs } from './components/breadcrumbs/Breadcrumbs.svelte' +export { default as BreadcrumbsElement } from './components/breadcrumbs/BreadcrumbsElement.svelte' export { default } from './plugin' export * from './types' export * from './utils' diff --git a/packages/presentation/src/types.ts b/packages/presentation/src/types.ts index cbbc0a6139..eba290d02d 100644 --- a/packages/presentation/src/types.ts +++ b/packages/presentation/src/types.ts @@ -2,6 +2,8 @@ import { Client, Doc, RelatedDocument } from '@hcengineering/core' import { Asset, IntlString, Resource } from '@hcengineering/platform' import { AnyComponent, AnySvelteComponent } from '@hcengineering/ui' +export * from './components/breadcrumbs/types' + /** * @public */ diff --git a/packages/theme/styles/_layouts.scss b/packages/theme/styles/_layouts.scss index 2d8ce605a8..0ceed92c2b 100644 --- a/packages/theme/styles/_layouts.scss +++ b/packages/theme/styles/_layouts.scss @@ -288,7 +288,6 @@ input.search { color: var(--theme-content-color); overflow: hidden; - visibility: visible; user-select: none; &:not(.nowrap) { diff --git a/packages/theme/styles/components.scss b/packages/theme/styles/components.scss index f6facb8263..b3904b9149 100644 --- a/packages/theme/styles/components.scss +++ b/packages/theme/styles/components.scss @@ -341,6 +341,7 @@ &:hover { fill: var(--theme-button-hovered); } } &__selected { fill: var(--theme-button-pressed); } + &__disabled { pointer-events: none; } .asb-label__container { position: absolute; @@ -356,7 +357,8 @@ font-weight: 500; font-size: 0.8125rem; color: var(--theme-dark-color); - pointer-events: none; + + &.disabled { pointer-events: none; } &.selected { color: var(--theme-caption-color); diff --git a/plugins/board-resources/src/components/EditCard.svelte b/plugins/board-resources/src/components/EditCard.svelte index a733e3a9c7..97980b3957 100644 --- a/plugins/board-resources/src/components/EditCard.svelte +++ b/plugins/board-resources/src/components/EditCard.svelte @@ -32,7 +32,13 @@ Label, showPopup } from '@hcengineering/ui' - import { ContextMenu, DocAttributeBar, invokeAction, UpDownNavigator } from '@hcengineering/view-resources' + import { + ContextMenu, + DocAttributeBar, + invokeAction, + ParentsNavigator, + UpDownNavigator + } from '@hcengineering/view-resources' import { createEventDispatcher, onMount } from 'svelte' import board from '../plugin' import { getCardActions } from '../utils/CardActionUtils' @@ -116,6 +122,7 @@ > +
diff --git a/plugins/contact-resources/src/components/PersonContent.svelte b/plugins/contact-resources/src/components/PersonContent.svelte index 6b76d8a917..25e419f788 100644 --- a/plugins/contact-resources/src/components/PersonContent.svelte +++ b/plugins/contact-resources/src/components/PersonContent.svelte @@ -119,7 +119,6 @@ color: var(--theme-caption-color); overflow: hidden; - visibility: visible; display: -webkit-box; /* autoprefixer: ignore next */ -webkit-box-orient: vertical; diff --git a/plugins/document-resources/src/components/EditDoc.svelte b/plugins/document-resources/src/components/EditDoc.svelte index f4ae649685..a427aaaa4a 100644 --- a/plugins/document-resources/src/components/EditDoc.svelte +++ b/plugins/document-resources/src/components/EditDoc.svelte @@ -47,7 +47,7 @@ SelectPopup, showPopup } from '@hcengineering/ui' - import { ClassAttributeBar, ContextMenu, UpDownNavigator } from '@hcengineering/view-resources' + import { ClassAttributeBar, ContextMenu, ParentsNavigator, UpDownNavigator } from '@hcengineering/view-resources' import { createEventDispatcher, onDestroy, onMount } from 'svelte' import document from '../plugin' import DocumentEditor from './DocumentEditor.svelte' @@ -385,6 +385,7 @@ > + diff --git a/plugins/task-resources/src/components/state/StatesBar.svelte b/plugins/task-resources/src/components/state/StatesBar.svelte index 272757cc49..7df430bdeb 100644 --- a/plugins/task-resources/src/components/state/StatesBar.svelte +++ b/plugins/task-resources/src/components/state/StatesBar.svelte @@ -15,12 +15,11 @@ --> + +{#await getBreadcrumbsModels(element) then models} + {#if models.length > 0} + + {/if} +{/await} diff --git a/plugins/view-resources/src/index.ts b/plugins/view-resources/src/index.ts index 08c313c652..261213de74 100644 --- a/plugins/view-resources/src/index.ts +++ b/plugins/view-resources/src/index.ts @@ -123,6 +123,7 @@ export { default as StatusRefPresenter } from './components/status/StatusRefPres export { default as TableBrowser } from './components/TableBrowser.svelte' export { default as ValueSelector } from './components/ValueSelector.svelte' export { default as FilterRemovedNotification } from './components/filter/FilterRemovedNotification.svelte' +export { default as ParentsNavigator } from './components/ParentsNavigator.svelte' export * from './context' export * from './filter' export * from './selection' diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index 2e2b4d8fde..b48c8fc294 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -949,3 +949,7 @@ export async function statusSort ( ) }) } + +export function isAttachedDoc (doc: Doc | AttachedDoc): doc is AttachedDoc { + return 'attachedTo' in doc +} diff --git a/tests/sanity/tests/org.members.spec.ts b/tests/sanity/tests/org.members.spec.ts index b0a89f8873..829b810669 100644 --- a/tests/sanity/tests/org.members.spec.ts +++ b/tests/sanity/tests/org.members.spec.ts @@ -25,6 +25,6 @@ test.describe('recruit tests', () => { await page.click('[id="contact:string:AddMember"]') await page.click('button:has-text("Chen Rosamund")') await page.click('text=Chen Rosamund less than a minute ago >> span') - await page.click(`:nth-match(:text("${orgId}"), 2)`) + await page.click(`.card a:has-text("${orgId}")`) }) })