Skip to content

Commit

Permalink
Merge pull request #177 from anjanaw/dev
Browse files Browse the repository at this point in the history
methods update
  • Loading branch information
anjanaw authored Feb 7, 2024
2 parents 59741eb + bb1fd9d commit c4696ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
78 changes: 41 additions & 37 deletions src/components/iSee/persona/PersonaIntents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,52 +235,56 @@ const PersonaIntents: React.FC<PersonaType> = (props) => {
};

useEffect(() => {
const handleVisibilityChange = () => {
const handleVisibilityChange = async () => {
if (document.visibilityState === 'visible' && chosenStrategy?.tree !== "" && chosenStrategy?.tree !== undefined) {
const hide = message.loading(
'Updating explanation strategies from the Explanation Experience Editor!',
0,
);
const data = await refresh_reuse_cases(usecaseId, chosenStrategy.tree);

const methods = data.methods;
const applicabilities = data.applicabilities;
let selectedIntent: PersonaIntent = {
id: "",
completed: false,
name: "",
evaluation: {}
};

refresh_reuse_cases(chosenStrategy.tree).then(methods => {


let selectedIntent: PersonaIntent = {
id: "",
completed: false,
name: "",
evaluation: {}
};

let intent_idx = 0;
personaState?.intents?.forEach((intent_, i) => {
intent_.strategies?.forEach((strat) => {
if (strat.id == chosenStrategy?.id) {
selectedIntent = intent_;
intent_idx = i;
}
})
});

const UPDATED_STRATEGIES = personaState.intents?.[intent_idx].strategies?.map((s) => {
if (s.tree === chosenStrategy.tree) {
s.methods = methods;
let intent_idx = 0;
personaState?.intents?.forEach((intent_, i) => {
intent_.strategies?.forEach((strat) => {
if (strat.id == chosenStrategy?.id) {
selectedIntent = intent_;
intent_idx = i;
}
return s;
});

const UPDATED_INTENTS = personaState.intents;
})
});

if (typeof UPDATED_INTENTS !== "undefined") {
UPDATED_INTENTS[intent_idx].strategies = UPDATED_STRATEGIES;
const UPDATED_STRATEGIES = personaState.intents?.[intent_idx].strategies?.map((s) => {
if (s.tree === chosenStrategy.tree) {
s.methods = methods;
s.applicabilities = applicabilities;
}
return s;
});

const UPDATED_INTENTS = personaState.intents;

selectedIntent.strategies = UPDATED_STRATEGIES;
if (typeof UPDATED_INTENTS !== "undefined") {
UPDATED_INTENTS[intent_idx].strategies = UPDATED_STRATEGIES;
}

api_persona_update_intent(usecaseId, personaState._id, selectedIntent.id, selectedIntent).then(res => {
selectedIntent.strategies = UPDATED_STRATEGIES;

const PERSONA_IDX = personas.findIndex(p => p._id === persona._id);
setPersonaState(res.personas[PERSONA_IDX]);
});
api_persona_update_intent(usecaseId, personaState._id, selectedIntent.id, selectedIntent).then(res => {

const PERSONA_IDX = personas.findIndex(p => p._id === persona._id);
setPersonaState(res.personas[PERSONA_IDX]);
});

hide();
}
};

Expand Down Expand Up @@ -401,7 +405,7 @@ const PersonaIntents: React.FC<PersonaType> = (props) => {
key: 'select',
render: (_: any, strategy: any) =>
(<Switch
disabled={isDisabled(strategy.applicabilities)}
disabled={isDisabled(strategy.applicabilities || {})}
checked={strategy.selected}
onClick={(event) => setSelectedStrategy(event, strategy)}
checkedChildren={<CheckOutlined />}
Expand Down Expand Up @@ -500,7 +504,7 @@ const PersonaIntents: React.FC<PersonaType> = (props) => {
</Button>
</p>
<p style={{ marginTop: -10 }}>
<Button block onClick={() => openEditor(strategy, usecaseId)} target="_blank" type="dashed" shape="round" icon={<EditOutlined />} >
<Button block danger={isDisabled(strategy.applicabilities || {})} onClick={() => openEditor(strategy, usecaseId)} target="_blank" type="dashed" shape="round" icon={<EditOutlined />} >
Edit
</Button>
</p></>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chatbot/DialogQuestionnaires.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ const DialogQuestionnaires: React.FC<Params> = (props) => {
onClick={sendAndReceive}
disabled={
(text == '' && responseType == ResponseType.NUMBER) ||
(words(text) < 100 && responseType == ResponseType.OPEN) ||
(words(text) < 1 && responseType == ResponseType.OPEN) ||
(!check && responseType == ResponseType.CHECK) ||
(!radio && responseType == ResponseType.RADIO) ||
(!likert && responseType == ResponseType.LIKERT) ||
Expand Down
10 changes: 7 additions & 3 deletions src/services/isee/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ export const open_editor_with_token = async (strategy: string, usecaseId: string
}
};

export const refresh_reuse_cases = async (strategy: string) => {
export const refresh_reuse_cases = async (usecase: string, strategy: string) => {
try {
const STRATEGY_URL = `${BASE_URL}/trees/Projects/${strategy}/methods`;
const STRATEGY_URL = `${BASE_URL}/trees/Projects/methods`;
const data = await fetch(STRATEGY_URL, {
method: 'GET',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-access-token': getToken()
},
body: JSON.stringify({
usecaseId: usecase,
treeId: strategy
})
});
const result = await data.json();
return result || [];
Expand Down

0 comments on commit c4696ce

Please sign in to comment.