mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: universal search permissions access control.
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user