diff --git a/spectre-api/src/main/kotlin/io/github/vudsen/spectre/api/service/ToolchainService.kt b/spectre-api/src/main/kotlin/io/github/vudsen/spectre/api/service/ToolchainService.kt index 175ea71..3bba6e8 100644 --- a/spectre-api/src/main/kotlin/io/github/vudsen/spectre/api/service/ToolchainService.kt +++ b/spectre-api/src/main/kotlin/io/github/vudsen/spectre/api/service/ToolchainService.kt @@ -2,7 +2,6 @@ package io.github.vudsen.spectre.api.service import io.github.vudsen.spectre.api.dto.ToolchainBundleDTO import io.github.vudsen.spectre.api.dto.ToolchainItemDTO -import io.github.vudsen.spectre.api.vo.ToolchainItemResponseVO import io.github.vudsen.spectre.repo.entity.ToolchainType import io.github.vudsen.spectre.repo.po.ToolchainBundlePO import io.github.vudsen.spectre.repo.po.ToolchainItemId @@ -37,7 +36,7 @@ interface ToolchainService { /** * 更新或者创建工具包 */ - fun updateOrCreateToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO + fun saveToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO /** * 检查包是否缓存到本地. diff --git a/spectre-core/src/main/kotlin/core/controller/ToolchainController.kt b/spectre-core/src/main/kotlin/core/controller/ToolchainController.kt index 985f87d..e859c63 100644 --- a/spectre-core/src/main/kotlin/core/controller/ToolchainController.kt +++ b/spectre-core/src/main/kotlin/core/controller/ToolchainController.kt @@ -3,6 +3,7 @@ package io.github.vudsen.spectre.core.controller import io.github.vudsen.spectre.api.exception.BusinessException import io.github.vudsen.spectre.api.service.ToolchainService import io.github.vudsen.spectre.repo.entity.ToolchainType +import io.github.vudsen.spectre.repo.po.ToolchainBundlePO import io.github.vudsen.spectre.repo.po.ToolchainItemId import io.github.vudsen.spectre.repo.po.ToolchainItemPO import org.springframework.security.access.prepost.PreAuthorize @@ -50,4 +51,10 @@ class ToolchainController( toolchainService.deleteToolchainBundleById(id.toLong()) } + @PostMapping("bundle/update") + @PreAuthorize("hasPermission(null, T(io.github.vudsen.spectre.api.perm.ACLPermissions).TOOL_CHAIN_BUNDLE_UPDATE)") + fun updateToolchainBundle(@Validated @RequestBody po: ToolchainBundlePO) { + toolchainService.saveToolchainBundle(po) + } + } \ No newline at end of file diff --git a/spectre-core/src/main/kotlin/core/controller/ql/ToolchainMutationsController.kt b/spectre-core/src/main/kotlin/core/controller/ql/ToolchainMutationsController.kt index 33a3ad3..9a7dac6 100644 --- a/spectre-core/src/main/kotlin/core/controller/ql/ToolchainMutationsController.kt +++ b/spectre-core/src/main/kotlin/core/controller/ql/ToolchainMutationsController.kt @@ -7,7 +7,6 @@ import io.github.vudsen.spectre.core.vo.ToolchainItemModifyVO import io.github.vudsen.spectre.repo.po.ToolchainBundlePO import io.github.vudsen.spectre.repo.po.ToolchainItemId import io.github.vudsen.spectre.repo.po.ToolchainItemPO -import org.springframework.beans.factory.annotation.Autowired import org.springframework.graphql.data.method.annotation.Argument import org.springframework.graphql.data.method.annotation.MutationMapping import org.springframework.graphql.data.method.annotation.SchemaMapping @@ -42,7 +41,7 @@ class ToolchainMutationsController( fun createToolchainBundle( @Argument @Validated(CreateGroup::class) vo: ToolchainBundleModifyVO ): ToolchainBundlePO { - return toolchainService.updateOrCreateToolchainBundle(ToolchainBundlePO( + return toolchainService.saveToolchainBundle(ToolchainBundlePO( null, vo.name, null, diff --git a/spectre-core/src/main/kotlin/core/service/impl/DefaultToolchainService.kt b/spectre-core/src/main/kotlin/core/service/impl/DefaultToolchainService.kt index 6d418d2..a02bb77 100644 --- a/spectre-core/src/main/kotlin/core/service/impl/DefaultToolchainService.kt +++ b/spectre-core/src/main/kotlin/core/service/impl/DefaultToolchainService.kt @@ -58,7 +58,7 @@ class DefaultToolchainService( return toolchainItemRepository.save(po) } - override fun updateOrCreateToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO { + override fun saveToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO { return toolchainBundleRepository.save(po) } diff --git a/spectre-frontend/src/api/impl/toolchain.ts b/spectre-frontend/src/api/impl/toolchain.ts index 73f6251..aa5c8ba 100644 --- a/spectre-frontend/src/api/impl/toolchain.ts +++ b/spectre-frontend/src/api/impl/toolchain.ts @@ -15,3 +15,15 @@ export const deleteToolchainItem = (vo: DeleteToolchainItemVO) => { export const deleteToolchainBundle = (id: string) => { return axios.post(`toolchain/bundle/delete?id=${id}`) } + +type ToolchainBundlePO = { + id: string + name: string + jattachTag: string + arthasTag: string + httpClientTag: string +} + +export const updateToolchainBundle = (po: ToolchainBundlePO) => { + return axios.post('toolchain/bundle/update', po) +} diff --git a/spectre-frontend/src/components/validation/ControlledSelect.tsx b/spectre-frontend/src/components/validation/ControlledSelect.tsx index 6929b04..4d3cbcd 100644 --- a/spectre-frontend/src/components/validation/ControlledSelect.tsx +++ b/spectre-frontend/src/components/validation/ControlledSelect.tsx @@ -35,7 +35,10 @@ function ControlledSelect( const ks0 = ks as Iterable defaultValue = ks0[Symbol.iterator]().next().value } + } else if (props.control._defaultValues) { + defaultValue = props.control._defaultValues[props.name] } + console.log(props, defaultValue) return ( ( {...field} validationBehavior="aria" isInvalid={fieldState.invalid} + defaultSelectedKeys={defaultValue ? [defaultValue] : undefined} name={props.name} errorMessage={fieldState.error?.message} > diff --git a/spectre-frontend/src/pages/toolchain/bundles/ToolchainBundle.tsx b/spectre-frontend/src/pages/toolchain/bundles/ToolchainBundle.tsx index 7f38628..d6c0d91 100644 --- a/spectre-frontend/src/pages/toolchain/bundles/ToolchainBundle.tsx +++ b/spectre-frontend/src/pages/toolchain/bundles/ToolchainBundle.tsx @@ -19,10 +19,11 @@ import Icon from '@/components/icon/icon.ts' import { graphql } from '@/graphql/generated' import ToolchainBundleModifyDrawerContent from './ToolchainBundleModifyDrawerContent.tsx' import useGraphQL from '@/hook/useGraphQL.ts' -import { formatTime, showDialog } from '@/common/util.ts' +import { showDialog } from '@/common/util.ts' import TableLoadingMask from '@/components/TableLoadingMask.tsx' import type { DocumentResult } from '@/graphql/execute.ts' import { deleteToolchainBundle } from '@/api/impl/toolchain.ts' +import Time from '@/components/Time.tsx' const ToolchainBundleQuery = graphql(` query ToolchainBundleQuery($page: Int, $size: Int) { @@ -50,6 +51,7 @@ const ToolchainBundle: React.FC = () => { page: 0, size: 10, }) + const [selectedEntity, setSelectedEntity] = useState() const { result, isLoading } = useGraphQL(ToolchainBundleQuery, qlArgs) const deleteBundle = useCallback((r: ToolchainBundleResp) => { @@ -71,6 +73,18 @@ const ToolchainBundle: React.FC = () => { const onModified = () => { setQlArgs({ ...qlArgs }) } + + const editBundle = (r: ToolchainBundleResp) => { + setSelectedEntity(r) + console.log(r) + onOpen() + } + + const createNew = () => { + setSelectedEntity(undefined) + onOpen() + } + const bundles = result?.toolchain.toolchainBundles.result ?? [] return (
@@ -86,12 +100,12 @@ const ToolchainBundle: React.FC = () => { className="ml-3 self-end" variant="flat" size="sm" - onPress={onOpen} + onPress={createNew} > + 新增
- +
名称 Arthas @@ -117,11 +131,20 @@ const ToolchainBundle: React.FC = () => { {bundle.httpClientTag} - {formatTime(bundle.createdAt)} + + +