Skip to content

Commit

Permalink
fix checkbox issues
Browse files Browse the repository at this point in the history
  • Loading branch information
debdeep12 committed Sep 26, 2023
1 parent 9089c24 commit 848b0b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions radlab-ui/webapp/src/components/DeleteDeploymentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from "axios"
import { useTranslation } from "next-i18next"
import { useState } from "react"
import { useNavigate } from "react-router-dom"
import { alertStore, userStore } from "@/store"
import { ALERT_TYPE } from "@/utils/types"
import Loading from "@/navigation/Loading"
Expand All @@ -11,15 +10,16 @@ interface IDeleteDeploymentModal {
deployId?: string
deploymentIds?: string[]
handleClick: Function
handleRefresh: Function
}

const DeleteDeploymentModal: React.FC<IDeleteDeploymentModal> = ({
deployId,
deploymentIds,
handleClick,
handleRefresh,
}) => {
const [modal, setModal] = useState(true)
const navigate = useNavigate()
const { t } = useTranslation()
const setAlert = alertStore((state) => state.setAlert)
const [loading, setLoading] = useState(false)
Expand Down Expand Up @@ -48,7 +48,7 @@ const DeleteDeploymentModal: React.FC<IDeleteDeploymentModal> = ({
durationMs: 10000,
type: ALERT_TYPE.SUCCESS,
})
navigate("/deployments")
handleRefresh(true)
} else {
setAlert({
message: t("delete-error"),
Expand Down
21 changes: 19 additions & 2 deletions radlab-ui/webapp/src/components/modules/ModuleDeployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ interface ModuleDeploymentProps {
defaultSortField?: SORT_FIELD
defaultSortDirection?: SORT_DIRECTION
headers: IHeader[]
handleRefresh: Function
}

const ModuleDeployment: React.FC<ModuleDeploymentProps> = ({
deployments,
defaultSortField,
defaultSortDirection,
headers,
handleRefresh,
}) => {
const [sortField, setSortField] = useState<SORT_FIELD>(
defaultSortField || SORT_FIELD.MODULE,
Expand All @@ -44,6 +46,7 @@ const ModuleDeployment: React.FC<ModuleDeploymentProps> = ({
const [isModal, setModal] = useState<boolean>(false)
const { t } = useTranslation()
const [deploymentId, setDeploymentId] = useState<string[]>([])
const [isCheckbox, setIsCheckbox] = useState<number>(0)

const setSort = (header: IHeader) => () => {
if (header.field === sortField) {
Expand Down Expand Up @@ -126,6 +129,7 @@ const ModuleDeployment: React.FC<ModuleDeploymentProps> = ({
<DeleteDeploymentModal
handleClick={handleClick}
deploymentIds={deploymentId}
handleRefresh={handleRefresh}
/>
)
}
Expand All @@ -140,7 +144,19 @@ const ModuleDeployment: React.FC<ModuleDeploymentProps> = ({
}
}

useEffect(() => {}, [deploymentId])
useEffect(() => {
deployments &&
deployments.map((deployment) => {
if (deployment.hasOwnProperty("deletedAt")) {
//@ts-ignore
deployment["status"] = "DELETED"
}
})
const value = deployments?.filter(
(deployment) => deployment.status === DEPLOYMENT_STATUS.SUCCESS,
)
if (value && value.length) setIsCheckbox(value.length)
}, [deploymentId])

return (
<>
Expand Down Expand Up @@ -191,14 +207,15 @@ const ModuleDeployment: React.FC<ModuleDeploymentProps> = ({
/>
</div>
<div className="flex gap-1">
{header.label === "Module" && deploymentId.length > 0 && (
{header.label === "Module" && (
<span className="flex gap-2">
<input
type="checkbox"
//@ts-ignore
checked={
isAllSelect && deploymentId.length && "checked"
}
disabled={!isCheckbox && !deploymentId.length}
className="checkbox checkbox-xs checkbox-primary mt-1"
onChange={() =>
deployments &&
Expand Down
7 changes: 6 additions & 1 deletion radlab-ui/webapp/src/routes/Deployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Deployments: React.FC<DeploymentsProps> = () => {
const setModuleNames = moduleNamesStore((state) => state.setModuleNames)

const [clearFilter, setClearFilter] = useState(false)
const [refresh, setRefresh] = useState(false)

const fetchData = async () => {
Promise.all([
Expand Down Expand Up @@ -104,10 +105,12 @@ const Deployments: React.FC<DeploymentsProps> = () => {
})
}

const handleRefresh = (state: boolean) => setRefresh(state)

useEffect(() => {
fetchData()
fetchModules()
}, [deploymentTab])
}, [deploymentTab, refresh])

const renderAllTab = () => {
return (
Expand Down Expand Up @@ -191,6 +194,7 @@ const Deployments: React.FC<DeploymentsProps> = () => {
deployments={filteredDeployments || listAllDeployments}
defaultSortField={SORT_FIELD.CREATEDAT}
defaultSortDirection={SORT_DIRECTION.DESC}
handleRefresh={handleRefresh}
/>
) : (
renderEmptyState()
Expand All @@ -202,6 +206,7 @@ const Deployments: React.FC<DeploymentsProps> = () => {
deployments={filteredDeployments || listMyDeployments}
defaultSortField={SORT_FIELD.CREATEDAT}
defaultSortDirection={SORT_DIRECTION.DESC}
handleRefresh={handleRefresh}
/>
) : (
renderEmptyState()
Expand Down

0 comments on commit 848b0b2

Please sign in to comment.