Skip to content

Commit

Permalink
Impl [Create Job] Marketplace: filter out Serving kind (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
eran-nussbaum authored Feb 22, 2021
1 parent 0deabf7 commit 22a2362
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
22 changes: 11 additions & 11 deletions src/actions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ const functionsActions = {
fetchFunctionsTemplates: () => dispatch => {
return functionsApi
.getFunctionTemplatesCatalog()
.then(result => {
const templates = Object.keys(result.data).map(func => {
return {
.then(({ data: functionTemplates }) => {
const templates = Object.entries(functionTemplates).map(
([key, value]) => ({
kind: value?.kind,
metadata: {
name: func,
name: key,
hash: '',
description: result.data[func].description,
categories: result.data[func].categories,
versions: result.data[func].versions,
description: value?.description,
categories: value?.categories,
versions: value?.versions,
tag: ''
},
status: {
status: ''
state: ''
}
}
})
})
)
const templatesCategories = generateCategories(templates)

dispatch(functionsActions.setFunctionsTemplates(templatesCategories))

return { templatesCategories, templates }
Expand Down
6 changes: 2 additions & 4 deletions src/components/CreateJobPage/CreateJobPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ const CreateJobPage = ({
)
const filteredTemplatesCategories = {}

Object.entries(templatesCategories).forEach(category => {
filteredTemplatesCategories[
category[0]
] = category[1].filter(template =>
Object.entries(templatesCategories).forEach(([key, value]) => {
filteredTemplatesCategories[key] = value.filter(template =>
template.metadata.name.includes(filterByName)
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ const JobsPanelParametersTableView = ({
<div className="table__cell-actions" />
</div>
)}
{Object.entries(tableContent)?.map((contentCategory, index) => {
return contentCategory[1].length > 0 ? (
<div key={contentCategory[0]}>
{Object.entries(tableContent)?.map(([key, value], index) =>
value.length > 0 ? (
<div key={key}>
<div className="table__row no-hover">
<div className="table__cell table__subheader">
{contentCategory[0]}
</div>
<div className="table__cell table__subheader">{key}</div>
</div>
{contentCategory[1].map(contentItem => {
{value.map(contentItem => {
if (
editItem &&
contentItem.data.name === selectedItem.data.name
Expand All @@ -58,7 +56,7 @@ const JobsPanelParametersTableView = ({
<EditableParametersRow
disabledOptions={disabledOptions}
handleEdit={handleEditParameter}
key={contentItem.data.name + index}
key={`${contentItem.data.name}${index}`}
selectedParameter={selectedItem}
setSelectedParameter={setSelectedItem}
/>
Expand All @@ -76,7 +74,7 @@ const JobsPanelParametersTableView = ({
contentItem={contentItem}
handleDelete={handleDeleteParameter}
handleEdit={handleEditParameter}
key={contentItem.data.name + index}
key={`${contentItem.data.name}${index}`}
section="parameters"
withCheckbox
/>
Expand All @@ -85,7 +83,7 @@ const JobsPanelParametersTableView = ({
})}
</div>
) : null
})}
)}
{children}
</div>
)
Expand Down
25 changes: 14 additions & 11 deletions src/utils/generateTemplatesCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ const aliasToCategory = {
test: 'other',
utils: 'other'
}
const excludeCategoryKinds = ['serving', 'nuclio']
export const generateCategories = templates => {
const templatesCategories = {}

templates.forEach(template => {
if (template.metadata.categories) {
template.metadata.categories.forEach(category => {
const valueToAdd = aliasToCategory[category] ?? category
templatesCategories[valueToAdd] ??= []
if (!templatesCategories[valueToAdd].includes(template)) {
templatesCategories[valueToAdd].push(template)
}
})
}
})
templates
.filter(template => !excludeCategoryKinds.includes(template.kind))
.forEach(template => {
if (template.metadata.categories) {
template.metadata.categories.forEach(category => {
const valueToAdd = aliasToCategory[category] ?? category
templatesCategories[valueToAdd] ??= []
if (!templatesCategories[valueToAdd].includes(template)) {
templatesCategories[valueToAdd].push(template)
}
})
}
})

return templatesCategories
}

0 comments on commit 22a2362

Please sign in to comment.