mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-29 07:39:36 +02:00
filter categories in server instead of the client and small fixes following latest rebase
This commit is contained in:
parent
cb794daf73
commit
64a9dabdd6
6 changed files with 35 additions and 34 deletions
|
@ -152,7 +152,7 @@ const Home = (props: ComponentProps): JSX.Element => {
|
|||
<AppGrid
|
||||
categories={
|
||||
!localSearch
|
||||
? appCategories.filter((category: Category) => category.isPinned && category.apps.length > 0)
|
||||
? appCategories.filter((category: Category) => category.isPinned && category.apps?.length > 0)
|
||||
: searchInCategories(localSearch, appCategories)
|
||||
}
|
||||
apps={
|
||||
|
@ -181,7 +181,7 @@ const Home = (props: ComponentProps): JSX.Element => {
|
|||
<BookmarkGrid
|
||||
categories={
|
||||
!localSearch
|
||||
? bookmarkCategories.filter((category: Category) => category.isPinned && category.bookmarks.length > 0)
|
||||
? bookmarkCategories.filter((category: Category) => category.isPinned && category.bookmarks?.length > 0)
|
||||
: searchInCategories(localSearch, bookmarkCategories)
|
||||
}
|
||||
bookmarks={
|
||||
|
|
|
@ -49,13 +49,11 @@ export const getAppCategories = () => async (dispatch: Dispatch) => {
|
|||
});
|
||||
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Category[]>>("/api/categories");
|
||||
const res = await axios.get<ApiResponse<Category[]>>("/api/categories/apps");
|
||||
|
||||
dispatch<GetAppCategoriesAction<Category[]>>({
|
||||
type: ActionTypes.getAppCategoriesSuccess,
|
||||
payload: res.data.data.filter(
|
||||
(category: Category) => category.type === "apps"
|
||||
),
|
||||
payload: res.data.data
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
|
@ -49,13 +49,11 @@ export const getBookmarkCategories = () => async (dispatch: Dispatch) => {
|
|||
});
|
||||
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Category[]>>("/api/categories");
|
||||
const res = await axios.get<ApiResponse<Category[]>>("/api/categories/bookmarks");
|
||||
|
||||
dispatch<GetBookmarkCategoriesAction<Category[]>>({
|
||||
type: ActionTypes.getBookmarkCategoriesSuccess,
|
||||
payload: res.data.data.filter(
|
||||
(category: Category) => category.type === "bookmarks"
|
||||
),
|
||||
payload: res.data.data
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
|
@ -201,7 +201,7 @@ async function retrieveDockerApps(apps, orderType, unpinStoppedApps) {
|
|||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
|
||||
containers = containers.filter(e => Object.keys(e.Labels).length !== 0);
|
||||
containers = containers.filter((e) => Object.keys(e.Labels).length !== 0);
|
||||
const dockerApps = [];
|
||||
for (const container of containers) {
|
||||
const labels = container.Labels;
|
||||
|
@ -270,7 +270,15 @@ async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
|
|||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
|
||||
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0);
|
||||
|
||||
const categories = await Category.findAll({
|
||||
where: {
|
||||
type: 'apps'
|
||||
},
|
||||
order: [[orderType, 'ASC']]
|
||||
});
|
||||
|
||||
ingresses = ingresses.filter((e) => Object.keys(e.metadata.annotations).length !== 0);
|
||||
const kubernetesApps = [];
|
||||
for (const ingress of ingresses) {
|
||||
const annotations = ingress.metadata.annotations;
|
||||
|
@ -286,7 +294,7 @@ async function retrieveKubernetesApps(apps, orderType, unpinStoppedApps) {
|
|||
const icons = annotations['flame.pawelmalak/icon'] ? annotations['flame.pawelmalak/icon'].split(';') : [];;
|
||||
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : dockerDefaultCategory;
|
||||
const category = categoriesLabels[i] ? categories.find(category => category.name.toUpperCase() === categoriesLabels[i].toUpperCase()) : kubernetesDefaultCategory;
|
||||
|
||||
kubernetesApps.push({
|
||||
name: names[i] || names[0],
|
||||
|
|
|
@ -21,6 +21,8 @@ exports.kubernetesDefaultCategory = {
|
|||
orderId: 999,
|
||||
};
|
||||
|
||||
const defaultCategories = [exports.dockerDefaultCategory, exports.kubernetesDefaultCategory];
|
||||
|
||||
// @desc Create new category
|
||||
// @route POST /api/categories
|
||||
// @access Public
|
||||
|
@ -60,37 +62,26 @@ exports.getCategories = asyncWrapper(async (req, res, next) => {
|
|||
|
||||
const orderType = useOrdering ? useOrdering.value : "createdAt";
|
||||
let categories;
|
||||
let categoryTypes = []
|
||||
if (!req.params.type || req.params.type === 'apps') {
|
||||
categoryTypes.push({model: App, as: "apps"});
|
||||
}
|
||||
if (!req.params.type || req.params.type === 'bookmarks') {
|
||||
categoryTypes.push({model: Bookmark, as: "bookmarks"});
|
||||
}
|
||||
|
||||
if (orderType == "name") {
|
||||
categories = await Category.findAll({
|
||||
include: [
|
||||
{
|
||||
model: App,
|
||||
as: 'apps',
|
||||
},
|
||||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
},
|
||||
],
|
||||
include: categoryTypes,
|
||||
order: [[Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC']],
|
||||
});
|
||||
} else {
|
||||
categories = await Category.findAll({
|
||||
include: [
|
||||
{
|
||||
model: App,
|
||||
as: 'apps',
|
||||
},
|
||||
{
|
||||
model: Bookmark,
|
||||
as: 'bookmarks',
|
||||
},
|
||||
],
|
||||
include: categoryTypes,
|
||||
order: [[orderType, 'ASC']],
|
||||
});
|
||||
categories.push(exports.dockerDefaultCategory);
|
||||
}
|
||||
categories.push(defaultCategories.filter((category) => categoryTypes.findIndex((includedType) => category.type === includedType.as) > -1));
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
|
@ -119,6 +110,8 @@ exports.getCategory = asyncWrapper(async (req, res, next) => {
|
|||
if (!category) {
|
||||
if (req.params.id === exports.dockerDefaultCategory.id) {
|
||||
category = exports.dockerDefaultCategory;
|
||||
} else if (req.params.id === exports.kubernetesDefaultCategory.id) {
|
||||
category = exports.kubernetesDefaultCategory;
|
||||
} else {
|
||||
return next(
|
||||
new ErrorResponse(
|
||||
|
|
|
@ -15,6 +15,10 @@ router
|
|||
.post(createCategory)
|
||||
.get(getCategories);
|
||||
|
||||
router
|
||||
.route('/:type')
|
||||
.get(getCategories);
|
||||
|
||||
router
|
||||
.route('/:id')
|
||||
.get(getCategory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue