Skip to content

Commit

Permalink
Add intents with rule page (#626)
Browse files Browse the repository at this point in the history
* chore: Update readme #804

* chore: Add domain constant #804

* chore: add intents with rule #804

* chore: adjust readme #804

* feat: move intents with rule to regular intents page #804

* feat: adjust response card #804

* feat: move response adding card out of examples table, initial response adding logic #804

* feat: Axios interceptor now handles 409 via translations

* chore: Update readme #804

* chore: Add domain constant #804

* chore: add intents with rule #804

* chore: adjust readme #804

* feat: move intents with rule to regular intents page #804

* feat: adjust response card #804

* feat: move response adding card out of examples table, initial response adding logic #804

* feat: intent response querying #804

* feat: response, rule adding #804

* feat: display intent response, id based queryRefresh #804

* chore: include howler in gui vite config #804

* chore: fix typo, add timestamp example for cookie #804

* feat: find selectedintent by id #804

* feat: find common intent by id, queryparam #804

* feat: remove title from intent type #804

* feat: add rules #804

* feat: remove intent with rule #804

* feat: usememo for examples in intents component #804

* feat: move example usememo into intents component, wip response editing #804

* feat: editing intent name creates new rule and response #804

* feat: mutateAsync #804

* feat: PR changes, remove comments, also copy intent param logic from common intents, add translation #804

---------

Co-authored-by: karlerik.hein <karlerik.hein@netgroup.com>
  • Loading branch information
joonasroosalung and karlerik.hein authored Aug 15, 2024
1 parent b81110d commit a7d954c
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 197 deletions.
2 changes: 1 addition & 1 deletion GUI/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ REACT_APP_NODE_ENV=development
REACT_APP_PUBLIC_URL=http://proto.we.ee/
REACT_APP_RUUTER_URL=http://localhost:8080/
REACT_APP_ENABLE_HIDDEN_FEATURES=TRUE
REACT_APP_MENU_JSON=[{"id":"conversations","label":{"et":"Vestlused","en":"Conversations"},"path":"/chat","children":[{"label":{"et":"Vastamata","en":"Unanswered"},"path":"/unanswered"},{"label":{"et":"Aktiivsed","en":"Active"},"path":"/active"},{"label":{"et":"Ajalugu","en":"History"},"path":"/history"}]},{"id":"training","label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Treening","en":"Training"},"path":"/training","children":[{"label":{"et":"Teemad","en":"Themes"},"path":"/training/intents"},{"label":{"et":"Avalikud teemad","en":"Public themes"},"path":"/training/common-intents"},{"label":{"et":"Teemade järeltreenimine","en":"Post training themes"},"path":"/training/intents-followup-training"},{"label":{"et":"Vastused","en":"Answers"},"path":"/training/responses"},{"label":{"et":"Kasutuslood","en":"User Stories"},"path":"/training/stories"},{"label":{"et":"Konfiguratsioon","en":"Configuration"},"path":"/training/configuration"},{"label":{"et":"Vormid","en":"Forms"},"path":"/training/forms"},{"label":{"et":"Mälukohad","en":"Slots"},"path":"/training/slots"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"}]},{"label":{"et":"Ajaloolised vestlused","en":"Historical conversations"},"path":"/history","children":[{"label":{"et":"Ajalugu","en":"History"},"path":"/history/history"},{"label":{"et":"Pöördumised","en":"Appeals"},"path":"/history/appeal"}]},{"label":{"et":"Mudelipank ja analüütika","en":"Modelbank and analytics"},"path":"/analytics","children":[{"label":{"et":"Teemade ülevaade","en":"Overview of topics"},"path":"/analytics/overview"},{"label":{"et":"Mudelite võrdlus","en":"Comparison of models"},"path":"/analytics/models"},{"label":{"et":"Testlood","en":"testTracks"},"path":"/analytics/testcases"}]},{"label":{"et":"Treeni uus mudel","en":"Train new model"},"path":"/train-new-model"}]},{"id":"analytics","label":{"et":"Analüütika","en":"Analytics"},"path":"/analytics","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Vestlused","en":"Chats"},"path":"/chats"},{"label":{"et":"Bürokratt","en":"Burokratt"},"path":"/burokratt"},{"label":{"et":"Tagasiside","en":"Feedback"},"path":"/feedback"},{"label":{"et":"Nõustajad","en":"Advisors"},"path":"/advisors"},{"label":{"et":"Avaandmed","en":"Reports"},"path":"/reports"}]},{"id":"services","label":{"et":"Teenused","en":"Services"},"path":"/services","children":[{"label":{"et":"Ülevaade","en":"Overview"},"path":"/overview"},{"label":{"et":"Uus teenus","en":"New Service"},"path":"/newService"},{"label":{"et":"Automatic Teenused","en":"Automatic Services"},"path":"/auto-services"},{"label":{"et":"Probleemsed teenused","en":"Faulty Services"},"path":"/faultyServices"}]},{"id":"settings","label":{"et":"Haldus","en":"Administration"},"path":"/settings","children":[{"label":{"et":"Kasutajad","en":"Users"},"path":"/users"},{"label":{"et":"Vestlusbot","en":"Chatbot"},"path":"/chatbot","children":[{"label":{"et":"Seaded","en":"Settings"},"path":"/chatbot/settings"},{"label":{"et":"Tervitussõnum","en":"Welcome message"},"path":"/chatbot/welcome-message"},{"label":{"et":"Välimus ja käitumine","en":"Appearance and behavior"},"path":"/chatbot/appearance"},{"label":{"et":"Erakorralised teated","en":"Emergency notices"},"path":"/chatbot/emergency-notices"}]},{"label":{"et":"Asutuse tööaeg","en":"Office opening hours"},"path":"/working-time"},{"label":{"et":"Sessiooni pikkus","en":"Session length"},"path":"/session-length"}]},{"id":"monitoring","label":{"et":"Seire","en":"Monitoring"},"path":"/monitoring","children":[{"label":{"et":"Aktiivaeg","en":"Working hours"},"path":"/uptime"}]}]
REACT_APP_MENU_JSON=[{"id": "conversations","label": {"et": "Vestlused","en": "Conversations"},"path": "/chat","children": [{"label": {"et": "Vastamata","en": "Unanswered"},"path": "/unanswered"},{"label": {"et": "Aktiivsed","en": "Active"},"path": "/active"},{"label": {"et": "Ajalugu","en": "History"},"path": "/history"}]},{"id": "training","label": {"et": "Treening","en": "Training"},"path": "/training","children": [{"label": {"et": "Treening","en": "Training"},"path": "/training","children": [{"label": {"et": "Teemad","en": "Themes"},"path": "/training/intents"},{"label": {"et": "Avalikud teemad","en": "Public themes"},"path": "/training/common-intents"},{"label": {"et": "Teemade järeltreenimine","en": "Post training themes"},"path": "/training/intents-followup-training"},{"label": {"et": "Vastused","en": "Answers"},"path": "/training/responses"},{"label": {"et": "Kasutuslood","en": "User Stories"},"path": "/training/stories"},{"label": {"et": "Konfiguratsioon","en": "Configuration"},"path": "/training/configuration"},{"label": {"et": "Vormid","en": "Forms"},"path": "/training/forms"},{"label": {"et": "Mälukohad","en": "Slots"},"path": "/training/slots"},{"label": {"et": "Automatic Teenused","en": "Automatic Services"},"path": "/auto-services"}]},{"label": {"et": "Ajaloolised vestlused","en": "Historical conversations"},"path": "/history","children": [{"label": {"et": "Ajalugu","en": "History"},"path": "/history/history"},{"label": {"et": "Pöördumised","en": "Appeals"},"path": "/history/appeal"}]},{"label": {"et": "Mudelipank ja analüütika","en": "Modelbank and analytics"},"path": "/analytics","children": [{"label": {"et": "Teemade ülevaade","en": "Overview of topics"},"path": "/analytics/overview"},{"label": {"et": "Mudelite võrdlus","en": "Comparison of models"},"path": "/analytics/models"},{"label": {"et": "Testlood","en": "testTracks"},"path": "/analytics/testcases"}]},{"label": {"et": "Treeni uus mudel","en": "Train new model"},"path": "/train-new-model"}]},{"id": "analytics","label": {"et": "Analüütika","en": "Analytics"},"path": "/analytics","children": [{"label": {"et": "Ülevaade","en": "Overview"},"path": "/overview"},{"label": {"et": "Vestlused","en": "Chats"},"path": "/chats"},{"label": {"et": "Bürokratt","en": "Burokratt"},"path": "/burokratt"},{"label": {"et": "Tagasiside","en": "Feedback"},"path": "/feedback"},{"label": {"et": "Nõustajad","en": "Advisors"},"path": "/advisors"},{"label": {"et": "Avaandmed","en": "Reports"},"path": "/reports"}]},{"id": "services","label": {"et": "Teenused","en": "Services"},"path": "/services","children": [{"label": {"et": "Ülevaade","en": "Overview"},"path": "/overview"},{"label": {"et": "Uus teenus","en": "New Service"},"path": "/newService"},{"label": {"et": "Automatic Teenused","en": "Automatic Services"},"path": "/auto-services"},{"label": {"et": "Probleemsed teenused","en": "Faulty Services"},"path": "/faultyServices"}]},{"id": "settings","label": {"et": "Haldus","en": "Administration"},"path": "/settings","children": [{"label": {"et": "Kasutajad","en": "Users"},"path": "/users"},{"label": {"et": "Vestlusbot","en": "Chatbot"},"path": "/chatbot","children": [{"label": {"et": "Seaded","en": "Settings"},"path": "/chatbot/settings"},{"label": {"et": "Tervitussõnum","en": "Welcome message"},"path": "/chatbot/welcome-message"},{"label": {"et": "Välimus ja käitumine","en": "Appearance and behavior"},"path": "/chatbot/appearance"},{"label": {"et": "Erakorralised teated","en": "Emergency notices"},"path": "/chatbot/emergency-notices"}]},{"label": {"et": "Asutuse tööaeg","en": "Office opening hours"},"path": "/working-time"},{"label": {"et": "Sessiooni pikkus","en": "Session length"},"path": "/session-length"}]},{"id": "monitoring","label": {"et": "Seire","en": "Monitoring"},"path": "/monitoring","children": [{"label": {"et": "Aktiivaeg","en": "Working hours"},"path": "/uptime"}]}]
71 changes: 35 additions & 36 deletions GUI/src/pages/Training/Intents/CommonIntents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const CommonIntents: FC = () => {
const toast = useToast();
const [searchParams] = useSearchParams();
const [commonIntentsEnabled, setCommonIntentsEnabled] = useState(true);
const [selectedTab, setSelectedTab] = useState<string | null>(null);
const [selectedIntent, setSelectedIntent] = useState<Intent | null>(null);
const [deletableIntent, setDeletableIntent] = useState<
string | number | null
Expand All @@ -50,6 +49,8 @@ const CommonIntents: FC = () => {
const [filter, setFilter] = useState('');
const [refreshing, setRefreshing] = useState(false);

let intentParam;

const { data: intentsFullResponse, isLoading } = useQuery({
queryKey: ['intents/common'],
});
Expand All @@ -63,11 +64,9 @@ const CommonIntents: FC = () => {

if (intentsFullList) {
intentsFullList.forEach((intent: any) => {
const formattedTitle = intent.title.replace(/_/g, ' ');
const countExamples = intent.examples.length;
const newIntent: Intent = {
id: intent.title,
intent: formattedTitle,
description: null,
inModel: intent.inmodel,
modifiedAt: '',
Expand All @@ -77,20 +76,20 @@ const CommonIntents: FC = () => {
};
commonIntents.push(newIntent);
});
intentParam = searchParams.get('intent');
}

useEffect(() => {
const queryIntentName = searchParams.get('intent');
if (commonIntents && queryIntentName) {
const queryIntent = commonIntents.find(
(intent) => intent.intent === queryIntentName
);
if (queryIntent) {
setSelectedIntent(queryIntent);
setSelectedTab(queryIntentName);
}
if (!intentParam || intentsFullList?.length !== commonIntents?.length) return;

const queryIntent = commonIntents.find(
(intent) => intent.id === intentParam
);

if (queryIntent) {
setSelectedIntent(queryIntent);
}
}, [commonIntents, searchParams]);
}, [intentParam]);

const getExampleArrayForIntentId = (): string[] => {
if (selectedIntent) {
Expand All @@ -111,7 +110,7 @@ const CommonIntents: FC = () => {
queryClient.fetchQuery(['intents/full']).then(() => {
setRefreshing(false);
if (commonIntents.length > 0) {
const newSelectedIntent = commonIntents.find((intent) => intent.intent === selectIntent) ?? null;
const newSelectedIntent = commonIntents.find((intent) => intent.id === selectIntent) ?? null;
setSelectedIntent(newSelectedIntent);
}
});
Expand Down Expand Up @@ -150,7 +149,7 @@ const CommonIntents: FC = () => {
});
},
onSettled: () => {
queryRefresh(selectedIntent?.intent || '');
queryRefresh(selectedIntent?.id || '');
},
});

Expand All @@ -174,7 +173,7 @@ const CommonIntents: FC = () => {
message: t('toast.intentAddedToModel'),
});
}
queryRefresh(selectedIntent?.intent || '');
queryRefresh(selectedIntent?.id || '');
},
onError: (error: AxiosError) => {
toast.open({
Expand Down Expand Up @@ -213,16 +212,18 @@ const CommonIntents: FC = () => {
});
},
onSettled: () => {
console.debug('deleteIntentMutation selectedIntent')
console.debug(selectedIntent)
commonIntents = commonIntents.filter(
(intent) => intent.intent !== selectedIntent?.intent
(intent) => intent.id !== selectedIntent?.id
);
setRefreshing(false);
},
});

const filteredIntents = useMemo(() => {
if (!commonIntents) return [];
return commonIntents.filter((intent) => intent.intent?.includes(filter));
return commonIntents.filter((intent) => intent.id?.includes(filter));
}, [commonIntents, filter]);

const intentModifiedMutation = useMutation({
Expand All @@ -234,22 +235,20 @@ const CommonIntents: FC = () => {
setSelectedIntent(null);
if (!commonIntents) return;
const selectedIntent = commonIntents.find(
(intent) => intent.intent === value
(intent) => intent.id === value
);
if (selectedIntent) {
queryRefresh(selectedIntent.intent || '');
queryRefresh(selectedIntent.id || '');
intentModifiedMutation.mutate(
{ intentName: selectedIntent.intent },
{ intentName: selectedIntent.id },
{
onSuccess: (data) => {
selectedIntent.modifiedAt = data.response;
setSelectedIntent(selectedIntent);
setSelectedTab(selectedIntent.intent);
},
onError: () => {
selectedIntent.modifiedAt = '';
setSelectedIntent(selectedIntent);
setSelectedTab(selectedIntent.intent);
},
}
);
Expand All @@ -261,7 +260,7 @@ const CommonIntents: FC = () => {
const handleNewExample = (example: string) => {
if (!selectedIntent) return;
addExamplesMutation.mutate({
intentName: selectedIntent.intent,
intentName: selectedIntent.id,
intentExamples: selectedIntent.examples,
newExamples: example,
});
Expand Down Expand Up @@ -380,7 +379,7 @@ const CommonIntents: FC = () => {
id="tabs"
className="vertical-tabs"
orientation="vertical"
value={selectedTab ?? undefined}
value={selectedIntent?.id ?? undefined}
onValueChange={handleTabsValueChange}
>
<Tabs.List
Expand All @@ -406,11 +405,11 @@ const CommonIntents: FC = () => {
<Tabs.Trigger
key={`${intent}-${index}`}
className="vertical-tabs__trigger"
value={intent.intent}
value={intent.id}
>
<Track gap={16}>
<span style={{ flex: 1 }}>
{intent.intent.replace(/^common_/, '')}
{intent.id.replace(/^common_/, '').replace(/_/g, ' ')}
</span>
<Tooltip content={t('training.intents.amountOfExamples')}>
<span style={{ color: '#5D6071' }}>
Expand Down Expand Up @@ -440,16 +439,16 @@ const CommonIntents: FC = () => {

{selectedIntent && (
<Tabs.Content
key={selectedIntent.intent}
key={selectedIntent.id}
className="vertical-tabs__body"
value={selectedIntent.intent}
value={selectedIntent.id}
style={{ overflowX: 'auto' }}
>
<div className="vertical-tabs__content-header">
<Track direction="vertical" align="stretch" gap={8}>
<Track justify="between">
<Track gap={16}>
<h3>{selectedIntent.intent}</h3>
<h3>{selectedIntent.id.replace(/^common_/, '').replace(/_/g, ' ')}</h3>
</Track>
<p style={{ color: '#4D4F5D' }}>
{t('global.modifiedAt')}:
Expand All @@ -472,7 +471,7 @@ const CommonIntents: FC = () => {
appearance="secondary"
onClick={() =>
intentDownloadMutation.mutate({
intentName: selectedIntent.intent,
intentName: selectedIntent!.id,
})
}
>
Expand All @@ -483,7 +482,7 @@ const CommonIntents: FC = () => {
appearance="secondary"
onClick={() =>
intentModelMutation.mutate({
name: selectedIntent.intent,
name: selectedIntent!.id,
inModel: true,
})
}
Expand All @@ -494,7 +493,7 @@ const CommonIntents: FC = () => {
<Button
onClick={() =>
intentModelMutation.mutate({
name: selectedIntent.intent,
name: selectedIntent!.id,
inModel: false,
})
}
Expand Down Expand Up @@ -524,7 +523,7 @@ const CommonIntents: FC = () => {
<span>
<Button
appearance="error"
onClick={() => setDeletableIntent(selectedIntent.id)}
onClick={() => setDeletableIntent(selectedIntent!.id)}
>
{t('global.delete')}
</Button>
Expand All @@ -551,7 +550,7 @@ const CommonIntents: FC = () => {

{connectableIntent !== null && (
<ConnectServiceToIntentModal
intent={connectableIntent.intent}
intent={connectableIntent.id}
onModalClose={() => setConnectableIntent(null)}
/>
)}
Expand All @@ -571,7 +570,7 @@ const CommonIntents: FC = () => {
<Button
appearance="error"
onClick={() =>
deleteIntentMutation.mutate({ name: deletableIntent.intent })
deleteIntentMutation.mutate({ name: deletableIntent!.id })
}
>
{t('global.yes')}
Expand Down
Loading

0 comments on commit a7d954c

Please sign in to comment.