Skip to content
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

UBER-916: Navigation from issue to mentioned issue break description #3746

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Doc, updateAttribute } from '@hcengineering/core'
import { Doc, Class, Ref, updateAttribute } from '@hcengineering/core'

import { IntlString } from '@hcengineering/platform'
import { createQuery, getAttribute, getClient, KeyedAttribute } from '@hcengineering/presentation'
Expand All @@ -32,15 +32,27 @@
const queryClient = createQuery()

let description: string
let prevObjectId: Ref<Doc>
let prevObjectClass: Ref<Class<Doc>>

let haveUnsavedChanges = false

$: if (object && description === undefined) {
/*
There is no onMount when go from one issue to another one via mention
There is a change of object when chaning a description.
So the only way to detect if we really need to re-init the state
is to check if object class and object id changed.
*/
$: if (object && (object._id !== prevObjectId || object._class !== prevObjectClass)) {
description = getAttribute(client, object, key)
prevObjectId = object._id
prevObjectClass = object._class
}

// We need to query the document one more time
// To make a difference between update of description from the bottom
// And update to if from another tab.

$: object &&
queryClient.query(object._class, { _id: object._id }, async (result: Doc[]) => {
if (result.length > 0) {
Expand All @@ -55,7 +67,7 @@

let descriptionBox: AttachmentStyledBox

async function save () {
async function save (object: Doc, description: string) {
clearTimeout(saveTrigger)
if (!object) {
return
Expand All @@ -80,7 +92,13 @@
function triggerSave (): void {
haveUnsavedChanges = true
clearTimeout(saveTrigger)
saveTrigger = setTimeout(save, 2500)

// Need to bind which object to save, because object could
// change after we have set timeout
const saveObject = object
const saveDescription = description

saveTrigger = setTimeout(() => save(saveObject, saveDescription), 2500)
}

export function isFocused (): boolean {
Expand All @@ -102,14 +120,14 @@
on:attached={(e) => descriptionBox.saveNewAttachment(e.detail)}
on:detached={(e) => descriptionBox.removeAttachmentById(e.detail)}
showButtons
on:blur={save}
on:blur={() => save(object, description)}
on:changeContent={triggerSave}
maxHeight={'card'}
focusable
bind:content={description}
{placeholder}
on:open-document={async (event) => {
save()
save(object, description)
const doc = await client.findOne(event.detail._class, { _id: event.detail._id })
if (doc != null) {
const location = await getObjectLinkFragment(client.getHierarchy(), doc, {}, view.component.EditDoc)
Expand Down