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