Skip to content

Commit

Permalink
more custom generic elements and localization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Apr 3, 2024
1 parent 1d25fd4 commit 6e0f6a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 5 additions & 5 deletions apps/exhibition-live/components/config/tableConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ const dateColDef: (
header: t(p([...path, key])),
id: p([...path, key, "single"]),
accessorFn: mkAccessor(`${p([...path, key, "single"])}.value`, "", (v) =>
specialDate2LocalDate(v, "de"),
typeof v === "string" || (typeof v === "number" && String(v).length === 8)
? specialDate2LocalDate(Number(v), "de")
: String(v),
),
filterVariant: "date",
filterFn: "betweenInclusive",
sortingFn: "datetime",
Cell: ({ cell }) => {
const val = cell.getValue<Date>();
return val && typeof val.toLocaleDateString === "function"
? val.toLocaleDateString()
: "";
const val = cell.getValue<string>();
return val || "";
},
Header: ({ column }) => <em>{column.columnDef.header}</em>,
muiFilterTextFieldProps: {
Expand Down
21 changes: 21 additions & 0 deletions apps/exhibition-live/components/form/lobid/LobidAllPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Accordion,
AccordionDetails,
AccordionSummary,
Box,
Button,
Checkbox,
Container,
Expand Down Expand Up @@ -35,6 +36,8 @@ import { OverflowContainer } from "../../lists";
import { specialDate2LocalDate } from "../../utils/specialDate2LocalDate";
import { useTranslation } from "next-i18next";
import isNil from "lodash/isNil";
import { isValidUrl } from "@slub/edb-core-utils";
import { Image } from "mui-image";

interface OwnProps {
allProps?: any;
Expand Down Expand Up @@ -80,6 +83,10 @@ const LabledLink = ({
);
};

const isImageUrl = (url: string) => {
return url.match(/\.(jpeg|jpg|gif|png)?\?.*$/) != null;
};

const useMenuState = () => {
const [menuAnchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const menuOpen = Boolean(menuAnchorEl);
Expand Down Expand Up @@ -251,6 +258,20 @@ const PropertyItem = ({
) : typeof value === "string" || typeof value === "number" ? (
property.toLowerCase().includes("date") ? (
specialDate2LocalDate(value as number, locale)
) : isValidUrl(value as string) ? (
isImageUrl(value as string) ? (
<Box sx={{ display: "flex", justifyContent: "end" }}>
<Link href={value as string} target="_blank">
<Image
src={value as string}
alt={value as string}
width={100}
/>
</Link>
</Box>
) : (
<LabledLink uri={value as string} />
)
) : (
value.toLocaleString()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dayjs from "dayjs";
export const specialDate2LocalDate = (date: number, locale: string) => {
const { year, month, day } = getDateParts(date);
const jsdate = numeric2JSDate(date);
if (!year) {
if (!year && month && day) {
return dayjs(jsdate).format("MM.DD.");
}
if (!day && month && year) {
Expand Down

0 comments on commit 6e0f6a9

Please sign in to comment.