table.helpers.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { AppCategoriesEnum, AppInfo } from '../../../generated/graphql';
  2. import { AppTableData } from './table.types';
  3. export const sortTable = (data: AppTableData, col: keyof Pick<AppInfo, 'name'>, direction: 'asc' | 'desc', categories: AppCategoriesEnum[], search: string) => {
  4. const sortedData = [...data].sort((a, b) => {
  5. const aVal = a[col];
  6. const bVal = b[col];
  7. if (aVal < bVal) {
  8. return direction === 'asc' ? -1 : 1;
  9. }
  10. if (aVal > bVal) {
  11. return direction === 'asc' ? 1 : -1;
  12. }
  13. return 0;
  14. });
  15. if (categories.length > 0) {
  16. return sortedData.filter((app) => app.categories.some((c) => categories.includes(c))).filter((app) => app.name.toLowerCase().includes(search.toLowerCase()));
  17. } else {
  18. return sortedData.filter((app) => app.name.toLowerCase().includes(search.toLowerCase()));
  19. }
  20. };
  21. export const limitText = (text: string, limit: number) => {
  22. return text.length > limit ? `${text.substring(0, limit)}...` : text;
  23. };
  24. export const colorSchemeForCategory: Record<AppCategoriesEnum, string> = {
  25. [AppCategoriesEnum.Network]: 'blue',
  26. [AppCategoriesEnum.Media]: 'green',
  27. [AppCategoriesEnum.Automation]: 'orange',
  28. [AppCategoriesEnum.Development]: 'purple',
  29. [AppCategoriesEnum.Utilities]: 'gray',
  30. [AppCategoriesEnum.Photography]: 'red',
  31. [AppCategoriesEnum.Security]: 'yellow',
  32. [AppCategoriesEnum.Social]: 'teal',
  33. [AppCategoriesEnum.Featured]: 'pink',
  34. [AppCategoriesEnum.Data]: 'red',
  35. [AppCategoriesEnum.Books]: 'blue',
  36. [AppCategoriesEnum.Music]: 'green',
  37. };