mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
feat: shortcuts keyword table permissions access control.
This commit is contained in:
@@ -1,110 +1,228 @@
|
|||||||
import React from 'react';
|
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
import {
|
||||||
|
AbilitySubject,
|
||||||
|
AccountAction,
|
||||||
|
BillAction,
|
||||||
|
CashflowAction,
|
||||||
|
CustomerAction,
|
||||||
|
ExpenseAction,
|
||||||
|
ItemAction,
|
||||||
|
ManualJournalAction,
|
||||||
|
ReportsAction,
|
||||||
|
SaleEstimateAction,
|
||||||
|
SaleInvoiceAction,
|
||||||
|
SaleReceiptAction,
|
||||||
|
VendorAction,
|
||||||
|
} from './abilityOption';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + I',
|
shortcut_key: 'Shift + I',
|
||||||
description: intl.get('jump_to_the_invoices'),
|
description: intl.get('jump_to_the_invoices'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleInvoiceAction.View,
|
||||||
|
subject: AbilitySubject.Invoice,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + E',
|
shortcut_key: 'Shift + E',
|
||||||
description: intl.get('jump_to_the_estimates'),
|
description: intl.get('jump_to_the_estimates'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleEstimateAction.View,
|
||||||
|
subject: AbilitySubject.Estimate,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + R',
|
shortcut_key: 'Shift + R',
|
||||||
description: intl.get('jump_to_the_receipts'),
|
description: intl.get('jump_to_the_receipts'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleReceiptAction.View,
|
||||||
|
subject: AbilitySubject.Receipt,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + X',
|
shortcut_key: 'Shift + X',
|
||||||
description: intl.get('jump_to_the_expenses'),
|
description: intl.get('jump_to_the_expenses'),
|
||||||
|
permission: {
|
||||||
|
ability: ExpenseAction.View,
|
||||||
|
subject: AbilitySubject.Expense,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + C',
|
shortcut_key: 'Shift + C',
|
||||||
description: intl.get('jump_to_the_customers'),
|
description: intl.get('jump_to_the_customers'),
|
||||||
|
permission: {
|
||||||
|
ability: CustomerAction.View,
|
||||||
|
subject: AbilitySubject.Customer,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + V',
|
shortcut_key: 'Shift + V',
|
||||||
description: intl.get('jump_to_the_vendors'),
|
description: intl.get('jump_to_the_vendors'),
|
||||||
|
permission: {
|
||||||
|
ability: VendorAction.View,
|
||||||
|
subject: AbilitySubject.Vendor,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + A',
|
shortcut_key: 'Shift + A',
|
||||||
description: intl.get('jump_to_the_chart_of_accounts'),
|
description: intl.get('jump_to_the_chart_of_accounts'),
|
||||||
|
permission: {
|
||||||
|
ability: AccountAction.View,
|
||||||
|
subject: AbilitySubject.Account,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + B',
|
shortcut_key: 'Shift + B',
|
||||||
description: intl.get('jump_to_the_bills'),
|
description: intl.get('jump_to_the_bills'),
|
||||||
|
permission: {
|
||||||
|
ability: BillAction.View,
|
||||||
|
subject: AbilitySubject.Bill,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + M',
|
shortcut_key: 'Shift + M',
|
||||||
description: intl.get('jump_to_the_manual_journals'),
|
description: intl.get('jump_to_the_manual_journals'),
|
||||||
|
permission: {
|
||||||
|
ability: ManualJournalAction.View,
|
||||||
|
subject: AbilitySubject.ManualJournal,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + W',
|
shortcut_key: 'Shift + W',
|
||||||
description: intl.get('jump_to_the_items'),
|
description: intl.get('jump_to_the_items'),
|
||||||
|
permission: {
|
||||||
|
ability: ItemAction.View,
|
||||||
|
subject: AbilitySubject.Item,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + D',
|
shortcut_key: 'Shift + D',
|
||||||
description: intl.get('jump_to_the_add_money_in'),
|
description: intl.get('jump_to_the_add_money_in'),
|
||||||
|
permission: {
|
||||||
|
ability: CashflowAction.Create,
|
||||||
|
subject: AbilitySubject.Cashflow,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + Q',
|
shortcut_key: 'Shift + Q',
|
||||||
description: intl.get('jump_to_the_add_money_out'),
|
description: intl.get('jump_to_the_add_money_out'),
|
||||||
|
permission: {
|
||||||
|
ability: CashflowAction.Create,
|
||||||
|
subject: AbilitySubject.Cashflow,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + 1',
|
shortcut_key: 'Shift + 1',
|
||||||
description: intl.get('jump_to_the_balance_sheet'),
|
description: intl.get('jump_to_the_balance_sheet'),
|
||||||
|
permission: {
|
||||||
|
ability: ReportsAction.READ_BALANCE_SHEET,
|
||||||
|
subject: AbilitySubject.Report,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + 2',
|
shortcut_key: 'Shift + 2',
|
||||||
description: intl.get('jump_to_the_profit_loss_sheet'),
|
description: intl.get('jump_to_the_profit_loss_sheet'),
|
||||||
|
permission: {
|
||||||
|
ability: ReportsAction.READ_PROFIT_LOSS,
|
||||||
|
subject: AbilitySubject.Report,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + 3',
|
shortcut_key: 'Shift + 3',
|
||||||
description: intl.get('jump_to_the_journal_sheet'),
|
description: intl.get('jump_to_the_journal_sheet'),
|
||||||
|
permission: {
|
||||||
|
ability: ReportsAction.READ_JOURNAL,
|
||||||
|
subject: AbilitySubject.Report,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + 4',
|
shortcut_key: 'Shift + 4',
|
||||||
description: intl.get('jump_to_the_general_ledger_sheet'),
|
description: intl.get('jump_to_the_general_ledger_sheet'),
|
||||||
|
permission: {
|
||||||
|
ability: ReportsAction.READ_GENERAL_LEDGET,
|
||||||
|
subject: AbilitySubject.Report,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Shift + 5',
|
shortcut_key: 'Shift + 5',
|
||||||
description: intl.get('jump_to_the_trial_balance_sheet'),
|
description: intl.get('jump_to_the_trial_balance_sheet'),
|
||||||
|
permission: {
|
||||||
|
ability: ReportsAction.READ_TRIAL_BALANCE_SHEET,
|
||||||
|
subject: AbilitySubject.Report,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + I ',
|
shortcut_key: 'Ctrl + Shift + I ',
|
||||||
description: intl.get('create_a_new_invoice'),
|
description: intl.get('create_a_new_invoice'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleInvoiceAction.Create,
|
||||||
|
subject: AbilitySubject.Invoice,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + E ',
|
shortcut_key: 'Ctrl + Shift + E ',
|
||||||
description: intl.get('create_a_new_estimate'),
|
description: intl.get('create_a_new_estimate'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleEstimateAction.Create,
|
||||||
|
subject: AbilitySubject.Estimate,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + R ',
|
shortcut_key: 'Ctrl + Shift + R ',
|
||||||
description: intl.get('create_a_new_receipt'),
|
description: intl.get('create_a_new_receipt'),
|
||||||
|
permission: {
|
||||||
|
ability: SaleReceiptAction.Create,
|
||||||
|
subject: AbilitySubject.Receipt,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + X ',
|
shortcut_key: 'Ctrl + Shift + X ',
|
||||||
description: intl.get('create_a_new_expense'),
|
description: intl.get('create_a_new_expense'),
|
||||||
|
permission: {
|
||||||
|
ability: ExpenseAction.Create,
|
||||||
|
subject: AbilitySubject.Expense,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + C ',
|
shortcut_key: 'Ctrl + Shift + C ',
|
||||||
description: intl.get('create_a_new_customer'),
|
description: intl.get('create_a_new_customer'),
|
||||||
|
permission: {
|
||||||
|
ability: CustomerAction.Create,
|
||||||
|
subject: AbilitySubject.Customer,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + V ',
|
shortcut_key: 'Ctrl + Shift + V ',
|
||||||
description: intl.get('create_a_new_vendor'),
|
description: intl.get('create_a_new_vendor'),
|
||||||
|
permission: {
|
||||||
|
ability: VendorAction.Create,
|
||||||
|
subject: AbilitySubject.Vendor,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + B ',
|
shortcut_key: 'Ctrl + Shift + B ',
|
||||||
description: intl.get('create_a_new_bill'),
|
description: intl.get('create_a_new_bill'),
|
||||||
|
permission: {
|
||||||
|
ability: BillAction.Create,
|
||||||
|
subject: AbilitySubject.Bill,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + M ',
|
shortcut_key: 'Ctrl + Shift + M ',
|
||||||
description: intl.get('create_a_new_journal'),
|
description: intl.get('create_a_new_journal'),
|
||||||
|
permission: {
|
||||||
|
ability: ManualJournalAction.Create,
|
||||||
|
subject: AbilitySubject.ManualJournal,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + Shift + W ',
|
shortcut_key: 'Ctrl + Shift + W ',
|
||||||
description: intl.get('create_a_new_item'),
|
description: intl.get('create_a_new_item'),
|
||||||
|
permission: {
|
||||||
|
ability: ItemAction.Create,
|
||||||
|
subject: AbilitySubject.Item,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut_key: 'Ctrl + / ',
|
shortcut_key: 'Ctrl + / ',
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { DataTable } from 'components';
|
import { DataTable } from 'components';
|
||||||
import { FormattedMessage as T } from 'components';
|
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import keyboardShortcuts from 'common/keyboardShortcutsOptions';
|
import { useKeywordShortcuts } from '../../hooks/dashboard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* keyboard shortcuts table.
|
* keyboard shortcuts table.
|
||||||
*/
|
*/
|
||||||
function ShortcutsTable() {
|
export default function ShortcutsTable() {
|
||||||
|
const keywordShortcuts = useKeywordShortcuts();
|
||||||
|
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => [
|
||||||
@@ -30,8 +29,5 @@ function ShortcutsTable() {
|
|||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
return <DataTable columns={columns} data={keywordShortcuts} />;
|
||||||
return <DataTable columns={columns} data={keyboardShortcuts} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ShortcutsTable;
|
|
||||||
|
|||||||
1
src/hooks/dashboard/index.js
Normal file
1
src/hooks/dashboard/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './useKeywordShortcuts';
|
||||||
15
src/hooks/dashboard/useKeywordShortcuts.js
Normal file
15
src/hooks/dashboard/useKeywordShortcuts.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import keyboardShortcuts from 'common/keyboardShortcutsOptions';
|
||||||
|
import { useAbilitiesFilter } from '../utils/useAbilityContext';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the filtered keyword shortcuts.
|
||||||
|
*/
|
||||||
|
export const useKeywordShortcuts = () => {
|
||||||
|
const abilitiesFilter = useAbilitiesFilter();
|
||||||
|
|
||||||
|
return React.useMemo(
|
||||||
|
() => abilitiesFilter(keyboardShortcuts),
|
||||||
|
[abilitiesFilter],
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -12,11 +12,12 @@ export const useAbilitiesFilter = () => {
|
|||||||
|
|
||||||
return React.useCallback(
|
return React.useCallback(
|
||||||
(items) => {
|
(items) => {
|
||||||
return items.filter((item) =>
|
return items.filter(
|
||||||
ability.can(item.permission.ability, item.permission.subject),
|
(item) =>
|
||||||
|
!item.permission ||
|
||||||
|
ability.can(item.permission.ability, item.permission.subject),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[ability],
|
[ability],
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user