Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ts-sc-client 0.5.0 #28

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 16 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"classnames": "^2.3.2",
"nanoid": "^4.0.2",
"normalize.css": "^8.0.1",
"ostis-ui-lib": "^0.1.1",
"ostis-ui-lib": "^0.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4",
Expand Down
2 changes: 1 addition & 1 deletion src/api/requests/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { API_URL } from '@constants';
import { objectToFormData } from '@utils';

interface IDoComandResult {
question: number;
action: number;
}

export const doCommand = (cmdAddr: number, ...args: number[]) => {
Expand Down
52 changes: 26 additions & 26 deletions src/api/requests/decomposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ interface IDecompositionItem {
}

const getLanguage = async (lang: TLanguage) => {
const keynodes = await scUtils.findKeynodes(langToKeynode[lang]);
const keynodes = await scUtils.searchKeynodes(langToKeynode[lang]);
return keynodes[snakeToCamelCase(langToKeynode[lang])];
};

export const getDecomposition = async (lang: TLanguage): Promise<Decomposition | null> => {
const LEVEL = '10';

const { uiStartScElement, uiMenuViewGetDecomposition, nrelSectionDecomposition } =
await scUtils.findKeynodes(
await scUtils.searchKeynodes(
'ui_start_sc_element',
'ui_menu_view_get_decomposition',
'nrel_section_decomposition',
);

const subjectDomainAlias = '_subjDomain';
const subjectDomainTemplate = new ScTemplate();
subjectDomainTemplate.triple(uiStartScElement, ScType.EdgeAccessVarPosPerm, [
ScType.NodeVar,
subjectDomainTemplate.triple(uiStartScElement, ScType.VarPermPosArc, [
ScType.VarNode,
subjectDomainAlias,
]);

const subjectDomainRes = await client.templateSearch(subjectDomainTemplate);
const subjectDomainRes = await client.searchByTemplate(subjectDomainTemplate);

if (!subjectDomainRes.length) return null;

const subjDomainAddr = subjectDomainRes[0].get(subjectDomainAlias);

const constr = new ScConstruction();
constr.createLink(ScType.LinkConst, new ScLinkContent(LEVEL, ScLinkContentType.String));
constr.generateLink(ScType.ConstNodeLink, new ScLinkContent(LEVEL, ScLinkContentType.String));

const [linkAddr] = await client.createElements(constr);
const [linkAddr] = await client.generateElements(constr);

const foundLang = await getLanguage(lang);

Expand All @@ -61,20 +61,20 @@ export const getDecomposition = async (lang: TLanguage): Promise<Decomposition |
nrelSectionDecomposition.value,
);

//Добавить вызов тоста
// Добавить вызов тоста
if (isAxiosError(commandResult)) {
return null;
}

const questionNode = commandResult.data.question;
const answer = await scUtils.getAnswer(new ScAddr(questionNode));
const actionNode = commandResult.data.action;
const result = await scUtils.getResult(new ScAddr(actionNode));

if (!answer) return null;
if (!result) return null;

const targetLinkAlias = '_targetLink';
const linkTemplate = new ScTemplate();
linkTemplate.triple(answer, ScType.EdgeAccessVarPosPerm, [ScType.LinkVar, targetLinkAlias]);
const linkRes = await client.templateSearch(linkTemplate);
linkTemplate.triple(result, ScType.VarPermPosArc, [ScType.VarNodeLink, targetLinkAlias]);
const linkRes = await client.searchByTemplate(linkTemplate);

if (!linkRes.length) return null;

Expand Down Expand Up @@ -105,25 +105,25 @@ export const deleteDecompositionItem = (parentID: string, id: string) => {
export const editDecompositionItem = async (addr: number, newContent: string, lang: TLanguage) => {
const linkAlias = '_link';

const { nrelMainIdtf, ...rest } = await scUtils.findKeynodes(
const { nrelMainIdtf, ...rest } = await scUtils.searchKeynodes(
'nrel_main_idtf',
langToKeynode[lang],
);

const foundLang = rest[snakeToCamelCase(langToKeynode[lang])];

const scTemplate = new ScTemplate();
scTemplate.tripleWithRelation(
scTemplate.quintuple(
new ScAddr(addr),
ScType.EdgeDCommonVar,
[ScType.LinkVar, linkAlias],
ScType.EdgeAccessVarPosPerm,
ScType.VarCommonArc,
[ScType.VarNodeLink, linkAlias],
ScType.VarPermPosArc,
nrelMainIdtf,
);

scTemplate.triple(foundLang, ScType.EdgeAccessVarPosPerm, linkAlias);
scTemplate.triple(foundLang, ScType.VarPermPosArc, linkAlias);

const result = await client.templateSearch(scTemplate);
const result = await client.searchByTemplate(scTemplate);

if (result.length) {
client.setLinkContents([
Expand All @@ -132,22 +132,22 @@ export const editDecompositionItem = async (addr: number, newContent: string, la
return true;
}

const link = await scUtils.createLink(newContent);
const link = await scUtils.generateLink(newContent);

if (!link) return;

const template = new ScTemplate();

template.tripleWithRelation(
template.quintuple(
new ScAddr(addr),
ScType.EdgeDCommonVar,
ScType.VarCommonArc,
link,
ScType.EdgeAccessVarPosPerm,
ScType.VarPermPosArc,
nrelMainIdtf,
);
template.triple(foundLang, ScType.EdgeAccessVarPosPerm, link);
template.triple(foundLang, ScType.VarPermPosArc, link);

const generateRes = await client.templateGenerate(template);
const generateRes = await client.generateByTemplate(template);

return !!generateRes;
};
Loading