selectors.ts 694 B

123456789101112131415161718
  1. import { ApiKeysState } from 'app/types';
  2. export const getApiKeysCount = (state: ApiKeysState) =>
  3. state.includeExpired ? state.keysIncludingExpired.length : state.keys.length;
  4. export const getApiKeys = (state: ApiKeysState) => {
  5. const regex = RegExp(state.searchQuery, 'i');
  6. const keysToFilter = state.includeExpired ? state.keysIncludingExpired : state.keys;
  7. return keysToFilter.filter((key) => {
  8. return regex.test(key.name) || regex.test(key.role);
  9. });
  10. };
  11. export const getIncludeExpired = (state: ApiKeysState) => state.includeExpired;
  12. export const getIncludeExpiredDisabled = (state: ApiKeysState) =>
  13. state.keys.length === 0 && state.keysIncludingExpired.length > 0;