-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
284 additions
and
2 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,67 @@ | ||
import Button from "@/components/shared/Button/Button"; | ||
import { getDecimalPlace } from "@/helpers/number"; | ||
import { parsingRoute } from "@/helpers/route"; | ||
import { IPredict } from "@/interfaces/responses/Result"; | ||
import { Routes } from "@/routes/routes"; | ||
import { EyeOutlined } from "@ant-design/icons"; | ||
import { Modal, Space, Table } from "antd"; | ||
import { ColumnsType } from "antd/es/table"; | ||
import React from "react"; | ||
|
||
interface IProps { | ||
open: boolean; | ||
closeModal: () => void; | ||
dataPredict: IPredict; | ||
} | ||
|
||
const ModalResultPredict: React.FC<IProps> = ({ | ||
open, | ||
closeModal, | ||
dataPredict, | ||
}) => { | ||
const footer = ( | ||
<Space> | ||
<Button onClick={closeModal}>Close</Button> | ||
<Button | ||
icon={<EyeOutlined />} | ||
href={parsingRoute(Routes.ResultDetail, { | ||
id: dataPredict?.resultId, | ||
})} | ||
> | ||
See Detail | ||
</Button> | ||
</Space> | ||
); | ||
|
||
const columns: ColumnsType = [ | ||
{ | ||
title: "Variable Output", | ||
dataIndex: "variableOutputName", | ||
}, | ||
{ | ||
title: "Value", | ||
dataIndex: "value", | ||
render: (value) => getDecimalPlace(value, 3), | ||
}, | ||
]; | ||
|
||
return ( | ||
<Modal | ||
open={open} | ||
centered | ||
closable={false} | ||
title={`Result predict for ${dataPredict?.name}`} | ||
footer={footer} | ||
> | ||
<Table | ||
bordered | ||
pagination={false} | ||
size="small" | ||
dataSource={dataPredict?.predict} | ||
columns={columns} | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ModalResultPredict; |
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,4 @@ | ||
export interface IPredictRequest { | ||
name: string; | ||
dataInput: { variableInputId: number; value: number }[]; | ||
} |
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,152 @@ | ||
import { Breadcrumbs } from "@/common/breadcrumb"; | ||
import ModalResultPredict from "@/components/modules/Result/ModalResultPredict"; | ||
import Button from "@/components/shared/Button/Button"; | ||
import ButtonAction from "@/components/shared/Form/ButtonActions"; | ||
import LoaderCenter from "@/components/shared/Loader/LoaderCenter"; | ||
import { getRequiredMessage } from "@/helpers/form"; | ||
import { modalConfirm } from "@/helpers/modal-confirm"; | ||
import { useFormUtility } from "@/hooks/useFormUtility"; | ||
import { IPredictRequest } from "@/interfaces/requests/Result"; | ||
import { IPredict } from "@/interfaces/responses/Result"; | ||
import MainLayout from "@/layouts/MainLayout"; | ||
import { Routes } from "@/routes/routes"; | ||
import { useResultPredictMutation } from "@/services/mutation/Result"; | ||
import { useVariableInputQueryIndex } from "@/services/query/VariableInput"; | ||
import { Card, Flex, Form, Input, InputNumber } from "antd"; | ||
import React from "react"; | ||
import * as yup from "yup"; | ||
|
||
const schema = yup.object().shape({ | ||
name: yup.string().required(getRequiredMessage("Name")), | ||
dataInput: yup | ||
.array() | ||
.of( | ||
yup.object().shape({ | ||
variableInputId: yup | ||
.number() | ||
.required(getRequiredMessage("Variable Input")) | ||
.defined(), | ||
value: yup | ||
.number() | ||
.required(getRequiredMessage("Value")) | ||
.defined(), | ||
}) | ||
) | ||
.required(), | ||
}); | ||
|
||
const ResultCreate: React.FC = () => { | ||
const { form, yupSync } = useFormUtility({ schema }); | ||
const queryVariableInput = useVariableInputQueryIndex(); | ||
|
||
const [openModalResultPredict, setOpenModalResultPredict] = | ||
React.useState(false); | ||
const [resultPredict, setResultPredict] = React.useState<IPredict>(null); | ||
|
||
const mutationPredict = useResultPredictMutation({ | ||
onSuccess: ({ data }) => { | ||
setOpenModalResultPredict(true); | ||
setResultPredict(data); | ||
}, | ||
}); | ||
|
||
const closeModal = () => { | ||
setOpenModalResultPredict(false); | ||
setResultPredict(null); | ||
}; | ||
|
||
const onFinish = async () => { | ||
await form.validateFields(); | ||
modalConfirm({ | ||
onOk: () => { | ||
const dataSubmitted = form.getFieldsValue(); | ||
mutationPredict.mutate(dataSubmitted as IPredictRequest); | ||
}, | ||
}); | ||
}; | ||
|
||
const getLabelOutput = (idContext) => { | ||
return queryVariableInput?.data?.data?.find( | ||
({ id }) => id === idContext | ||
)?.name; | ||
}; | ||
|
||
const formListDataInput = ( | ||
<Form.List name="dataInput"> | ||
{(fields) => | ||
fields.map((field) => ( | ||
<React.Fragment key={field.key}> | ||
<Form.Item | ||
required | ||
label={getLabelOutput( | ||
form.getFieldValue([ | ||
"dataInput", | ||
field.name, | ||
"variableInputId", | ||
]) | ||
)} | ||
name={[field.name, "value"]} | ||
rules={[yupSync]} | ||
> | ||
<InputNumber /> | ||
</Form.Item> | ||
<Form.Item | ||
name={[field.name, "variableInputId"]} | ||
></Form.Item> | ||
</React.Fragment> | ||
)) | ||
} | ||
</Form.List> | ||
); | ||
|
||
return ( | ||
<MainLayout title="Predict" breadcrumbs={Breadcrumbs.Result.Create()}> | ||
<Card> | ||
{queryVariableInput.isLoading || | ||
queryVariableInput.isFetching ? ( | ||
<LoaderCenter /> | ||
) : ( | ||
<Form | ||
form={form} | ||
onFinish={onFinish} | ||
initialValues={{ | ||
name: "", | ||
dataInput: queryVariableInput?.data?.data?.map( | ||
({ id }) => ({ variableInputId: id, value: 0 }) | ||
), | ||
}} | ||
> | ||
<Form.Item | ||
required | ||
label="Name" | ||
name="name" | ||
rules={[yupSync]} | ||
> | ||
<Input /> | ||
</Form.Item> | ||
<Flex wrap="wrap" style={{ columnGap: "1rem" }}> | ||
{formListDataInput} | ||
</Flex> | ||
<ButtonAction | ||
actions={[ | ||
<Button href={Routes.ResultIndex}> | ||
Cancel | ||
</Button>, | ||
<Button type="primary" htmlType="submit"> | ||
Predict | ||
</Button>, | ||
]} | ||
/> | ||
</Form> | ||
)} | ||
</Card> | ||
<ModalResultPredict | ||
open={openModalResultPredict} | ||
closeModal={closeModal} | ||
dataPredict={resultPredict} | ||
/> | ||
</MainLayout> | ||
); | ||
}; | ||
|
||
export default ResultCreate; |
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
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,19 @@ | ||
import { IPredictRequest } from "@/interfaces/requests/Result"; | ||
import { IResultPredictResponse } from "@/interfaces/responses/Result"; | ||
import { IBaseResponse } from "@/interfaces/responses/base"; | ||
import { resultPredict } from "@/services/apis/Result"; | ||
import { UseMutationOptions, useMutation } from "@tanstack/react-query"; | ||
|
||
export const useResultPredictMutation = ( | ||
options?: UseMutationOptions< | ||
IResultPredictResponse, | ||
IBaseResponse<unknown>, | ||
IPredictRequest | ||
> | ||
) => { | ||
return useMutation({ | ||
mutationKey: ["result-predict"], | ||
mutationFn: (payload) => resultPredict(payload), | ||
...options, | ||
}); | ||
}; |