Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
2b9f394a
Commit
2b9f394a
authored
Jun 13, 2023
by
JzoNg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add type for notion info list
parent
56bebe04
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
20 deletions
+85
-20
base.tsx
web/app/components/base/notion-page-selector/base.tsx
+1
-1
index.tsx
web/app/components/datasets/create/index.tsx
+6
-2
index.tsx
web/app/components/datasets/create/step-one/index.tsx
+17
-4
index.tsx
web/app/components/datasets/create/step-two/index.tsx
+43
-6
index.tsx
web/app/components/datasets/documents/index.tsx
+2
-1
datasets.ts
web/models/datasets.ts
+16
-6
No files found.
web/app/components/base/notion-page-selector/base.tsx
View file @
2b9f394a
...
...
@@ -26,7 +26,7 @@ const NotionPageSelector = ({
canPreview
,
previewPageId
,
onPreview
,
datasetId
,
datasetId
=
''
,
}:
NotionPageSelectorProps
)
=>
{
const
{
data
}
=
useSWR
({
url
:
'/notion/pre-import/pages'
,
datasetId
},
preImportNotionPages
)
const
[
prevData
,
setPrevData
]
=
useState
(
data
)
...
...
web/app/components/datasets/create/index.tsx
View file @
2b9f394a
...
...
@@ -11,9 +11,12 @@ import { DataSourceType } from '@/models/datasets'
import
type
{
DataSet
,
File
,
createDocumentResponse
}
from
'@/models/datasets'
import
{
fetchDataSource
,
fetchTenantInfo
}
from
'@/service/common'
import
{
fetchDataDetail
}
from
'@/service/datasets'
import
type
{
DataSourceNotionPage
}
from
'@/models/common'
import
AccountSetting
from
'@/app/components/header/account-setting'
type
Page
=
DataSourceNotionPage
&
{
workspace_id
:
string
}
type
DatasetUpdateFormProps
=
{
datasetId
?:
string
}
...
...
@@ -32,8 +35,8 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => {
const
[
hasError
,
setHasError
]
=
useState
(
false
)
// TODO
const
[
notionPages
,
setNotionPages
]
=
useState
<
any
>
([])
const
updateNotionPages
=
(
value
:
any
[])
=>
{
const
[
notionPages
,
setNotionPages
]
=
useState
<
Page
[]
>
([])
const
updateNotionPages
=
(
value
:
Page
[])
=>
{
setNotionPages
(
value
)
}
...
...
@@ -100,6 +103,7 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => {
onSetting=
{
showDataSourceSetting
}
datasetId=
{
datasetId
}
dataSourceType=
{
dataSourceType
}
dataSourceTypeDisable=
{
!!
detail
?.
data_source_type
}
changeType=
{
setDataSourceType
}
file=
{
file
}
updateFile=
{
updateFile
}
...
...
web/app/components/datasets/create/step-one/index.tsx
View file @
2b9f394a
...
...
@@ -16,6 +16,7 @@ import { NotionPageSelector } from '@/app/components/base/notion-page-selector'
type
IStepOneProps
=
{
datasetId
?:
string
dataSourceType
:
DataSourceType
dataSourceTypeDisable
:
Boolean
hasConnection
:
boolean
onSetting
:
()
=>
void
file
?:
File
...
...
@@ -31,6 +32,7 @@ type Page = DataSourceNotionPage & { workspace_id: string }
const
StepOne
=
({
datasetId
,
dataSourceType
,
dataSourceTypeDisable
,
changeType
,
hasConnection
,
onSetting
,
...
...
@@ -66,8 +68,14 @@ const StepOne = ({
<
div
className=
{
s
.
form
}
>
<
div
className=
{
s
.
dataSourceTypeList
}
>
<
div
className=
{
cn
(
s
.
dataSourceItem
,
dataSourceType
===
DataSourceType
.
FILE
&&
s
.
active
)
}
className=
{
cn
(
s
.
dataSourceItem
,
dataSourceType
===
DataSourceType
.
FILE
&&
s
.
active
,
dataSourceTypeDisable
&&
dataSourceType
!==
DataSourceType
.
FILE
&&
s
.
disabled
,
)
}
onClick=
{
()
=>
{
if
(
dataSourceTypeDisable
)
return
changeType
(
DataSourceType
.
FILE
)
hidePreview
()
}
}
...
...
@@ -76,8 +84,14 @@ const StepOne = ({
{
t
(
'datasetCreation.stepOne.dataSourceType.file'
)
}
</
div
>
<
div
className=
{
cn
(
s
.
dataSourceItem
,
dataSourceType
===
DataSourceType
.
NOTION
&&
s
.
active
)
}
className=
{
cn
(
s
.
dataSourceItem
,
dataSourceType
===
DataSourceType
.
NOTION
&&
s
.
active
,
dataSourceTypeDisable
&&
dataSourceType
!==
DataSourceType
.
NOTION
&&
s
.
disabled
,
)
}
onClick=
{
()
=>
{
if
(
dataSourceTypeDisable
)
return
changeType
(
DataSourceType
.
NOTION
)
hidePreview
()
}
}
...
...
@@ -112,9 +126,8 @@ const StepOne = ({
)
}
{
hasConnection
&&
(
<>
{
/* TODO */
}
<
div
className=
'mb-8 w-[640px]'
>
<
NotionPageSelector
onSelect=
{
updateNotionPages
}
onPreview=
{
updateCurrentPage
}
/>
<
NotionPageSelector
value=
{
notionPages
.
map
(
page
=>
page
.
page_id
)
}
onSelect=
{
updateNotionPages
}
onPreview=
{
updateCurrentPage
}
/>
</
div
>
<
Button
disabled=
{
!
notionPages
.
length
}
className=
{
s
.
submitButton
}
type=
'primary'
onClick=
{
onStepChange
}
>
{
t
(
'datasetCreation.stepOne.button'
)
}
</
Button
>
</>
...
...
web/app/components/datasets/create/step-two/index.tsx
View file @
2b9f394a
...
...
@@ -6,9 +6,10 @@ import { useBoolean } from 'ahooks'
import
{
XMarkIcon
}
from
'@heroicons/react/20/solid'
import
cn
from
'classnames'
import
Link
from
'next/link'
import
{
groupBy
}
from
'lodash-es'
import
PreviewItem
from
'./preview-item'
import
s
from
'./index.module.css'
import
type
{
CreateDocumentReq
,
DataSourceType
,
File
,
FullDocumentDetail
,
FileIndexingEstimateResponse
as
IndexingEstimateResponse
,
PreProcessingRule
,
Rules
,
createDocumentResponse
}
from
'@/models/datasets'
import
type
{
CreateDocumentReq
,
File
,
FullDocumentDetail
,
FileIndexingEstimateResponse
as
IndexingEstimateResponse
,
NotionInfo
,
PreProcessingRule
,
Rules
,
createDocumentResponse
}
from
'@/models/datasets'
import
{
createDocument
,
createFirstDocument
,
...
...
@@ -20,6 +21,10 @@ import Loading from '@/app/components/base/loading'
import
Toast
from
'@/app/components/base/toast'
import
{
formatNumber
}
from
'@/utils/format'
import
type
{
DataSourceNotionPage
}
from
'@/models/common'
import
{
DataSourceType
}
from
'@/models/datasets'
type
Page
=
DataSourceNotionPage
&
{
workspace_id
:
string
}
type
StepTwoProps
=
{
isSetting
?:
boolean
...
...
@@ -30,7 +35,7 @@ type StepTwoProps = {
indexingType
?:
string
dataSourceType
:
DataSourceType
file
?:
File
notionPages
?:
any
[]
notionPages
?:
Page
[]
onStepChange
?:
(
delta
:
number
)
=>
void
updateIndexingTypeCache
?:
(
type
:
string
)
=>
void
updateResultCache
?:
(
res
:
createDocumentResponse
)
=>
void
...
...
@@ -56,6 +61,7 @@ const StepTwo = ({
indexingType
,
dataSourceType
,
file
,
notionPages
,
onStepChange
,
updateIndexingTypeCache
,
updateResultCache
,
...
...
@@ -188,6 +194,30 @@ const StepTwo = ({
return
params
}
const
getNotionInfo
=
()
=>
{
const
workspacesMap
=
groupBy
(
notionPages
,
'workspace_id'
)
const
workspaces
=
Object
.
keys
(
workspacesMap
).
map
((
workspaceId
)
=>
{
return
{
workspaceId
,
pages
:
workspacesMap
[
workspaceId
],
}
})
return
workspaces
.
map
((
workspace
)
=>
{
return
{
workspace_id
:
workspace
.
workspaceId
,
pages
:
workspace
.
pages
.
map
((
page
)
=>
{
const
{
page_id
,
page_name
,
page_icon
,
type
}
=
page
return
{
page_id
,
page_name
,
page_icon
,
type
,
}
}),
}
})
as
NotionInfo
[]
}
const
getCreationParams
=
()
=>
{
let
params
if
(
isSetting
)
{
...
...
@@ -200,14 +230,21 @@ const StepTwo = ({
params
=
{
data_source
:
{
type
:
dataSourceType
,
// name: file?.name,
info
:
[{
upload_file_id
:
file
?.
id
,
}],
info_list
:
{
data_source_type
:
dataSourceType
,
},
},
indexing_technique
:
getIndexing_technique
(),
process_rule
:
getProcessRule
(),
}
as
CreateDocumentReq
if
(
dataSourceType
===
DataSourceType
.
FILE
)
{
params
.
data_source
.
info_list
.
file_info_list
=
{
// TODO multi files
file_ids
:
[
file
?.
id
||
''
],
}
}
if
(
dataSourceType
===
DataSourceType
.
NOTION
)
params
.
data_source
.
info_list
.
notion_info_list
=
getNotionInfo
()
}
return
params
}
...
...
web/app/components/datasets/documents/index.tsx
View file @
2b9f394a
...
...
@@ -19,6 +19,7 @@ import { useDatasetDetailContext } from '@/context/dataset-detail'
import
{
NotionPageSelectorModal
}
from
'@/app/components/base/notion-page-selector'
import
type
{
DataSourceNotionPage
}
from
'@/models/common'
import
type
{
CreateDocumentReq
}
from
'@/models/datasets'
import
{
DataSourceType
}
from
'@/models/datasets'
// Custom page count is not currently supported.
const
limit
=
15
...
...
@@ -95,7 +96,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
const
total
=
documentsRes
?.
total
||
0
const
routeToDocCreate
=
()
=>
{
if
(
dataset
?.
data_source_type
===
'notion_import'
)
{
if
(
dataset
?.
data_source_type
===
DataSourceType
.
NOTION
)
{
setNotionPageSelectorModalVisible
(
true
)
return
}
...
...
web/models/datasets.ts
View file @
2b9f394a
...
...
@@ -13,7 +13,7 @@ export type DataSet = {
icon_background
:
string
description
:
string
permission
:
'only_me'
|
'all_team_members'
data_source_type
:
'upload_file'
data_source_type
:
DataSourceType
indexing_technique
:
'high_quality'
|
'economy'
created_by
:
string
updated_by
:
string
...
...
@@ -169,13 +169,23 @@ export type CreateDocumentReq = {
}
export
type
DataSource
=
{
type
:
string
// name: string
info
:
Info
[]
// upload_file_id
type
:
DataSourceType
info_list
:
{
data_source_type
:
DataSourceType
notion_info_list
?:
NotionInfo
[]
file_info_list
?:
{
file_ids
:
string
[]
}
}
}
export
type
Info
=
{
upload_file_id
:
string
export
type
NotionInfo
=
{
workspace_id
:
string
pages
:
NotionPage
[]
}
export
type
NotionPage
=
{
page_id
:
string
type
:
string
}
export
type
ProcessRule
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment