feat: universal search permissions access control.

This commit is contained in:
a.bouhuolia
2021-11-27 17:22:29 +02:00
parent 56ab0a68e2
commit 3db00f6f70
14 changed files with 142 additions and 39 deletions

View File

@@ -14,7 +14,7 @@ import DashboardUniversalSearchItemActions from './DashboardUniversalSearchItemA
import { DashboardUniversalSearchItem } from './components';
import DashboardUniversalSearchHotkeys from './DashboardUniversalSearchHotkeys';
import { getUniversalSearchTypeOptions } from './utils';
import { useGetUniversalSearchTypeOptions } from './utils';
/**
* Dashboard universal search.
@@ -28,6 +28,8 @@ function DashboardUniversalSearch({
closeGlobalSearch,
defaultUniversalResourceType,
}) {
const searchTypeOptions = useGetUniversalSearchTypeOptions();
// Search keyword.
const [searchKeyword, setSearchKeyword] = React.useState('');
@@ -97,10 +99,9 @@ function DashboardUniversalSearch({
setSearchKeyword('');
};
const searchTypeOptions = React.useMemo(
() => getUniversalSearchTypeOptions(),
[],
);
if (searchTypeOptions.length === 0) {
return null;
}
return (
<div class="dashboard__universal-search">

View File

@@ -1,5 +1,9 @@
import { get } from 'lodash';
import * as R from 'ramda';
import React from 'react';
import { universalSearchBinds } from './DashboardUniversalSearchBinds';
import { useAbilitiesFilter } from '../../hooks/utils';
/**
*
@@ -23,22 +27,28 @@ export const getUniversalSearchBind = (resourceType, key) => {
};
/**
*
* @returns
* Retrieve universal search type options.
*/
export const getUniversalSearchTypeOptions = () => {
return getUniversalSearchBinds().map((bind) => ({
key: bind.resourceType,
label: bind.optionItemLabel,
}))
}
export const useGetUniversalSearchTypeOptions = () => {
const abilityFilter = useAbilitiesFilter();
const momerizedBinds = React.useMemo(() => {
const filteredBinds = R.compose(abilityFilter, getUniversalSearchBinds)();
return filteredBinds.map((bind) => ({
key: bind.resourceType,
label: bind.optionItemLabel,
}));
}, [abilityFilter]);
return momerizedBinds;
};
/**
*
* @returns
* Retrieve universal search types actions.
*/
export const getUniversalSearchItemsActions = () => {
return getUniversalSearchBinds()
.filter((bind) => bind.selectItemAction)
.map((bind) => bind.selectItemAction);
}
};