Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,7 +36,7 @@ interface ToolchainService {
/**
* 更新或者创建工具包
*/
fun updateOrCreateToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO
fun saveToolchainBundle(po: ToolchainBundlePO): ToolchainBundlePO

/**
* 检查包是否缓存到本地.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 12 additions & 0 deletions spectre-frontend/src/api/impl/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function ControlledSelect<Values extends FieldValues>(
const ks0 = ks as Iterable<string | number>
defaultValue = ks0[Symbol.iterator]().next().value
}
} else if (props.control._defaultValues) {
defaultValue = props.control._defaultValues[props.name]
}
console.log(props, defaultValue)
return (
<Controller
control={props.control}
Expand All @@ -48,6 +51,7 @@ function ControlledSelect<Values extends FieldValues>(
{...field}
validationBehavior="aria"
isInvalid={fieldState.invalid}
defaultSelectedKeys={defaultValue ? [defaultValue] : undefined}
name={props.name}
errorMessage={fieldState.error?.message}
>
Expand Down
32 changes: 28 additions & 4 deletions spectre-frontend/src/pages/toolchain/bundles/ToolchainBundle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -50,6 +51,7 @@ const ToolchainBundle: React.FC = () => {
page: 0,
size: 10,
})
const [selectedEntity, setSelectedEntity] = useState<ToolchainBundleResp>()
const { result, isLoading } = useGraphQL(ToolchainBundleQuery, qlArgs)

const deleteBundle = useCallback((r: ToolchainBundleResp) => {
Expand All @@ -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 (
<div className="space-y-3">
Expand All @@ -86,12 +100,12 @@ const ToolchainBundle: React.FC = () => {
className="ml-3 self-end"
variant="flat"
size="sm"
onPress={onOpen}
onPress={createNew}
>
+ 新增
</Button>
</div>
<Table removeWrapper>
<Table removeWrapper aria-label="Toolchain bundle">
<TableHeader>
<TableColumn>名称</TableColumn>
<TableColumn>Arthas</TableColumn>
Expand All @@ -117,11 +131,20 @@ const ToolchainBundle: React.FC = () => {
<TableCell>
<Code>{bundle.httpClientTag}</Code>
</TableCell>
<TableCell>{formatTime(bundle.createdAt)}</TableCell>
<TableCell>
<Time time={bundle.createdAt} />
</TableCell>
<TableCell
align="right"
className="relative flex items-center justify-end gap-2"
>
<Button
isIconOnly
variant="light"
onPress={() => editBundle(bundle)}
>
<SvgIcon icon={Icon.EDIT} />
</Button>
<Button
isIconOnly
color="danger"
Expand All @@ -139,6 +162,7 @@ const ToolchainBundle: React.FC = () => {
<DrawerContent>
{(onClose) => (
<ToolchainBundleModifyDrawerContent
oldEntity={selectedEntity}
onClose={onClose}
onModified={onModified}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ import useGraphQL from '@/hook/useGraphQL.ts'
import ControlledInput from '@/components/validation/ControlledInput.tsx'
import { execute } from '@/graphql/execute.ts'
import { handleError } from '@/common/util.ts'
import { updateToolchainBundle } from '@/api/impl/toolchain.ts'

type OldEntity = {
id: string
jattachTag: string
arthasTag: string
httpClientTag: string
}

interface ToolchainBundleModifyDrawerContentProps {
onClose: () => void
oldEntity?: unknown
oldEntity?: OldEntity
onModified: () => void
}

Expand Down Expand Up @@ -77,7 +85,9 @@ const ToolchainBundleModifyDrawerContent: React.FC<
const { isLoading: isVersionsLoading, result } = useGraphQL(
QueryToolchainVersions,
)
const { control, trigger, getValues } = useForm<Values>()
const { control, trigger, getValues } = useForm<Values>({
defaultValues: props.oldEntity,
})
const [isLoading, setLoading] = useState(false)

const arthasVersions = result?.arthas.toolchainItems.result ?? []
Expand All @@ -92,13 +102,24 @@ const ToolchainBundleModifyDrawerContent: React.FC<
setLoading(true)
try {
const values = getValues()
await execute(CreateToolchainBundle, {
vo: values,
})
addToast({
title: '添加成功',
color: 'success',
})
if (props.oldEntity) {
await updateToolchainBundle({
id: props.oldEntity.id,
...values,
})
addToast({
title: '更新成功',
color: 'success',
})
} else {
await execute(CreateToolchainBundle, {
vo: values,
})
addToast({
title: '添加成功',
color: 'success',
})
}
props.onClose()
props.onModified()
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.PrePersist
import jakarta.persistence.Table
import jakarta.validation.constraints.Null
import org.hibernate.annotations.DynamicUpdate
import java.sql.Timestamp

Expand All @@ -17,6 +18,7 @@ data class ToolchainBundlePO(
var id: Long? = null,
var name: String? = null,
@Column(name = "created_at", updatable = false, insertable = false)
@Null
var createdAt: Timestamp? = null,
var jattachTag: String? = null,
var arthasTag: String? = null,
Expand Down