@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.
166 lines (165 loc) • 5.85 kB
JavaScript
import { jsx as a } from "react/jsx-runtime";
import K, { useState as V, useEffect as Q } from "react";
import { Container as R, Loader as X, Grid as Y, GridRow as Z } from "semantic-ui-react";
import $ from "../connected-templates/PostIntro.js";
import { injectIntl as tt } from "react-intl";
import { getStartDateAndEndDateFromYear as B } from "./utils.js";
import et from "./NoData.js";
import { useDispatch as ot, useSelector as rt } from "react-redux";
import { getCustomPosts as nt } from "../reducers/data-api.js";
import { useParams as st } from "react-router";
import { toNumber as at, toBoolean as it } from "../../utils/data.js";
const lt = (b) => {
const { posts: l, numberOfColumns: x, sortFirstBy: u, countryCategory: i, postWidth: p, postHeight: S } = b, m = [];
if (i && u && u !== "none") {
const c = l.filter((f) => f[i].includes(Number(u))), y = l.filter((f) => !f[i].includes(Number(u)));
m.push(...c), m.push(...y);
} else
m.push(...l);
return /* @__PURE__ */ a(Y, { className: "filtered-posts", columns: x, children: /* @__PURE__ */ a(Z, { children: m.map((c) => /* @__PURE__ */ a(Y.Column, { children: /* @__PURE__ */ a("div", { className: "filtered-posts-column", style: { width: p, height: S, overflow: "hidden" }, children: /* @__PURE__ */ a(
$,
{
style: {
width: "100%",
height: "100%",
overflow: "hidden",
margin: 0,
padding: 0
},
as: R,
fluid: !0,
post: c
},
c.id
) }) }, c.id)) }) });
}, ut = (b) => {
const {
"data-group": l,
"data-number-of-columns": x,
"data-type": u,
"data-taxonomy": i,
"data-categories": p,
"data-height": S,
"data-post-width": m,
"data-post-height": c,
"data-number-of-items-per-page": y,
"data-enable-sorting": f,
"data-sort-first-by": C,
"data-sorting-taxonomy": v,
editing: z
} = b, M = ot(), { locale: j } = st(), [D, h] = V(!1), w = rt((t) => t).getIn(["data", "posts", l]), [F, T] = V([]), A = it(f) && C !== "none" ? at(C) : null, g = w ?? {
yearFilter: null,
categoryFilter: null,
countryFilter: null,
page: 1,
countryTaxonomy: null,
categoryTaxonomy: null
}, N = (t) => {
if (t == null)
return { values: [], isExplicitNone: !1 };
const e = Array.isArray(t) ? t : [t], s = e.some(
(o) => Number(o) === Number.MIN_SAFE_INTEGER
);
return {
values: e.map((o) => Number(o)).filter((o) => Number.isFinite(o) && o !== Number.MIN_SAFE_INTEGER),
isExplicitNone: s
};
}, H = (t) => {
if (!t || t.length === 0)
return null;
const e = Array.from(new Set(t)).sort((E, P) => E - P);
if (e.length === 0)
return null;
const s = e[0], r = e[e.length - 1], o = B(s), n = B(r);
return !(o != null && o.startDate) || !(n != null && n.endDate) ? null : {
startDate: o.startDate,
endDate: n.endDate
};
}, W = () => {
const t = N(g.yearFilter), e = t.isExplicitNone ? null : H(t.values), s = g.countryFilter ?? null, r = g.categoryFilter ?? null, o = g.categoryTaxonomy || (i && i !== "none" ? i : null), n = g.countryTaxonomy || null;
return {
before: (e == null ? void 0 : e.endDate) || null,
after: (e == null ? void 0 : e.startDate) || null,
categoryFilter: r,
categoryTaxonomy: o,
countryFilter: s,
countryTaxonomy: n
};
}, I = (t) => z ? t : decodeURIComponent(t), J = (t) => {
try {
return JSON.parse(I(t));
} catch (e) {
return console.warn("JSON parsing failed for value:", t, "- treating as plain string. Error:", e), I(t);
}
}, L = () => {
const t = J(p);
return t ? typeof t == "string" ? t.split(",").map(Number) : typeof t == "number" ? [t] : t : [];
}, q = (t, e, s) => {
if (s) return null;
if (t.length === 0) return e.length > 0 ? e : null;
if (e.length === 0) return t;
const r = new Set(t), o = e.filter((n) => r.has(n));
return o.length > 0 ? o : null;
}, U = async () => {
h(!0);
const t = W(), e = N(L()).values, s = N(t.categoryFilter), r = q(
e,
s.values,
s.isExplicitNone
), o = N(t.countryFilter);
if (s.isExplicitNone) {
T([]), h(!1);
return;
}
if (o.isExplicitNone) {
T([]), h(!1);
return;
}
const n = /* @__PURE__ */ new Map();
t.categoryTaxonomy && r && r.length > 0 && n.set(t.categoryTaxonomy, r), t.countryTaxonomy && o.values.length > 0 && n.set(t.countryTaxonomy, o.values);
const E = r ? r.join(",") : void 0, P = {
after: t.after,
before: t.before,
perPage: Number(y || 10),
page: g.page || 1,
locale: j || "en",
postType: u,
taxonomy: t.categoryTaxonomy || void 0,
category: E || void 0,
taxonomyFilters: n,
ordering: "date",
orderingDirection: "desc"
};
await nt(P).then((O) => {
if (O) {
const { data: k, meta: d } = O;
T(k);
const _ = d && d["x-wp-totalpages"] ? d["x-wp-totalpages"] : 1, G = d && d["x-wp-total"] ? d["x-wp-total"] : 0;
_ && G && M({
type: "SET_POSTS_PAGINATION",
group: l,
totalPages: Number(_),
totalItems: Number(G)
});
}
}).finally(() => {
h(!1);
});
};
return Q(() => {
(async () => await U())();
}, [w, u, i, y, p, A, v]), /* @__PURE__ */ a(R, { fluid: !0, children: D ? /* @__PURE__ */ a(X, { active: !0, inline: "centered" }) : !D && F && F.length > 0 ? /* @__PURE__ */ a(
lt,
{
posts: F,
postWidth: Number(m),
postHeight: Number(c),
numberOfColumns: Number(x),
sortFirstBy: A,
countryCategory: v
}
) : /* @__PURE__ */ a(et, { noDataMsg: "No posts found", group: l }) });
}, Tt = tt(K.memo(ut));
export {
Tt as default
};