From ae31a676039d61d394a3221648a4daf3dbc596a9 Mon Sep 17 00:00:00 2001
From: Chiki <66981070+JulianBiancardi@users.noreply.github.com>
Date: Thu, 19 Sep 2024 14:55:49 -0300
Subject: [PATCH 01/12] feat: add card component and page view action
---
.../card/FastboardCard.tsx | 139 ++++++++++
.../card/FastboardCardDraggable.tsx | 20 ++
.../card/ImageComponent.tsx | 39 +++
.../card/TextComponent.tsx | 33 +++
.../card/properties/CardComponentsList.tsx | 71 +++++
.../CardImageComponentProperties.tsx | 45 ++++
.../CardTextComponentProperties.tsx | 83 ++++++
.../properties/FastboardCardProperties.tsx | 230 +++++++++++++++++
.../table/FastboardTable.tsx | 27 +-
.../properties/FastboardTableProperties.tsx | 3 +-
.../table/properties/TableActionsList.tsx | 3 +
.../table/properties/ViewActionProperties.tsx | 243 ++++++++++++++++++
.../editor/fastboard-components/utils.tsx | 30 ++-
src/components/shared/AlignmentProperty.tsx | 48 ++++
src/hooks/useData.ts | 8 +-
src/hooks/useNavigation.ts | 23 +-
src/lib/editor.utils.ts | 7 +-
src/lib/services/adapter.ts | 17 +-
src/lib/table.utils.ts | 13 +
src/types/editor/card-types.ts | 69 +++++
src/types/editor/index.ts | 1 +
src/types/editor/table-types.ts | 3 +
22 files changed, 1130 insertions(+), 25 deletions(-)
create mode 100644 src/components/editor/fastboard-components/card/FastboardCard.tsx
create mode 100644 src/components/editor/fastboard-components/card/FastboardCardDraggable.tsx
create mode 100644 src/components/editor/fastboard-components/card/ImageComponent.tsx
create mode 100644 src/components/editor/fastboard-components/card/TextComponent.tsx
create mode 100644 src/components/editor/fastboard-components/card/properties/CardComponentsList.tsx
create mode 100644 src/components/editor/fastboard-components/card/properties/CardImageComponentProperties.tsx
create mode 100644 src/components/editor/fastboard-components/card/properties/CardTextComponentProperties.tsx
create mode 100644 src/components/editor/fastboard-components/card/properties/FastboardCardProperties.tsx
create mode 100644 src/components/editor/fastboard-components/table/properties/ViewActionProperties.tsx
create mode 100644 src/components/shared/AlignmentProperty.tsx
create mode 100644 src/types/editor/card-types.ts
diff --git a/src/components/editor/fastboard-components/card/FastboardCard.tsx b/src/components/editor/fastboard-components/card/FastboardCard.tsx
new file mode 100644
index 00000000..d11608b9
--- /dev/null
+++ b/src/components/editor/fastboard-components/card/FastboardCard.tsx
@@ -0,0 +1,139 @@
+import { ComponentId, ComponentType } from "@/types/editor";
+import {
+ CardComponentProperties,
+ CardComponentType,
+ CardProperties,
+ TextComponentProperties,
+} from "@/types/editor/card-types";
+import { Card, CardBody, CardHeader, Image, Spinner } from "@nextui-org/react";
+import scrollbarStyles from "@/styles/scrollbar.module.css";
+import useData from "@/hooks/useData";
+import { toast } from "sonner";
+import { useEffect, useMemo, useState } from "react";
+import useNavigation from "@/hooks/useNavigation";
+import { useSetRecoilState } from "recoil";
+import { propertiesDrawerState } from "@/atoms/editor";
+import useDashboard from "@/hooks/dashboards/useDashboard";
+import TextComponent from "./TextComponent";
+import ImageComponent from "./ImageComponent";
+
+export default function FastboardCard({
+ id,
+ properties,
+}: {
+ id: ComponentId;
+ properties: CardProperties;
+}) {
+ const { sourceQueryData, queryParameters, components, showShadow } =
+ properties;
+ const { updateComponentProperties } = useDashboard();
+ const { getQueryParam } = useNavigation();
+ const traducedQueryParameters = useMemo(() => {
+ if (!queryParameters) return {};
+
+ return Object.entries(queryParameters).reduce((acc, parameter) => {
+ // Test if the value of the parametes has the synstax {{URL.queryValue}}
+ const pattern = /\{\{\s*URL\.([^\s]+)\s*\}\}/;
+ const match = parameter[1].match(pattern);
+ if (match) {
+ const queryValue = getQueryParam(match[1]);
+ return { ...acc, [parameter[0]]: queryValue };
+ }
+ return { ...acc, [parameter[0]]: parameter[1] };
+ }, {});
+ }, [queryParameters]);
+ const {
+ data,
+ keys,
+ isFetching: dataFetching,
+ isError: isDataError,
+ error: dataError,
+ } = useData(
+ `${ComponentType.Card}-${id}`,
+ sourceQueryData,
+ traducedQueryParameters
+ );
+ const setPropertiesState = useSetRecoilState(propertiesDrawerState);
+
+ useEffect(() => {
+ console.log("keys updated", keys);
+ updateComponentProperties(id, {
+ ...properties,
+ dataKeys: keys,
+ });
+ setPropertiesState((previous) => {
+ if (previous.selectedComponentId !== id) {
+ return previous;
+ }
+ return {
+ ...previous,
+ properties: {
+ ...previous.properties,
+ dataKeys: keys,
+ },
+ };
+ });
+ }, [keys]);
+
+ useEffect(() => {
+ if (isDataError) {
+ toast.error(dataError?.message);
+ }
+ }, [isDataError]);
+
+ function isValidData(data: any[]) {
+ if (data.length > 1) {
+ return false;
+ }
+ if (data.length === 0) {
+ return false;
+ }
+ return typeof data[0] === "object";
+ }
+
+ if (dataFetching) {
+ return
+ Error: {dataError?.message} +
+ ); + } + + function renderComponent(component: CardComponentProperties, data: any[]) { + const item = data[0]; + + switch (component.type) { + case CardComponentType.Text: { + return ( +Component not found
; + } + } + + return isValidData(data) ? ( ++ Seems like the data is not an object or is empty. +
+ ); +} diff --git a/src/components/editor/fastboard-components/card/FastboardCardDraggable.tsx b/src/components/editor/fastboard-components/card/FastboardCardDraggable.tsx new file mode 100644 index 00000000..d5bce513 --- /dev/null +++ b/src/components/editor/fastboard-components/card/FastboardCardDraggable.tsx @@ -0,0 +1,20 @@ +import Draggable from "../Draggable"; +import { ComponentType } from "@/types/editor"; +import DraggableImage from "@/components/shared/DraggableImage"; +import { CardProperties } from "@/types/editor/card-types"; + +export default function FastboardCardDraggable() { + return ( +
+ {"{{URL.queryValue}}"}
+ {" "}
+ syntax to access url query strings.
+ {"preview value"} setting
+ on queries editor.
+ Component not found
; } diff --git a/src/components/editor/fastboard-components/card/ImageComponent.tsx b/src/components/editor/fastboard-components/card/ImageComponent.tsx index b960bd7c..f494d894 100644 --- a/src/components/editor/fastboard-components/card/ImageComponent.tsx +++ b/src/components/editor/fastboard-components/card/ImageComponent.tsx @@ -10,7 +10,7 @@ export default function ImageComponent({ properties: ImageComponentProperties; item: any; }) { - const { dataKey, alignment } = properties; + const { dataKey, alignment, border } = properties; const [imageError, setImageError] = useState(false); useEffect(() => { @@ -20,7 +20,7 @@ export default function ImageComponent({ return (Position
-Photo Border Radius
Component not found
; } diff --git a/src/components/editor/fastboard-components/card/LinkComponent.tsx b/src/components/editor/fastboard-components/card/LinkComponent.tsx new file mode 100644 index 00000000..9c14378f --- /dev/null +++ b/src/components/editor/fastboard-components/card/LinkComponent.tsx @@ -0,0 +1,76 @@ +import { Alignment } from "@/components/shared/AlignmentProperty"; +import { Icon } from "@/components/shared/IconPicker"; +import { LinkComponentProperties } from "@/types/editor/card-types"; +import { Link } from "@nextui-org/react"; +import { useTheme } from "next-themes"; + +export default function LinkComponent({ + properties, + item, +}: { + properties: LinkComponentProperties; + item: any; +}) { + const { theme } = useTheme(); + const { + dataKey, + alignment, + label, + defaultText, + isExternal, + externalIcon, + showExternalIcon, + fontSize, + textColor, + labelColor, + } = properties; + + function addPrefix(url: string) { + if (!url.startsWith("http://") && !url.startsWith("https://")) { + return `https://${url}`; + } + return url; + } + + return ( +Seems like the data is not an object or is empty. From 9b8f47cacda311956c3ef97d416f462887037ff5 Mon Sep 17 00:00:00 2001 From: Chiki <66981070+JulianBiancardi@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:59:30 -0300 Subject: [PATCH 06/12] fix: styles and responsive --- .../card/FastboardCard.tsx | 6 +++-- .../card/ImageComponent.tsx | 2 +- src/components/shared/Viewport.tsx | 24 ++++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/components/editor/fastboard-components/card/FastboardCard.tsx b/src/components/editor/fastboard-components/card/FastboardCard.tsx index ec52229a..4abe1670 100644 --- a/src/components/editor/fastboard-components/card/FastboardCard.tsx +++ b/src/components/editor/fastboard-components/card/FastboardCard.tsx @@ -148,7 +148,7 @@ export default function FastboardCard({ return isValidData(data) ? (
diff --git a/src/components/editor/fastboard-components/card/ImageComponent.tsx b/src/components/editor/fastboard-components/card/ImageComponent.tsx index f494d894..adae2a43 100644 --- a/src/components/editor/fastboard-components/card/ImageComponent.tsx +++ b/src/components/editor/fastboard-components/card/ImageComponent.tsx @@ -32,7 +32,7 @@ export default function ImageComponent({ src={imageError ? "../ImageErrorImage.svg" : item[dataKey]} alt="Card image" width={"200px"} - height={"200px"} + height={"100%"} radius={border as any} onError={() => setImageError(true)} /> diff --git a/src/components/shared/Viewport.tsx b/src/components/shared/Viewport.tsx index e33e69e1..5ca415ea 100644 --- a/src/components/shared/Viewport.tsx +++ b/src/components/shared/Viewport.tsx @@ -107,17 +107,19 @@ export default function Viewport({ style={{ width: layoutsWidth }} > {selectedPage && selectedPage.returnPage && ( - +
- Error: {dataError?.message} -
- ); - } - function renderComponent(component: CardComponentProperties, data: any[]) { const item = data[0]; @@ -145,25 +133,51 @@ export default function FastboardCard({ } } - return isValidData(data) ? ( + return (+ {dataError?.message} +
+ )} + + {!dataFetching && !isDataError && ( + <> + {!sourceQueryData && ( ++ Seems like the data is not an object or is empty. +
+ )} + > )} -- Seems like the data is not an object or is empty. -
); } diff --git a/src/components/editor/fastboard-components/card/properties/FastboardCardProperties.tsx b/src/components/editor/fastboard-components/card/properties/FastboardCardProperties.tsx index 63e085b8..375f2564 100644 --- a/src/components/editor/fastboard-components/card/properties/FastboardCardProperties.tsx +++ b/src/components/editor/fastboard-components/card/properties/FastboardCardProperties.tsx @@ -1,12 +1,7 @@ import QuerySelection from "@/components/editor/QuerySelection"; import { CardComponentProperties, - CardComponentType, CardProperties, - ImageComponentProperties, - LinkComponentProperties, - TextComponentProperties, - VideoComponentProperties, } from "@/types/editor/card-types"; import { Accordion, @@ -15,21 +10,16 @@ import { Breadcrumbs, Code, Input, - Select, - SelectItem, Spacer, Tooltip, } from "@nextui-org/react"; import { RiQuestionLine } from "react-icons/ri"; import CardComponentsList from "./CardComponentsList"; import { useEffect, useState } from "react"; -import CardTextComponentProperties from "./CardTextComponentProperties"; import { useRecoilValue } from "recoil"; import { propertiesDrawerState } from "@/atoms/editor"; -import CardImageComponentProperties from "./CardImageComponentProperties"; -import CardVideoComponentProperties from "./CardVideoComponentProperties"; -import CardLinkComponentProperties from "./CardLinkComponentProperties"; import CardComponent from "./CardComponent"; +import { QueryType } from "@/types/connections"; export default function FastboardCardProperties({ properties, @@ -97,6 +87,7 @@ export default function FastboardCardProperties({ }} >Component not found
; } @@ -136,9 +153,14 @@ export default function FastboardCard({ return ({dataError?.message}
diff --git a/src/components/editor/fastboard-components/card/ImageComponent.tsx b/src/components/editor/fastboard-components/card/ImageComponent.tsx index c9a0a00d..70b92e0f 100644 --- a/src/components/editor/fastboard-components/card/ImageComponent.tsx +++ b/src/components/editor/fastboard-components/card/ImageComponent.tsx @@ -1,5 +1,6 @@ import { Alignment } from "@/components/shared/AlignmentProperty"; import { ImageComponentProperties } from "@/types/editor/card-types"; +import { FastboardHeaderPhotoSize } from "@/types/editor/header-types"; import { Image } from "@nextui-org/react"; import { useEffect, useState } from "react"; @@ -10,13 +11,24 @@ export default function ImageComponent({ properties: ImageComponentProperties; item: any; }) { - const { dataKey, alignment, border } = properties; + const { dataKey, alignment, border, size } = properties; const [imageError, setImageError] = useState(false); useEffect(() => { setImageError(false); }, [dataKey]); + function getSize(size: FastboardHeaderPhotoSize) { + switch (size) { + case FastboardHeaderPhotoSize.Small: + return "100px"; + case FastboardHeaderPhotoSize.Medium: + return "150px"; + case FastboardHeaderPhotoSize.Large: + return "300px"; + } + } + return (