diff --git a/.betterer.results b/.betterer.results index 38ab3e6a0d5..e0aca642544 100644 --- a/.betterer.results +++ b/.betterer.results @@ -548,16 +548,6 @@ exports[`better eslint`] = { "packages/grafana-runtime/src/utils/queryResponse.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "packages/grafana-runtime/src/utils/useFavoriteDatasources.ts:5381": [ - [0, 0, 0, "React Hook \\"useCallback\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "0"], - [0, 0, 0, "React Hook \\"useCallback\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "1"], - [0, 0, 0, "React Hook \\"useCallback\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "2"], - [0, 0, 0, "React Hook \\"useCallback\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "3"], - [0, 0, 0, "React Hook \\"useEffect\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "4"], - [0, 0, 0, "React Hook \\"useState\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "5"], - [0, 0, 0, "React Hook \\"useState\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "6"], - [0, 0, 0, "React Hook \\"useState\\" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?", "7"] - ], "packages/grafana-runtime/src/utils/userStorage.tsx:5381": [ [0, 0, 0, "Direct usage of localStorage is not allowed. import store from @grafana/data instead", "0"], [0, 0, 0, "Direct usage of localStorage is not allowed. import store from @grafana/data instead", "1"], diff --git a/packages/grafana-runtime/src/utils/useFavoriteDatasources.ts b/packages/grafana-runtime/src/utils/useFavoriteDatasources.ts index 20233bbf1c7..29cc5caa55c 100644 --- a/packages/grafana-runtime/src/utils/useFavoriteDatasources.ts +++ b/packages/grafana-runtime/src/utils/useFavoriteDatasources.ts @@ -36,24 +36,16 @@ const userStorage = new UserStorage('grafana-runtime'); * @public */ export function useFavoriteDatasources(): FavoriteDatasources { - if (!config.featureToggles.favoriteDatasources) { - return { - enabled: false, - isLoading: false, - favoriteDatasources: [], - initialFavoriteDataSources: [], - addFavoriteDatasource: () => {}, - removeFavoriteDatasource: () => {}, - isFavoriteDatasource: () => false, - }; - } - const [favoriteDatasources, setFavoriteDatasources] = useState([]); const [initialFavoriteDataSources, setInitialFavoriteDataSources] = useState([]); const [isLoading, setIsLoading] = useState(false); // Load favorites from storage on mount useEffect(() => { + if (!config.featureToggles.favoriteDatasources) { + return; + } + const loadFavorites = async () => { setIsLoading(true); const stored = await userStorage.getItem(FAVORITE_DATASOURCES_KEY); @@ -108,6 +100,18 @@ export function useFavoriteDatasources(): FavoriteDatasources { [favoriteDatasources] ); + if (!config.featureToggles.favoriteDatasources) { + return { + enabled: false, + isLoading: false, + favoriteDatasources: [], + initialFavoriteDataSources: [], + addFavoriteDatasource: () => {}, + removeFavoriteDatasource: () => {}, + isFavoriteDatasource: () => false, + }; + } + return { enabled: true, isLoading,