Browse Source

fix: ws issue with cmdk

nc-fix/cmdk-ws-2
mertmit 2 months ago
parent
commit
9aa6c11ea4
  1. 20
      packages/nc-gui/components/cmd-k/index.vue
  2. 42
      packages/nc-gui/composables/useCommandPalette/index.ts

20
packages/nc-gui/components/cmd-k/index.vue

@ -40,6 +40,8 @@ const cmdInputEl = ref<HTMLInputElement>()
const cmdInput = ref('')
const debouncedCmdInput = ref('')
const { user } = useGlobal()
const selected = ref<string>()
@ -56,7 +58,7 @@ const formattedData: ComputedRef<(CmdAction & { weight: number })[]> = computed(
parent: el.parent || 'root',
weight: commandScore(
`${el.section}${el?.section === 'Views' && el?.is_default ? t('title.defaultView') : el.title}${el.keywords?.join()}`,
cmdInput.value,
debouncedCmdInput.value,
),
})
}
@ -117,7 +119,7 @@ const actionList = computed(() => {
return 0
})
return formattedData.value.filter((el) => {
if (cmdInput.value === '') {
if (debouncedCmdInput.value === '') {
if (el.parent === activeScope.value) {
if (!el.handler) {
return isThereAnyActionInScope(el.id)
@ -137,8 +139,20 @@ const actionList = computed(() => {
})
})
const updateDebouncedInput = useDebounceFn(() => {
debouncedCmdInput.value = cmdInput.value
}, 300)
watch(cmdInput, () => {
if (cmdInput.value === '') {
debouncedCmdInput.value = ''
} else {
updateDebouncedInput()
}
})
const searchedActionList = computed(() => {
if (cmdInput.value === '') return actionList.value
if (debouncedCmdInput.value === '') return actionList.value
actionList.value.sort((a, b) => {
if (a.weight > b.weight) return -1
if (a.weight < b.weight) return 1

42
packages/nc-gui/composables/useCommandPalette/index.ts

@ -36,6 +36,26 @@ export const useCommandPalette = createSharedComposable(() => {
const { workspacesList } = storeToRefs(useWorkspace())
const workspacesCmd = computed(() =>
(workspacesList.value || []).map((workspace: { id: string; title: string; meta?: { color: string } }) => ({
id: `ws-nav-${workspace.id}`,
title: workspace.title,
icon: 'workspace',
iconColor: workspace.meta?.color,
section: 'Workspaces',
scopePayload: {
scope: `ws-${workspace.id}`,
data: {
workspace_id: workspace.id,
},
},
handler: processHandler({
type: 'navigate',
payload: `/${workspace.id}/settings`,
}),
})),
)
const commands = ref({
homeCommands,
baseCommands: [],
@ -63,25 +83,7 @@ export const useCommandPalette = createSharedComposable(() => {
staticCmd.push(...commands.value.baseCommands)
return (workspacesList.value || [])
.map((workspace: { id: string; title: string; meta?: { color: string } }) => ({
id: `ws-nav-${workspace.id}`,
title: workspace.title,
icon: 'workspace',
iconColor: workspace.meta?.color,
section: 'Workspaces',
scopePayload: {
scope: `ws-${workspace.id}`,
data: {
workspace_id: workspace.id,
},
},
handler: processHandler({
type: 'navigate',
payload: `/${workspace.id}/settings`,
}),
}))
.concat(staticCmd)
return workspacesCmd.value.concat(staticCmd)
})
const dynamicData = ref<any>([])
@ -188,6 +190,8 @@ export const useCommandPalette = createSharedComposable(() => {
scope: `ws-${route.value.params.typeOrId}`,
data: { workspace_id: route.value.params.typeOrId },
}
refreshCommandPalette.trigger()
} else if (route.value.params.typeOrId === 'nc') {
if (activeScope.value.data.base_id === route.value.params.baseId) return

Loading…
Cancel
Save