-
Notifications
You must be signed in to change notification settings - Fork 374
fix: correct URL when switching page modes #4736
Changes from 8 commits
d8e7505
cbbdba8
74c7daa
f7d7f0a
fff0805
f868b3f
87e53fe
2a0ef2d
5cfb0dc
19ae9ff
d4df821
2850b07
3916e38
8c826f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,19 +22,25 @@ const CodeEditor = React.lazy(() => import('./code-editor')); | |
| interface LGPageProps { | ||
| dialogId: string; | ||
| projectId: string; | ||
| skillId?: string; | ||
| } | ||
|
|
||
| const LGPage: React.FC<RouteComponentProps<LGPageProps>> = (props: RouteComponentProps<LGPageProps>) => { | ||
| const { dialogId = '', projectId = '' } = props; | ||
| const dialogs = useRecoilValue(validateDialogsSelectorFamily(projectId)); | ||
| const { dialogId = '', projectId = '', skillId = null } = props; | ||
| const dialogs = useRecoilValue(validateDialogsSelectorFamily(skillId ?? projectId)); | ||
|
|
||
| console.log(skillId, projectId, skillId ?? projectId, dialogs); | ||
|
||
|
|
||
| const path = props.location?.pathname ?? ''; | ||
|
|
||
| const edit = /\/edit(\/)?$/.test(path); | ||
|
|
||
| const baseURL = | ||
| projectId === skillId || skillId == null ? `/bot/${projectId}/` : `/bot/${projectId}/skill/${skillId}/`; | ||
|
||
|
|
||
| const navLinks: INavTreeItem[] = useMemo(() => { | ||
| const newDialogLinks: INavTreeItem[] = dialogs.map((dialog) => { | ||
| let url = `/bot/${projectId}/language-generation/${dialog.id}`; | ||
| let url = baseURL + `language-generation/${dialog.id}`; | ||
| if (edit) { | ||
| url += `/edit`; | ||
| } | ||
|
|
@@ -51,7 +57,7 @@ const LGPage: React.FC<RouteComponentProps<LGPageProps>> = (props: RouteComponen | |
| const mainDialog = newDialogLinks.splice(mainDialogIndex, 1)[0]; | ||
| newDialogLinks.splice(0, 0, mainDialog); | ||
| } | ||
| let commonUrl = `/bot/${projectId}/language-generation/common`; | ||
| let commonUrl = baseURL + `language-generation/common`; | ||
| if (edit) { | ||
| commonUrl += '/edit'; | ||
| } | ||
|
|
@@ -68,13 +74,13 @@ const LGPage: React.FC<RouteComponentProps<LGPageProps>> = (props: RouteComponen | |
| useEffect(() => { | ||
| const activeDialog = dialogs.find(({ id }) => id === dialogId); | ||
| if (!activeDialog && dialogs.length && dialogId !== 'common') { | ||
| navigateTo(`/bot/${projectId}/language-generation/common`); | ||
| navigateTo(baseURL + `language-generation/common`); | ||
| } | ||
| }, [dialogId, dialogs, projectId]); | ||
|
|
||
| const onToggleEditMode = useCallback( | ||
| (_e) => { | ||
| let url = `/bot/${projectId}/language-generation/${dialogId}`; | ||
| let url = baseURL + `language-generation/${dialogId}`; | ||
| if (!edit) url += `/edit`; | ||
| navigateTo(url); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,17 +21,20 @@ const CodeEditor = React.lazy(() => import('./code-editor')); | |
| const LUPage: React.FC<RouteComponentProps<{ | ||
| dialogId?: string; | ||
| projectId: string; | ||
| skillId: string; | ||
| }>> = (props) => { | ||
| const { dialogId = '', projectId = '' } = props; | ||
| const dialogs = useRecoilValue(validateDialogsSelectorFamily(projectId)); | ||
| const { dialogId = '', projectId = '', skillId = null } = props; | ||
|
||
| const dialogs = useRecoilValue(validateDialogsSelectorFamily(skillId ?? projectId)); | ||
|
|
||
| const path = props.location?.pathname ?? ''; | ||
| const edit = /\/edit(\/)?$/.test(path); | ||
| const isRoot = dialogId === 'all'; | ||
| const baseURL = | ||
| projectId === skillId || skillId == null ? `/bot/${projectId}/` : `/bot/${projectId}/skill/${skillId}/`; | ||
|
|
||
| const navLinks: INavTreeItem[] = useMemo(() => { | ||
| const newDialogLinks: INavTreeItem[] = dialogs.map((dialog) => { | ||
| let url = `/bot/${projectId}/language-understanding/${dialog.id}`; | ||
| let url = baseURL + `language-understanding/${dialog.id}`; | ||
| if (edit) { | ||
| url += `/edit`; | ||
| } | ||
|
|
@@ -52,21 +55,21 @@ const LUPage: React.FC<RouteComponentProps<{ | |
| id: 'all', | ||
| name: formatMessage('All'), | ||
| ariaLabel: formatMessage('all language understanding files'), | ||
| url: `/bot/${projectId}/language-understanding/all`, | ||
| url: baseURL + `language-understanding/all`, | ||
| }); | ||
| return newDialogLinks; | ||
| }, [dialogs, edit]); | ||
|
|
||
| useEffect(() => { | ||
| const activeDialog = dialogs.find(({ id }) => id === dialogId); | ||
| if (!activeDialog && dialogId !== 'all' && dialogs.length) { | ||
| navigateTo(`/bot/${projectId}/language-understanding/all`); | ||
| navigateTo(baseURL + `language-understanding/all`); | ||
| } | ||
| }, [dialogId, dialogs, projectId]); | ||
|
|
||
| const onToggleEditMode = useCallback( | ||
| (_e) => { | ||
| let url = `/bot/${projectId}/language-understanding/${dialogId}`; | ||
| let url = baseURL + `language-understanding/${dialogId}`; | ||
| if (!edit) url += `/edit`; | ||
| navigateTo(url); | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projectId === skillId should never happen correct?