Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add attachment policy and group selection component to formkit (#…
…4258) #### What type of PR is this? /kind feature /area console #### What this PR does / why we need it: 为 formkit 添加一个 `attachmentPolicySelect` 类型的下拉选择框组件,用来供用户选择附件策略。 同时也添加了一个 `attachmentGroupSelect` 类型的下拉选择框组件,用来供用户选择附件分组。 #### Which issue(s) this PR fixes: Fixes #4247 #### Special notes for your reviewer: 使用 formkit 组件时将 type 修改为 `attachmentPolicySelect` 或 `attachmentGroupSelect`,查看是否能够展示一个可以选择附件策略或附件分组的组件, #### Does this PR introduce a user-facing change? ```release-note None ```
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { apiClient } from "@/utils/api-client"; | ||
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core"; | ||
import { select, selects, defaultIcon } from "@formkit/inputs"; | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
const { data } = | ||
await apiClient.extension.storage.group.liststorageHaloRunV1alpha1Group({ | ||
labelSelector: ["!halo.run/hidden"], | ||
}); | ||
|
||
node.props.options = data.items.map((group) => { | ||
return { | ||
value: group.metadata.name, | ||
label: group.spec.displayName, | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
export const attachmentGroupSelect: FormKitTypeDefinition = { | ||
...select, | ||
props: ["placeholder"], | ||
forceTypeProp: "select", | ||
features: [optionsHandler, selects, defaultIcon("select", "select")], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { apiClient } from "@/utils/api-client"; | ||
import type { FormKitNode, FormKitTypeDefinition } from "@formkit/core"; | ||
import { select, selects, defaultIcon } from "@formkit/inputs"; | ||
|
||
function optionsHandler(node: FormKitNode) { | ||
node.on("created", async () => { | ||
const { data } = | ||
await apiClient.extension.storage.policy.liststorageHaloRunV1alpha1Policy(); | ||
|
||
node.props.options = data.items.map((policy) => { | ||
return { | ||
value: policy.metadata.name, | ||
label: policy.spec.displayName, | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
export const attachmentPolicySelect: FormKitTypeDefinition = { | ||
...select, | ||
props: ["placeholder"], | ||
forceTypeProp: "select", | ||
features: [optionsHandler, selects, defaultIcon("select", "select")], | ||
}; |