-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pref: implement business selector using new selector component (#6525)
#### What type of PR is this? /kind improvement /area ui /milestone 2.19.x #### What this PR does / why we need it: 使用 #6473 中重构的 Formkit Select 组件来实现用户、文章、页面等各种业务搜索组件。 Fixes #4931 #### How to test it? 测试各类搜索组件是否正常可用。 测试从旧版本升级后,原有数据是否可以正常显示。 #### Does this PR introduce a user-facing change? ```release-note 使用重构的 Formkit Select 组件来实现业务选择器。 ```
- Loading branch information
Showing
8 changed files
with
225 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core"; | ||
import { defaultIcon, select, selects } from "@formkit/inputs"; | ||
import { coreApiClient } from "@halo-dev/api-client"; | ||
import { select } from "./select"; | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
const { data } = await coreApiClient.storage.policy.listPolicy(); | ||
|
||
node.props.options = data.items.map((policy) => { | ||
return { | ||
value: policy.metadata.name, | ||
label: policy.spec.displayName, | ||
}; | ||
}); | ||
if (node.context) { | ||
node.context.attrs.options = data.items.map((policy) => { | ||
return { | ||
value: policy.metadata.name, | ||
label: policy.spec.displayName, | ||
}; | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export const attachmentPolicySelect: FormKitTypeDefinition = { | ||
...select, | ||
props: ["placeholder"], | ||
forceTypeProp: "nativeSelect", | ||
features: [optionsHandler, selects, defaultIcon("select", "select")], | ||
forceTypeProp: "select", | ||
features: [optionsHandler], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core"; | ||
import { defaultIcon, select, selects } from "@formkit/inputs"; | ||
import { coreApiClient } from "@halo-dev/api-client"; | ||
import { select } from "./select"; | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
const { data } = await coreApiClient.menuItem.listMenuItem({ | ||
fieldSelector: [`name=(${node.props.menuItems.join(",")})`], | ||
}); | ||
|
||
node.props.options = data.items.map((menuItem) => { | ||
return { | ||
value: menuItem.metadata.name, | ||
label: menuItem.status?.displayName, | ||
}; | ||
}); | ||
if (node.context) { | ||
node.context.attrs.options = data.items.map((menuItem) => { | ||
return { | ||
value: menuItem.metadata.name, | ||
label: menuItem.status?.displayName, | ||
}; | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export const menuItemSelect: FormKitTypeDefinition = { | ||
...select, | ||
props: ["placeholder", "menuItems"], | ||
forceTypeProp: "nativeSelect", | ||
features: [optionsHandler, selects, defaultIcon("select", "select")], | ||
forceTypeProp: "select", | ||
features: [optionsHandler], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,65 @@ | ||
import { postLabels } from "@/constants/labels"; | ||
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core"; | ||
import { defaultIcon, select, selects } from "@formkit/inputs"; | ||
import { consoleApiClient } from "@halo-dev/api-client"; | ||
import { select } from "./select"; | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
const { data } = await consoleApiClient.content.post.listPosts({ | ||
labelSelector: [ | ||
`${postLabels.DELETED}=false`, | ||
`${postLabels.PUBLISHED}=true`, | ||
], | ||
}); | ||
async function search({ page, size, keyword }) { | ||
const { data } = await consoleApiClient.content.post.listPosts({ | ||
page, | ||
size, | ||
keyword, | ||
labelSelector: [ | ||
`${postLabels.DELETED}=false`, | ||
`${postLabels.PUBLISHED}=true`, | ||
], | ||
}); | ||
|
||
node.props.options = data.items.map((post) => { | ||
return { | ||
options: data.items.map((post) => { | ||
return { | ||
value: post.post.metadata.name, | ||
label: post.post.spec.title, | ||
}; | ||
}); | ||
}), | ||
total: data.total, | ||
size: data.size, | ||
page: data.page, | ||
}; | ||
} | ||
|
||
async function findOptionsByValues(values: string[]) { | ||
if (values.length === 0) { | ||
return []; | ||
} | ||
|
||
const { data } = await consoleApiClient.content.post.listPosts({ | ||
fieldSelector: [`metadata.name=(${values.join(",")})`], | ||
}); | ||
|
||
return data.items.map((post) => { | ||
return { | ||
value: post.post.metadata.name, | ||
label: post.post.spec.title, | ||
}; | ||
}); | ||
} | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
node.props = { | ||
...node.props, | ||
remote: true, | ||
remoteOption: { | ||
search, | ||
findOptionsByValues, | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
export const postSelect: FormKitTypeDefinition = { | ||
...select, | ||
props: ["placeholder"], | ||
forceTypeProp: "nativeSelect", | ||
features: [optionsHandler, selects, defaultIcon("select", "select")], | ||
forceTypeProp: "select", | ||
features: [optionsHandler], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.