skills screen
This commit is contained in:
parent
cac5fad8ce
commit
a920f5fb45
49 changed files with 681 additions and 168 deletions
78
ui/src/features/skills/skills_store.ts
Normal file
78
ui/src/features/skills/skills_store.ts
Normal file
|
@ -0,0 +1,78 @@
|
|||
import makeAutoObservable from "mobx-store-inheritance";
|
||||
import { UiDrawerFormState } from "../../core/store/base_store";
|
||||
import { NavigateFunction } from "react-router-dom";
|
||||
import { HttpError } from "../../core/repository/core_http_repository";
|
||||
import { ParamViewModel, SkillModel } from "../../core/model/skill_model";
|
||||
import { Form } from "../behavior_tree_builder/presentation/ui/forms/forms";
|
||||
import { message } from "antd";
|
||||
import { SkillsHttpRepository } from "./skills_http_repository";
|
||||
export enum DrawersSkills {
|
||||
newSkill = "Новый навык",
|
||||
}
|
||||
export class SkillsStore extends UiDrawerFormState<SkillModel, HttpError> {
|
||||
isModalOpen: boolean = false;
|
||||
activeIndex?: number;
|
||||
viewModel: SkillModel = SkillModel.empty();
|
||||
selectParam?: {
|
||||
form: Form;
|
||||
component?: React.ReactNode;
|
||||
};
|
||||
skills: SkillModel[];
|
||||
skillsHttpRepository: SkillsHttpRepository = new SkillsHttpRepository();
|
||||
|
||||
constructor() {
|
||||
super(DrawersSkills);
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
init = async (navigate?: NavigateFunction | undefined) => {
|
||||
this.mapOk("skills", this.skillsHttpRepository.getAllSkills());
|
||||
};
|
||||
showModal = () => {
|
||||
this.isModalOpen = true;
|
||||
};
|
||||
|
||||
handleOk = () => {
|
||||
this.isModalOpen = false;
|
||||
};
|
||||
|
||||
handleCancel = () => {
|
||||
this.isModalOpen = false;
|
||||
};
|
||||
addNewParam = (index: number) => {
|
||||
this.activeIndex = index;
|
||||
this.showModal();
|
||||
};
|
||||
onChangeBtDependency = (dependency: Object) =>
|
||||
this.viewModel.BTAction.at(this.activeIndex ?? 0)
|
||||
?.validParam(this.selectParam?.form ?? "")
|
||||
.fold(
|
||||
() => {
|
||||
this.updateForm({
|
||||
BTAction: this.viewModel.BTAction.replacePropIndex(
|
||||
{
|
||||
param: this.viewModel.BTAction.at(this.activeIndex ?? 0)?.param.add(
|
||||
new ParamViewModel(this.selectParam?.form ?? "", dependency)
|
||||
),
|
||||
},
|
||||
this.activeIndex ?? 0
|
||||
),
|
||||
});
|
||||
this.handleCancel();
|
||||
},
|
||||
() => {
|
||||
message.error(`${this.selectParam?.form} is filled`);
|
||||
this.handleCancel();
|
||||
}
|
||||
);
|
||||
|
||||
clickParam(el: { form: Form; component: null } | { form: Form; component: React.JSX.Element }): void {
|
||||
this.selectParam = el;
|
||||
if (el.component === null) this.onChangeBtDependency({});
|
||||
}
|
||||
saveNewSkill = async () => {
|
||||
(await this.viewModel.valid<SkillModel>()).fold(
|
||||
async (model) => this.skillsHttpRepository.createNewSkill(model),
|
||||
async (e) => message.error(e)
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue