-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
48 additions
and
54 deletions.
There are no files selected for viewing
23 changes: 9 additions & 14 deletions
23
...ditor/components/PluginActionForm/components/CommonEditorForm/hooks/useSelectedFormTab.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import { useCallback } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { API_EDITOR_TABS } from "constants/ApiEditorConstants/CommonApiConstants"; | ||
import { | ||
getPluginActionConfigSelectedTabIndex, | ||
getPluginActionConfigSelectedTab, | ||
setPluginActionEditorSelectedTab, | ||
} from "PluginActionEditor/store"; | ||
|
||
export function useSelectedFormTab(): [string, (id: string) => void] { | ||
export function useSelectedFormTab(): [ | ||
string | undefined, | ||
(id: string) => void, | ||
] { | ||
const dispatch = useDispatch(); | ||
// the redux form has been configured with indexes, but the new ads components need strings to work. | ||
// these functions convert them back and forth as needed. | ||
const selectedIndex = useSelector(getPluginActionConfigSelectedTabIndex) || 0; | ||
const selectedValue = Object.values(API_EDITOR_TABS)[selectedIndex]; | ||
const setSelectedIndex = useCallback( | ||
const selectedValue = useSelector(getPluginActionConfigSelectedTab); | ||
const setSelectedTab = useCallback( | ||
(value: string) => { | ||
const index = Object.values(API_EDITOR_TABS).indexOf( | ||
value as API_EDITOR_TABS, | ||
); | ||
|
||
dispatch(setPluginActionEditorSelectedTab(index)); | ||
dispatch(setPluginActionEditorSelectedTab(value)); | ||
}, | ||
[dispatch], | ||
); | ||
|
||
return [selectedValue, setSelectedIndex]; | ||
return [selectedValue, setSelectedTab]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters