Skip to content

Commit

Permalink
fix: model list view query bug w/ names w/ parentheses (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabis94 authored Apr 26, 2024
1 parent ab56bc1 commit cd16b04
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<template v-else-if="pendingModel">
<ArrowUpOnSquareIcon class="w-4 h-4 text-foreground-2 mx-2" />
</template>
<template v-else>
<div class="w-4 h-4 mx-2" />
</template>

<!-- Name -->
<div class="flex justify-start space-x-2 items-center">
Expand Down Expand Up @@ -200,25 +203,32 @@
v-if="hasChildren && expanded && !isPendingFileUpload(item)"
class="pl-8 mt-4 space-y-4"
>
<div v-for="child in children" :key="child.fullName" class="flex">
<div class="h-20 absolute -ml-8 flex items-center mt-0 mr-1 pl-1">
<ChevronDownIcon class="w-4 h-4 rotate-45 text-foreground-2" />
</div>
<div v-if="childrenLoading" class="mr-8">
<CommonLoadingBar loading />
</div>
<ProjectPageModelsStructureItem
:item="child"
:project="project"
:can-contribute="canContribute"
class="flex-grow"
@model-updated="onModelUpdated"
@create-submodel="emit('create-submodel', $event)"
<template v-else>
<div v-for="child in children" :key="child.fullName" class="flex">
<div class="h-20 absolute -ml-8 flex items-center mt-0 mr-1 pl-1">
<ChevronDownIcon class="w-4 h-4 rotate-45 text-foreground-2" />
</div>
<ProjectPageModelsStructureItem
:item="child"
:project="project"
:can-contribute="canContribute"
class="flex-grow"
@model-updated="onModelUpdated"
@create-submodel="emit('create-submodel', $event)"
/>
</div>
</template>
<div v-if="canContribute" class="mr-8">
<ProjectPageModelsNewModelStructureItem
:project-id="project.id"
:parent-model-name="item.fullName"
/>
</div>
<ProjectPageModelsNewModelStructureItem
v-if="canContribute"
:project-id="project.id"
:parent-model-name="item.fullName"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -396,7 +406,11 @@ const viewAllUrl = computed(() => {
return modelRoute(props.project.id, `$${props.item.fullName}`)
})
const { result: childrenResult, refetch: refetchChildren } = useQuery(
const {
result: childrenResult,
refetch: refetchChildren,
loading: childrenLoading
} = useQuery(
projectModelChildrenTreeQuery,
() => ({
projectId: props.project.id,
Expand Down
24 changes: 22 additions & 2 deletions packages/frontend-2/components/user/profile/EditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@
</LayoutDialogSection>
<UserProfileEditDialogChangePassword :user="user" />
<UserProfileEditDialogDeleteAccount :user="user" @deleted="isOpen = false" />
<div class="text-tiny text-foreground-2 mt-4">
User #{{ user.id }} {{ distinctId ? ` | ${distinctId}` : '' }}
<div class="text-xs text-foreground-2 mt-4">
User ID:
<CommonTextLink size="xs" no-underline @click="copyUserId">
#{{ user.id }}
</CommonTextLink>
<template v-if="distinctId">
|
<CommonTextLink size="xs" no-underline @click="copyDistinctId">
{{ distinctId }}
</CommonTextLink>
</template>
</div>
</div>
</LayoutDialog>
Expand Down Expand Up @@ -44,6 +53,7 @@ const props = defineProps<{
}>()
const { activeUser: user, distinctId } = useActiveUser()
const { copy } = useClipboard()
const isOpen = computed({
get: () => !!(props.open && user.value),
Expand All @@ -59,4 +69,14 @@ const developerSettingsButton = computed(() => ({
isOpen.value = false
}
}))
const copyUserId = () => {
if (!user.value) return
copy(user.value.id)
}
const copyDistinctId = () => {
if (!distinctId.value) return
copy(distinctId.value)
}
</script>
18 changes: 11 additions & 7 deletions packages/server/modules/core/repositories/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,23 @@ function getModelTreeItemsBaseQuery(
projectId: string,
options?: Partial<{ filterOutEmptyMain: boolean; parentModelName: string }>
) {
const cleanInput = (input: string | null | undefined) => {
const clean = (input || '').toLowerCase()
const trimmed = trim(trim(clean), '/')
return trimmed
const cleanInput = (
input: string | null | undefined,
options?: Partial<{ escapeRegexp: boolean }>
) => {
let clean = (input || '').toLowerCase()
clean = trim(trim(clean), '/')
clean = options?.escapeRegexp ? clean.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') : clean
return clean
}

const { filterOutEmptyMain = true, parentModelName } = options || {}
const cleanModelName = cleanInput(parentModelName)
const cleanModelName = cleanInput(parentModelName, { escapeRegexp: true })
const branchPartPattern = `[^/]+` // regexp for each branch part between slashes

const regExp = cleanModelName.length
? // only direct children of parentModelName
`^${cleanModelName.replace('/', '\\/')}\\/(${branchPartPattern})`
`^${cleanModelName}\\/(${branchPartPattern})`
: // only first branch part (top level item)
`^${branchPartPattern}`

Expand Down Expand Up @@ -470,7 +474,7 @@ function getModelTreeItemsBaseQuery(

return {
query: finalQuery,
parentModelName: cleanModelName
parentModelName: cleanInput(parentModelName)
}
}

Expand Down

0 comments on commit cd16b04

Please sign in to comment.