forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#7196 from jerolimov/odc-5019
Get customized catalog categories in dev catalog from server flags
- Loading branch information
Showing
17 changed files
with
529 additions
and
136 deletions.
There are no files selected for viewing
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
34 changes: 32 additions & 2 deletions
34
frontend/packages/dev-console/src/components/catalog/hooks/useCatalogCategories.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,6 +1,36 @@ | ||
import * as React from 'react'; | ||
|
||
import { defaultCatalogCategories } from '../utils/default-categories'; | ||
import { CatalogCategories } from '../utils/types'; | ||
import { CatalogCategory } from '../utils/types'; | ||
|
||
const useCatalogCategories = (): CatalogCategory[] => { | ||
const categories = React.useMemo<CatalogCategory[]>(() => { | ||
try { | ||
const categoriesString = window.SERVER_FLAGS.developerCatalogCategories; | ||
if (!categoriesString) { | ||
return defaultCatalogCategories; | ||
} | ||
|
||
const categoriesArray: CatalogCategory[] = JSON.parse(categoriesString); | ||
|
||
if (!Array.isArray(categoriesArray)) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`Unexpected server flag "developerCatalogCategories" format. Expected array, got ${typeof categoriesArray}:`, | ||
categoriesArray, | ||
); | ||
return defaultCatalogCategories; | ||
} | ||
|
||
return categoriesArray; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Could not parse server flag "developerCatalogCategories":', error); | ||
return defaultCatalogCategories; | ||
} | ||
}, []); | ||
|
||
const useCatalogCategories = (): CatalogCategories => defaultCatalogCategories; | ||
return categories; | ||
}; | ||
|
||
export default useCatalogCategories; |
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
Oops, something went wrong.