UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

36 lines (35 loc) 1.85 kB
import { jsx as t, jsxs as h } from "react/jsx-runtime"; import { useState as J, useRef as b, useEffect as m } from "react"; import { useDispatch as j, useSelector as u } from "react-redux"; import { CategoriesContext as w } from "./DataContext.js"; import { getCategories as v, setData as z } from "../reducers/data.js"; import { Container as S, Segment as x } from "semantic-ui-react"; const k = (d) => { const { app: e, filters: n, source: a, store: C, params: r = {}, csv: s, group: I, editing: g, children: P } = d, f = j(), [L, y] = J(!1), o = b({ filters: n, params: r, app: e, source: a, csv: s }), c = ["data", "categories", e]; r.dvzProxyDatasetId && c.push(r.dvzProxyDatasetId); const l = u((i) => i.getIn([...c, "items"])), D = u((i) => i.getIn([...c, "error"])), p = u((i) => i.getIn([...c, "loading"])); return m(() => { !l && !p && f(v(d)); }, []), m(() => { (n !== o.current.filters || JSON.stringify(r) !== JSON.stringify(o.current.params) || e !== o.current.app || o.current.source !== a || s !== o.current.csv) && (e === "csv" ? f(z({ app: e, csv: s, store: C, params: r, group: I })) : (g && (r.v = (Math.random() + 1).toString(36).substring(7)), y(!1), f(v(d)))), o.current = { filters: n, params: r, app: e, source: a, csv: s }; }, [n, r, e, a, s, g]), p ? /* @__PURE__ */ t(S, {}) : l ? /* @__PURE__ */ t(w.Provider, { value: l.toJS(), children: P }) : D ? /* @__PURE__ */ h(x, { color: "red", children: [ /* @__PURE__ */ t("h1", { children: "500" }), /* @__PURE__ */ t("p", { children: "Wasn't able to load data" }) ] }) : /* @__PURE__ */ t(S, { children: /* @__PURE__ */ h(x, { color: "red", children: [ /* @__PURE__ */ t("h1", { children: "404" }), /* @__PURE__ */ t("p", { children: "Can't find this page" }) ] }) }); }; export { k as default };