aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/utils/table.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-19 12:23:39 -0300
committerSebastian <sebasjm@gmail.com>2022-12-19 12:23:39 -0300
commit72b429321553841ac1ff48cf974bfc65da01bb06 (patch)
tree7db9a4462f02de6cb86de695a1e64772b00ead5f /packages/merchant-backoffice-ui/src/utils/table.ts
parent770ab6f01dc81a16f384f314982bd761540f8e65 (diff)
downloadwallet-core-72b429321553841ac1ff48cf974bfc65da01bb06.tar.xz
pretty
Diffstat (limited to 'packages/merchant-backoffice-ui/src/utils/table.ts')
-rw-r--r--packages/merchant-backoffice-ui/src/utils/table.ts36
1 files changed, 20 insertions, 16 deletions
diff --git a/packages/merchant-backoffice-ui/src/utils/table.ts b/packages/merchant-backoffice-ui/src/utils/table.ts
index a79edfdcc..71358e25f 100644
--- a/packages/merchant-backoffice-ui/src/utils/table.ts
+++ b/packages/merchant-backoffice-ui/src/utils/table.ts
@@ -17,37 +17,41 @@
import { WithId } from "../declaration.js";
/**
-*
-* @author Sebastian Javier Marchano (sebasjm)
-*/
+ *
+ * @author Sebastian Javier Marchano (sebasjm)
+ */
export interface Actions<T extends WithId> {
element: T;
- type: 'DELETE' | 'UPDATE';
+ type: "DELETE" | "UPDATE";
}
function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
return value !== null && value !== undefined;
}
-export function buildActions<T extends WithId>(instances: T[], selected: string[], action: 'DELETE'): Actions<T>[] {
- return selected.map(id => instances.find(i => i.id === id))
+export function buildActions<T extends WithId>(
+ instances: T[],
+ selected: string[],
+ action: "DELETE",
+): Actions<T>[] {
+ return selected
+ .map((id) => instances.find((i) => i.id === id))
.filter(notEmpty)
- .map(id => ({ element: id, type: action }))
+ .map((id) => ({ element: id, type: action }));
}
/**
* For any object or array, return the same object if is not empty.
- * not empty:
+ * not empty:
* - for arrays: at least one element not undefined
* - for objects: at least one property not undefined
- * @param obj
- * @returns
+ * @param obj
+ * @returns
*/
-export function undefinedIfEmpty<T extends Record<string, unknown>|Array<unknown>>(obj: T): T | undefined {
- if (obj === undefined) return undefined
- return Object.values(obj).some((v) => v !== undefined)
- ? obj
- : undefined;
+export function undefinedIfEmpty<
+ T extends Record<string, unknown> | Array<unknown>,
+>(obj: T): T | undefined {
+ if (obj === undefined) return undefined;
+ return Object.values(obj).some((v) => v !== undefined) ? obj : undefined;
}
-