Skip to content

Commit

Permalink
Merge pull request #1872 from akto-api-security/fix/remove_deactivate…
Browse files Browse the repository at this point in the history
…d_collections_from_input

hiding deactivated collections from the dropdown search menu
  • Loading branch information
Ark2307 authored Dec 31, 2024
2 parents 5e02f5e + ff35d73 commit 646de5b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function CollectionComponent(props) {
}, [condition])

const allCollections = PersistStore(state => state.allCollections);
const allCollectionsOptions = allCollections.filter(x => x.type !== "API_GROUP")
const activatedCollections = allCollections.filter(collection => collection.deactivated === false)
const allCollectionsOptions = activatedCollections.filter(x => x.type !== "API_GROUP")
.map(collection => {
return {
label: collection.displayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ function ConditionComponent(props) {
}
},[condition])
const allCollections = PersistStore(state => state.allCollections);
const allCollectionsOptions = allCollections.map(collection => {
return {
label: collection.displayName,
value: collection.id
}
})
const activatedCollections = allCollections.filter(collection => collection.deactivated === false)
const allCollectionsOptions = activatedCollections.map(collection => ({
label: collection.displayName,
value: collection.id
}))
const getApiEndpointsOptions = (data) => {
return data.map(apiEndpoint => {
let str = func.toMethodUrlString(apiEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,19 @@ function DropdownSearch(props) {
setLoading(true);
}

const defaultSliceValue = sliceMaxVal || 20

setTimeout(() => {
if (value === '' && selectedOptions.length === 0) {
setOptions(deselectedOptions);
const options = deselectedOptions.slice(0, defaultSliceValue);
const title = options.length > defaultSliceValue
? `Showing ${options.length} result${func.addPlurality(options.length)} only. (type more to refine results)`
: "Showing all results";
const nestedOptions = [{
title: title,
options: options
}]
setOptions(nestedOptions);
setLoading(false);
return;
}
Expand All @@ -87,8 +97,17 @@ function DropdownSearch(props) {
});
}else{
resultOptions = deselectedOptions.filter((option) =>
option[searchKey].match(filterRegex)
);
option[searchKey].match(filterRegex)
).slice(0, defaultSliceValue);

const title = resultOptions.length >= defaultSliceValue
? `Showing ${resultOptions.length} result${func.addPlurality(resultOptions.length)} only. (type more to refine results)`
: "Showing all results";

resultOptions = [{
title: title,
options: resultOptions
}]
}
setOptions(resultOptions);
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function ApiGroupModal(props){
const setCollectionsMap = PersistStore(state => state.setCollectionsMap)
const allCollections = PersistStore(state => state.allCollections);
const setAllCollections = PersistStore(state => state.setAllCollections)
const activatedGroupCollections = allCollections.filter((x) => { return (x.type === 'API_GROUP' && x.deactivated === false) })

const [apiGroupName, setApiGroupName] = useState(currentApiGroupName)

Expand Down Expand Up @@ -65,12 +66,13 @@ function ApiGroupModal(props){
id={"select-api-group"}
label="Select API group"
placeholder="Select API group"
optionsList={allCollections.filter((x) => { return x.type === 'API_GROUP' }).map((x) => {
return {
label: x.displayName,
value: x.displayName
}
})
optionsList={
activatedGroupCollections.map((x) => {
return {
label: x.displayName,
value: x.displayName
}
})
}
setSelected={setApiGroupName}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ const SampleApi = () => {
}


const allCollectionsOptions = allCollections.map(collection => {
const activatedCollections = allCollections.filter(collection => collection.deactivated === false)
const allCollectionsOptions = activatedCollections.map(collection => {
return {
label: collection.displayName,
value: collection.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function SelectCollectionComponent() {
const allCollections = PersistStore(state => state.allCollections);
const navigate = useNavigate()
let urlsCount = 0
const allCollectionsOptions = allCollections.filter(x => x.type !== "API_GROUP")
const allCollectionsOptions = allCollections.filter(x => (x.type !== "API_GROUP" && x.deactivated === false))
.map(collection => {
urlsCount += collection.urlsCount
return {
Expand Down
4 changes: 3 additions & 1 deletion apps/dashboard/web/polaris_web/web/src/util/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,11 @@ getDeprecatedEndpoints(apiInfoList, unusedEndpoints, apiCollectionId) {
getSearchItemsArr(allRoutes,allCollections){
let combinedArr = []

const activatedColections = allCollections.filter((item) => item.deactivated === false)

let initialStr = "/dashboard/observe/inventory/"

allCollections.forEach((item)=> {
activatedColections.forEach((item)=> {
combinedArr.push({content: item.displayName, url: initialStr + item.id, type:'collection'})
})

Expand Down

0 comments on commit 646de5b

Please sign in to comment.