Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Field mapping updates #445

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 56 additions & 44 deletions apps/client-ts/src/app/(Dashboard)/configuration/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
'use client'

import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
Dialog,
DialogContent,
DialogTrigger,
} from "@/components/ui/dialog"
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/components/ui/tabs"
import { LinkedUsersPage } from "@/components/Configuration/LinkedUsers/LinkedUsersPage";
import { Button } from "@/components/ui/button";
import { PlusCircledIcon } from "@radix-ui/react-icons";
import { FModal } from "@/components/Configuration/FieldMappings/FieldMappingModal"
import { Separator } from "@/components/ui/separator";
import FieldMappingsTable from "@/components/Configuration/FieldMappings/FieldMappingsTable";
import AddLinkedAccount from "@/components/Configuration/LinkedUsers/AddLinkedAccount";
Expand All @@ -32,28 +23,22 @@ import { useState } from "react";
import AddWebhook from "@/components/Configuration/Webhooks/AddWebhook";
import { WebhooksPage } from "@/components/Configuration/Webhooks/WebhooksPage";
import useWebhooks from "@/hooks/get/useWebhooks";
import { usePostHog } from 'posthog-js/react'
import config from "@/lib/config";
import useProjectStore from "@/state/projectStore";
import useConnectionStrategies from "@/hooks/get/useConnectionStrategies";
import { extractAuthMode,extractProvider,extractVertical} from '@panora/shared'
import { Heading } from "@/components/ui/heading";
import CustomConnectorPage from "@/components/Configuration/Connector/CustomConnectorPage";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { HelpCircle } from "lucide-react";
import { Button } from "@/components/ui/button";

