@hortiview/shared-components 0.0.6285 → 0.0.6320

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,4 +50,4 @@ import { TableLayoutProps } from '../../types/GenericTable';
50
50
  * @param headerTranslation function that will be called to translate the headers by its key
51
51
  * @returns a table based on a given type and data
52
52
  */
53
- export declare const GenericTable: <T>({ data, hiddenColumns, order, cellTemplates, tableActions, noContentText, headerTranslation, pagination, getRowActions, }: TableLayoutProps<T>) => import("react/jsx-runtime").JSX.Element;
53
+ export declare const GenericTable: <T>({ data, hiddenColumns, order, cellTemplates, tableActions, noContentText, headerTranslation, pagination, getRowActions, customColumnWidth, title, }: TableLayoutProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,89 +1,98 @@
1
1
  import "../../assets/GenericTable.css";
2
- import { jsx as n } from "react/jsx-runtime";
3
- import { Elevation as h, Table as v, TableTopBar as y, Group as d, TypoSubtitle as B } from "@element/react-components";
4
- import { useMemo as b, Fragment as g } from "react";
5
- import { ContextMenu as T } from "../ContextMenu/ContextMenu.js";
6
- const x = "_topBar_1msoo_1", N = "_filterBar_1msoo_5", C = "_emptyTable_1msoo_9", I = "_elevation_1msoo_17", M = "_table_1msoo_22", m = {
7
- topBar: x,
8
- filterBar: N,
9
- emptyTable: C,
10
- elevation: I,
11
- table: M
12
- }, W = (e, l) => {
13
- if (!e)
2
+ import { jsx as e, jsxs as B } from "react/jsx-runtime";
3
+ import { Elevation as T, Table as x, TableTopBar as b, Group as _, Padding as N, TypoDisplay as j, TypoSubtitle as C } from "@element/react-components";
4
+ import { useMemo as v, Fragment as D } from "react";
5
+ import { ContextMenu as I } from "../ContextMenu/ContextMenu.js";
6
+ const M = "_topBar_1msoo_1", G = "_filterBar_1msoo_5", O = "_emptyTable_1msoo_9", P = "_elevation_1msoo_17", W = "_table_1msoo_22", d = {
7
+ topBar: M,
8
+ filterBar: G,
9
+ emptyTable: O,
10
+ elevation: P,
11
+ table: W
12
+ }, z = (n, l) => {
13
+ if (!n)
14
14
  return [];
15
- let o = Object.keys(e).map((r) => r);
16
- return l.length > 0 && (o = o.sort((r, u) => {
17
- const p = l.findIndex((s) => s === r), i = l.findIndex((s) => s === u);
18
- return p === -1 ? 1 : i === -1 ? -1 : p - i;
15
+ let o = Object.keys(n).map((t) => t);
16
+ return l.length > 0 && (o = o.sort((t, i) => {
17
+ const m = l.findIndex((c) => c === t), s = l.findIndex((c) => c === i);
18
+ return m === -1 ? 1 : s === -1 ? -1 : m - s;
19
19
  })), o;
20
- }, E = ({
21
- data: e = [],
20
+ }, $ = ({
21
+ data: n = [],
22
22
  hiddenColumns: l = [],
23
23
  order: o = [],
24
- cellTemplates: r = void 0,
25
- tableActions: u = [],
26
- noContentText: p = "No data available",
27
- headerTranslation: i = (f) => f,
28
- pagination: s = !1,
29
- getRowActions: c = void 0
24
+ cellTemplates: t = void 0,
25
+ tableActions: i = [],
26
+ noContentText: m = "No data available",
27
+ headerTranslation: s = (f) => f,
28
+ pagination: c = !1,
29
+ getRowActions: p = void 0,
30
+ customColumnWidth: h,
31
+ title: u
30
32
  }) => {
31
- const f = b(() => {
32
- if (e.length === 0)
33
+ const f = v(() => {
34
+ if (n.length === 0)
33
35
  return [];
34
- const a = W(e[0], o).map((t) => ({
35
- id: t,
36
- header: i(t),
37
- accessor: t,
38
- cellTemplate: r ? r[t] : void 0
39
- }));
40
- return c ? [...a, { id: "actions", header: "", accessor: "actions" }] : a;
41
- }, [e, r, o, i, c]), _ = b(() => c ? e.map((a) => {
42
- const t = /* @__PURE__ */ n(T, { actions: c(a), iconOrientation: "horizontal" });
43
- return { ...a, actions: t };
44
- }) : e, [e, c]);
45
- return /* @__PURE__ */ n(h, { elevation: 1, className: m.elevation, children: /* @__PURE__ */ n(
46
- v,
36
+ const a = z(n[0], o).map((r) => {
37
+ const y = h ? h[r] : void 0;
38
+ return {
39
+ id: r,
40
+ header: s(r),
41
+ accessor: r,
42
+ cellTemplate: t ? t[r] : void 0,
43
+ cellProps: { width: y }
44
+ };
45
+ });
46
+ return p ? [...a, { id: "actions", header: "", accessor: "actions" }] : a;
47
+ }, [n, t, o, s, p, h]), g = v(() => p ? n.map((a) => {
48
+ const r = /* @__PURE__ */ e(I, { actions: p(a), iconOrientation: "horizontal" });
49
+ return { ...a, actions: r };
50
+ }) : n, [n, p]);
51
+ return /* @__PURE__ */ e(T, { elevation: 1, className: d.elevation, children: /* @__PURE__ */ e(
52
+ x,
47
53
  {
48
- className: m.table,
54
+ className: d.table,
49
55
  fullWidth: !0,
50
56
  alwaysUseDivTags: !0,
51
57
  layout: "standard",
52
58
  hiddenColumns: l,
53
- data: _,
59
+ data: g,
54
60
  columns: f,
55
- leadingContent: u.length > 0 && /* @__PURE__ */ n(
56
- y,
61
+ leadingContent: u && i.length === 0 ? /* @__PURE__ */ e(b, { title: u }) : i.length > 0 && /* @__PURE__ */ e(
62
+ b,
57
63
  {
58
- className: m.topBar,
59
- filterBar: /* @__PURE__ */ n(
60
- d,
61
- {
62
- className: m.filterBar,
63
- fullWidth: !0,
64
- primaryAlign: "center",
65
- secondaryAlign: "center",
66
- children: u.map((a, t) => /* @__PURE__ */ n(g, { children: a }, `action_${t}`))
67
- }
68
- )
64
+ className: d.topBar,
65
+ filterBar: /* @__PURE__ */ B(_, { fullWidth: !0, direction: "vertical", gap: "none", children: [
66
+ u && /* @__PURE__ */ e(N, { children: /* @__PURE__ */ e(j, { level: 6, children: u }) }),
67
+ /* @__PURE__ */ e(
68
+ _,
69
+ {
70
+ className: d.filterBar,
71
+ fullWidth: !0,
72
+ primaryAlign: "center",
73
+ secondaryAlign: "center",
74
+ children: i.map((a, r) => /* @__PURE__ */ e(D, { children: a }, `action_${r}`))
75
+ }
76
+ )
77
+ ] })
69
78
  }
70
79
  ),
71
- paginated: s,
80
+ paginated: c,
72
81
  sortable: !0,
73
82
  noContentIncludeTable: !!f,
74
- noContentMessage: /* @__PURE__ */ n(
75
- d,
83
+ noContentMessage: /* @__PURE__ */ e(
84
+ _,
76
85
  {
77
86
  fullWidth: !0,
78
87
  primaryAlign: "center",
79
88
  secondaryAlign: "center",
80
- className: m.emptyTable,
81
- children: /* @__PURE__ */ n(B, { children: p })
89
+ className: d.emptyTable,
90
+ children: /* @__PURE__ */ e(C, { children: m })
82
91
  }
83
92
  )
84
93
  }
85
94
  ) });
86
95
  };
87
96
  export {
88
- E as GenericTable
97
+ $ as GenericTable
89
98
  };
@@ -1,54 +1,71 @@
1
- import { jsx as o, jsxs as B } from "react/jsx-runtime";
2
- import { r as d, s as t } from "../../react.esm-D9-uytwS.js";
1
+ import { jsx as a, jsxs as u } from "react/jsx-runtime";
2
+ import { r as i, s as e } from "../../react.esm-D9-uytwS.js";
3
3
  import { GenericTable as c } from "./GenericTable.js";
4
- import { d as u, t as i, g as e, v as m } from "../../vi.JYQecGiw-BbUbJcT8.js";
5
- u("GenericTable Test", () => {
6
- const T = [];
7
- i("render GenericTable with custom no content text", () => {
8
- d(/* @__PURE__ */ o(c, { data: T, noContentText: "noContent" })), e(t.getByText("noContent")).toBeInTheDocument();
9
- }), i("render GenericTable with data should render headers", () => {
10
- d(/* @__PURE__ */ o(c, { data: [{ id: 1, name: "test" }] })), e(t.getByText("id")).toBeInTheDocument(), e(t.getByText("name")).toBeInTheDocument();
11
- }), i("render GenericTable with hidden headers", () => {
12
- d(/* @__PURE__ */ o(c, { data: [{ id: 1, name: "test" }], hiddenColumns: ["name"] })), e(t.getByText("id")).toBeInTheDocument(), e(t.queryByText("name")).not.toBeInTheDocument();
13
- }), i("render GenericTable with custom header translation", () => {
14
- d(/* @__PURE__ */ o(c, { data: [{ id: 1, name: "test" }], headerTranslation: (a) => a + ".translated" })), e(t.getByText("id.translated")).toBeInTheDocument(), e(t.getByText("name.translated")).toBeInTheDocument();
15
- }), i("render GenericTable with custom cell template", () => {
16
- d(
17
- /* @__PURE__ */ o(
4
+ import { d as B, t as d, g as t, v as r } from "../../vi.JYQecGiw-BbUbJcT8.js";
5
+ B("GenericTable Test", () => {
6
+ const m = [];
7
+ d("render GenericTable with custom no content text", () => {
8
+ i(/* @__PURE__ */ a(c, { data: m, noContentText: "noContent" })), t(e.getByText("noContent")).toBeInTheDocument();
9
+ }), d("render GenericTable with data should render headers", () => {
10
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }] })), t(e.getByText("id")).toBeInTheDocument(), t(e.getByText("name")).toBeInTheDocument();
11
+ }), d("render GenericTable with hidden headers", () => {
12
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], hiddenColumns: ["name"] })), t(e.getByText("id")).toBeInTheDocument(), t(e.queryByText("name")).not.toBeInTheDocument();
13
+ }), d("render GenericTable with custom header translation", () => {
14
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], headerTranslation: (o) => o + ".translated" })), t(e.getByText("id.translated")).toBeInTheDocument(), t(e.getByText("name.translated")).toBeInTheDocument();
15
+ }), d("render GenericTable with custom cell template", () => {
16
+ i(
17
+ /* @__PURE__ */ a(
18
18
  c,
19
19
  {
20
20
  data: [{ id: 1, name: "test" }],
21
- cellTemplates: { id: (a) => /* @__PURE__ */ B("div", { children: [
21
+ cellTemplates: { id: (o) => /* @__PURE__ */ u("div", { children: [
22
22
  "label: ",
23
- a.row.original.id
23
+ o.row.original.id
24
24
  ] }) }
25
25
  }
26
26
  )
27
- ), e(t.getByText("label: 1")).toBeInTheDocument();
28
- }), i("render GenericTable with custom table actions", () => {
29
- const n = m.fn();
30
- d(/* @__PURE__ */ o(c, { data: [{ id: 1, name: "test" }], tableActions: [
31
- /* @__PURE__ */ o("button", { "data-testid": "testButton", onClick: n, children: "testbutton" }, "test")
32
- ] })), e(t.getByText("testbutton")).toBeInTheDocument(), t.getByTestId("testButton").click(), e(n).toHaveBeenCalled();
33
- }), i("render GenericTable with custom pagination", () => {
34
- d(/* @__PURE__ */ o(c, { data: [
27
+ ), t(e.getByText("label: 1")).toBeInTheDocument();
28
+ }), d("render GenericTable with custom table actions", () => {
29
+ const n = r.fn();
30
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], tableActions: [
31
+ /* @__PURE__ */ a("button", { "data-testid": "testButton", onClick: n, children: "testbutton" }, "test")
32
+ ] })), t(e.getByText("testbutton")).toBeInTheDocument(), e.getByTestId("testButton").click(), t(n).toHaveBeenCalled();
33
+ }), d("render GenericTable with custom pagination", () => {
34
+ i(/* @__PURE__ */ a(c, { data: [
35
35
  { id: 1, name: "test" },
36
36
  { id: 2, name: "test2" },
37
37
  { id: 3, name: "test3" }
38
- ], pagination: !0 })), e(t.getByText("1 - 3 of 3")).toBeInTheDocument(), e(t.getByText("last_page")).toBeInTheDocument();
39
- }), i("render GenericTable with custom getRowActions", () => {
40
- const n = [{ id: 1, name: "test" }], a = m.fn();
41
- d(/* @__PURE__ */ o(c, { data: n, getRowActions: (l) => [
38
+ ], pagination: !0 })), t(e.getByText("1 - 3 of 3")).toBeInTheDocument(), t(e.getByText("last_page")).toBeInTheDocument();
39
+ }), d("render GenericTable with custom getRowActions", () => {
40
+ const n = [{ id: 1, name: "test" }], o = r.fn();
41
+ i(/* @__PURE__ */ a(c, { data: n, getRowActions: (T) => [
42
42
  {
43
43
  primaryText: "primText",
44
44
  secondaryText: "secText",
45
- onClick: () => a(l.id),
45
+ onClick: () => o(T.id),
46
46
  leadingBlock: "edit"
47
47
  }
48
- ] })), e(t.getByText("primText")).toBeInTheDocument(), t.getByText("primText").click(), e(a).toHaveBeenCalledWith(1);
49
- }), i("render GenericTable with custom order", () => {
50
- d(/* @__PURE__ */ o(c, { data: [{ id: 1, name: "test", age: 20 }], order: ["name", "age"] }));
51
- const a = t.getByText("id"), r = t.getByText("name"), s = t.getByText("age");
52
- e(r).toBeInTheDocument(), e(s).toBeInTheDocument(), e(a).toBeInTheDocument(), e(r.compareDocumentPosition(s)).toBe(4), e(s.compareDocumentPosition(a)).toBe(4);
48
+ ] })), t(e.getByText("primText")).toBeInTheDocument(), e.getByText("primText").click(), t(o).toHaveBeenCalledWith(1);
49
+ }), d("render GenericTable with custom order", () => {
50
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test", age: 20 }], order: ["name", "age"] }));
51
+ const o = e.getByText("id"), s = e.getByText("name"), l = e.getByText("age");
52
+ t(s).toBeInTheDocument(), t(l).toBeInTheDocument(), t(o).toBeInTheDocument(), t(s.compareDocumentPosition(l)).toBe(4), t(l.compareDocumentPosition(o)).toBe(4);
53
+ }), d("render GenericTable with custom columnWidth in pixel", () => {
54
+ i(
55
+ /* @__PURE__ */ a(c, { data: [{ id: 1, name: "test", age: 20 }], customColumnWidth: { id: 200, name: 200, age: 200 } })
56
+ );
57
+ const s = e.getAllByRole("cell")[0].getAttribute("width");
58
+ t(s).toBe("200");
59
+ }), d("render GenericTable with custom columnWidth in percent", () => {
60
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], customColumnWidth: { id: "50%", name: "50%" } }));
61
+ const s = e.getAllByRole("cell")[0].getAttribute("width");
62
+ t(s).toBe("50%");
63
+ }), d("render GenericTable with title", () => {
64
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], title: "test-title" })), t(e.getByText("test-title")).toBeInTheDocument();
65
+ }), d("render GenericTable with title and table actions", () => {
66
+ const n = r.fn();
67
+ i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], title: "test-title", tableActions: [
68
+ /* @__PURE__ */ a("button", { "data-testid": "testButton", onClick: n, children: "test-button" }, "test")
69
+ ] })), t(e.getByText("test-title")).toBeInTheDocument(), t(e.getByText("test-button")).toBeInTheDocument(), e.getByTestId("testButton").click(), t(n).toHaveBeenCalled();
53
70
  });
54
71
  });
@@ -61,6 +61,15 @@ export type TableLayoutProps<T> = {
61
61
  * @returns an array of ListItemProps that will be shown as actions for the row
62
62
  */
63
63
  getRowActions?: (row: T) => ListItemProps[];
64
+ /**
65
+ * custom column width that is specified by a column key. Note, can be a unit-less number (in pixels) or a percentage "10%"
66
+ * @example customColumnWidth={{ id: '15%', actionColumn: '10%' }}
67
+ */
68
+ customColumnWidth?: Partial<Record<keyof T, number | string>>;
69
+ /**
70
+ * table title to be displayed in the TableTopBar
71
+ */
72
+ title?: string;
64
73
  };
65
74
  /**
66
75
  * Props for the CellTemplate component {@link CellTemplate}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/shared-components",
3
3
  "description": "This is a shared component library. It should used in the HortiView platform and its modules.",
4
- "version": "0.0.6285",
4
+ "version": "0.0.6320",
5
5
  "type": "module",
6
6
  "repository": "https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared",
7
7
  "author": "Falk Menge <falk.menge.ext@bayer.com>",