mirror of https://github.com/grafana/grafana.git
Chore: fix betterer issues (#110100)
This commit is contained in:
parent
5724fae778
commit
145577831b
|
@ -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"],
|
||||
|
|
|
@ -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<string[]>([]);
|
||||
const [initialFavoriteDataSources, setInitialFavoriteDataSources] = useState<string[]>([]);
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue