Skip to content

Commit

Permalink
feat: can format tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzio committed May 1, 2024
1 parent 60b87a0 commit ae65131
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions extensions/database/src/ui/tag/TagSelectorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@penx/constants'
import { PenxEditor, useEditorStatic } from '@penx/editor-common'
import { findNodePath, getNodeByPath } from '@penx/editor-queries'
import { db, getRandomColor } from '@penx/local-db'
import { db, formatTagName, getRandomColor } from '@penx/local-db'
import { INode } from '@penx/model-types'
import { useNodes } from '@penx/node-hooks'
import { getEmptyParagraph } from '@penx/paragraph'
Expand Down Expand Up @@ -68,7 +68,8 @@ export const TagSelectorContent = ({ close, element }: Props) => {
editor.isInTodoPage

const text = getSearchText(editor, element)
const tagName = text.replace(/^#/, '')
// const tagName = text.replace(/^#/, '')
const tagName = formatTagName(text.replace(/^#/, ''))

const filteredTypes = useMemo(() => {
const q = text.replace(/^#/, '').toLowerCase()
Expand Down
6 changes: 3 additions & 3 deletions packages/database-ui/src/TagMenu/TagMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
usePopoverContext,
} from 'uikit'
import { ModalNames } from '@penx/constants'
import { db, getColorNames } from '@penx/local-db'
import { db, formatTagName, getColorNames } from '@penx/local-db'
import { Node } from '@penx/model'
import { IDatabaseNode } from '@penx/model-types'
import { useCopyToClipboard } from '@penx/shared'
Expand Down Expand Up @@ -73,11 +73,11 @@ function Content() {
size="sm"
value={name}
onBlur={() => {
updateDatabaseProps({ name })
updateDatabaseProps({ name: formatTagName(name) })
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
updateDatabaseProps({ name })
updateDatabaseProps({ name: formatTagName(name) })
close()
}
}}
Expand Down
4 changes: 3 additions & 1 deletion packages/local-db/src/domains/database.domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ViewType,
} from '@penx/model-types'
import { uniqueId } from '@penx/unique-id'
import { formatTagName } from '../libs/formatTagName'
import { getRandomColor } from '../libs/getRandomColor'
import { PenxDB, penxDB } from '../penx-db'
import {
Expand Down Expand Up @@ -846,14 +847,15 @@ export class DatabaseDomain {
}

createTagRow = async (spaceId: string, name: string, ref = '') => {
const tagName = formatTagName(name)
const databases = await this.penx.node
.where({
type: NodeType.DATABASE,
spaceId,
})
.toArray()

const database = databases.find((db) => db.props.name === name)
const database = databases.find((db) => db.props.name === tagName)
if (!database) return

// Get all database cells
Expand Down
1 change: 1 addition & 0 deletions packages/local-db/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './libs/getCommonNode'
export * from './emitter'
export * from './libs/getRandomColor'
export * from './libs/array-sorter'
export * from './libs/formatTagName'
3 changes: 3 additions & 0 deletions packages/local-db/src/libs/formatTagName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function formatTagName(name = '') {
return name.trim().replace(/\s+/g, '-').toLowerCase()
}

0 comments on commit ae65131

Please sign in to comment.