export default function Page() {
const {idProject} = useProjectStore();

const { data: linkedUsers, isLoading, error } = useLinkedUsers();
const { data: webhooks, isLoading: isWebhooksLoading, error: isWebhooksError } = useWebhooks();
const { data: connectionStrategies, isLoading: isConnectionStrategiesLoading, error: isConnectionStategiesError} = useConnectionStrategies()
const { data: mappings, isLoading: isFieldMappingsLoading, error: isFieldMappingsError } = useFieldMappings();

const [open, setOpen] = useState(false);
const handleClose = () => {
setOpen(false);
};

const posthog = usePostHog()

if(error){
console.log("error linked users..");
Expand Down Expand Up @@ -87,7 +72,7 @@ export default function Page() {
standard_object: mapping.ressource_owner_type,
source_app: mapping.source,
status: mapping.status,
category: mapping.ressource_owner_type,
category: mapping.ressource_owner_type.split('.')[0],
source_field: mapping.remote_id,
destination_field: mapping.slug,
data_type: mapping.data_type,
Expand Down Expand Up @@ -121,7 +106,31 @@ export default function Page() {
<AddLinkedAccount/>
<Card className="col-span-12">
<CardHeader>
<CardTitle className="text-left">Your Linked Accounts</CardTitle>
<CardTitle className="text-left flex items-center">
<span>Your Linked Accounts</span>
<TooltipProvider>
<Tooltip>
<Popover>
<PopoverTrigger asChild>
<TooltipTrigger asChild>
<Button variant={"link"} size="icon">
<HelpCircle className="h-4 w-4" />
<span className="sr-only">Help</span>
</Button>
</TooltipTrigger>
</PopoverTrigger>
<PopoverContent className="flex w-[420px] p-0">
<div className="flex flex-col gap-2 px-2 py-4">
<div className="grid min-w-[250px] gap-1 ">
<p className="font-bold text-sm">What are linked accounts ? </p>
</div>
</div>
</PopoverContent>
</Popover>
<TooltipContent>Help</TooltipContent>
</Tooltip>
</TooltipProvider>
</CardTitle>
<CardDescription className="text-left">
You connected {linkedUsers ? linkedUsers.length : <Skeleton className="w-[20px] h-[12px] rounded-md" />} linked accounts.
</CardDescription>
Expand All @@ -136,33 +145,36 @@ export default function Page() {

<TabsContent value="field-mappings" className="space-y-4">
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-12">
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button
size="sm"
className="h-7 gap-1 w-[180px]"
onClick={() => {
posthog?.capture("add_field_mappings_button_clicked", {
id_project: idProject,
mode: config.DISTRIBUTION
})}}
>
<span className="flex flex-row justify-center sr-only sm:not-sr-only sm:whitespace-nowrap">
<PlusCircledIcon className="h-3.5 w-3.5 mt-[3px] mr-1" />
Create Field Mappings
</span>
</Button>
</DialogTrigger>
<DialogContent className="sm:w-[450px] lg:max-w-screen-lg overflow-y-scroll max-h-screen">
<FModal onClose={handleClose}/>
</DialogContent>
</Dialog>
<Card className="col-span-12">
<CardHeader>
<CardTitle className="text-left">Your Fields Mapping</CardTitle>
<CardTitle className="text-left flex items-center">
<span>Your Fields Mappings</span>
<TooltipProvider>
<Tooltip>
<Popover>
<PopoverTrigger asChild>
<TooltipTrigger asChild>
<Button variant={"link"} size="icon">
<HelpCircle className="h-4 w-4" />
<span className="sr-only">Help</span>
</Button>
</TooltipTrigger>
</PopoverTrigger>
<PopoverContent className="flex w-[420px] p-0">
<div className="flex flex-col gap-2 px-2 py-4">
<div className="grid min-w-[250px] gap-1 ">
<p className="font-bold text-sm">What are field mappings ? </p>
</div>
</div>
</PopoverContent>
</Popover>
<TooltipContent>Help</TooltipContent>
</Tooltip>
</TooltipProvider>
</CardTitle>
<CardDescription className="text-left">
You built {mappings ? mappings.length : <Skeleton className="w-[20px] h-[12px] rounded-md" />} fields mappings.
<a href="https://docs.panora.dev/core-concepts/custom-fields" target="_blank" rel="noopener noreferrer">Learn more about custom field mappings</a>
<a href="https://docs.panora.dev/core-concepts/custom-fields" className="font-bold" target="_blank" rel="noopener noreferrer"> Learn more about custom field mappings in our docs !</a>
</CardDescription>
</CardHeader>
<Separator className="mb-10"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import {
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card"
Card,
CardContent,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { DataTable } from "@/components/shared/data-table";
import { columns } from "./columns";
import { useColumns } from "./columns";
import { DataTableLoading } from "@/components/shared/data-table-loading";

import { Button } from "@/components/ui/button";
import { PlusCircledIcon } from "@radix-ui/react-icons";
import { usePostHog } from "posthog-js/react";
import useProjectStore from "@/state/projectStore";
import config from "@/lib/config";
import {
Dialog,
DialogContent,
DialogTrigger,
} from "@/components/ui/dialog"
import { DefineForm } from "./defineForm";
import { useState } from "react";
import { MapForm } from "./mapForm";
export interface Mapping {
standard_object: string;
source_app: string;
Expand All @@ -20,8 +32,19 @@ export interface Mapping {

export default function FieldMappingsTable({
mappings,
isLoading
isLoading
}: { mappings: Mapping[] | undefined; isLoading: boolean }) {
const [defineOpen, setDefineOpen] = useState(false);
const [mapOpen, setMapOpen] = useState(false);
const columns = useColumns();
const handleDefineClose = () => {
setDefineOpen(false);
};
const handleMapClose = () => {
setMapOpen(false);
};
const posthog = usePostHog()
const {idProject} = useProjectStore();

const countDefined = mappings?.filter(mapping => mapping.status === "defined").length;
const countMapped = mappings?.filter(mapping => mapping.status === "mapped").length;
Expand All @@ -32,22 +55,65 @@ export default function FieldMappingsTable({
<>
<div className="hidden h-full flex-1 flex-col space-y-8 md:flex">
<div className="flex items-center space-x-4 justify-between flex-row">
<Card className="w-1/2">
<CardHeader>
<CardTitle>Defined</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{countDefined}</p>
</CardContent>

<Card className="relative w-1/2">
<CardHeader>
<CardTitle>Defined</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{countDefined}</p>
</CardContent>
<Dialog open={defineOpen} onOpenChange={setDefineOpen}>
<DialogTrigger asChild>
<Button
size="sm"
className="absolute bottom-0 right-0 mb-2 mr-2 h-7 gap-1 w-[180px]" // Adjusted classes
onClick={() => {
posthog?.capture("add_field_mappings_button_clicked", {
id_project: idProject,
mode: config.DISTRIBUTION
})
}}
>
<span className="flex flex-row justify-center sr-only sm:not-sr-only sm:whitespace-nowrap">
<PlusCircledIcon className="h-3.5 w-3.5 mt-[3px] mr-1" />
Define a custom field
</span>
</Button>
</DialogTrigger>
<DialogContent className="sm:w-[450px] lg:max-w-screen-lg overflow-y-scroll max-h-screen">
<DefineForm onClose={handleDefineClose}/>
</DialogContent>
</Dialog>
</Card>
<Card className="w-1/2">
<Card className="relative w-1/2">
<CardHeader>
<CardTitle>Mapped</CardTitle>
</CardHeader>
<CardContent>
<p className="text-4xl font-bold">{countMapped}</p>
</CardContent>
<Dialog open={mapOpen} onOpenChange={setMapOpen}>
<DialogTrigger asChild>
<Button
size="sm"
className="absolute bottom-0 right-0 mb-2 mr-2 h-7 gap-1 w-[180px]"
onClick={() => {
posthog?.capture("map_field_mappings_button_clicked", {
id_project: idProject,
mode: config.DISTRIBUTION
})
}}
>
<span className="flex flex-row justify-center sr-only sm:not-sr-only sm:whitespace-nowrap">
<PlusCircledIcon className="h-3.5 w-3.5 mt-[3px] mr-1" />
Map a custom field
</span>
</Button>
</DialogTrigger>
<DialogContent className="sm:w-[450px] lg:max-w-screen-lg overflow-y-scroll max-h-screen">
<MapForm onClose={handleMapClose}/>
</DialogContent>
</Dialog>
</Card>
</div>
{mappings && <DataTable data={mappings} columns={columns} />}
Expand Down
Loading
Loading