2022-04-16 23:49:50 +08:00
import { css } from "@emotion/css" ;
import { useForm } from "@formily/react" ;
2022-06-29 23:42:03 +08:00
import { useCollectionFilterOptions } from "@nocobase/client" ;
2022-11-11 23:37:41 +08:00
import { NAMESPACE } from "../locale" ;
2022-04-16 23:49:50 +08:00
export const collection = {
type : 'string' ,
2022-04-30 10:06:25 +08:00
title : '{{t("Collection")}}' ,
2022-04-27 10:31:16 +08:00
name : 'config.collection' ,
2022-04-16 23:49:50 +08:00
required : true ,
'x-reactions' : [ '{{useCollectionDataSource()}}' ] ,
'x-decorator' : 'FormItem' ,
'x-component' : 'Select' ,
2022-06-10 23:27:35 +08:00
'x-component-props' : {
placeholder : '{{t("Select collection")}}'
}
2022-04-16 23:49:50 +08:00
} ;
export const values = {
type : 'object' ,
2022-04-30 15:44:03 +08:00
title : '{{t("Fields values")}}' ,
2022-04-27 10:31:16 +08:00
name : 'config.params.values' ,
2022-04-16 23:49:50 +08:00
'x-decorator' : 'FormItem' ,
'x-decorator-props' : {
labelAlign : 'left' ,
className : css `
flex - direction : column ;
`
} ,
2022-04-30 15:44:03 +08:00
'x-component' : 'CollectionFieldset' ,
2022-11-11 23:37:41 +08:00
description : ` {{t("Fields that are not assigned a value will be set to the default value, and those that do not have a default value are set to null.", { ns: " ${ NAMESPACE } " })}} ` ,
2022-04-16 23:49:50 +08:00
} ;
export const filter = {
type : 'object' ,
2022-04-30 10:06:25 +08:00
title : '{{t("Filter")}}' ,
2022-04-27 10:31:16 +08:00
name : 'config.params.filter' ,
2022-04-16 23:49:50 +08:00
'x-decorator' : 'FormItem' ,
'x-decorator-props' : {
labelAlign : 'left' ,
className : css `
flex - direction : column ;
`
} ,
'x-component' : 'Filter' ,
'x-component-props' : {
useProps() {
const { values } = useForm ( ) ;
2022-04-28 10:18:44 +08:00
const options = useCollectionFilterOptions ( values . config ? . collection ) ;
2022-04-16 23:49:50 +08:00
return {
options ,
className : css `
position : relative ;
width : 100 % ;
`
} ;
} ,
dynamicComponent : 'VariableComponent'
}
} ;