Skip to content

Commit

Permalink
* feat(SFT-1555): add the possibility to add separators for object pr…
Browse files Browse the repository at this point in the history
…operties (#1624)

* feat(SFT-1555): translations for object property separators in builder
* feat(SFT-1555): added object separators for various CRM integrations in builder

---------

Co-authored-by: kjmartens <[email protected]>
  • Loading branch information
gustavs-gutmanis and kjmartens authored Nov 12, 2024
1 parent cadc777 commit 80dae07
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 2 deletions.
58 changes: 58 additions & 0 deletions packages/client/src/app/components/form-controls/delimiter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import type { Delimiter } from '@ff-client/types/properties';

type Props = {
delimiter?: Delimiter;
};

import { labelText } from '@ff-client/styles/mixins';
import { shadows } from '@ff-client/styles/variables';
import styled from 'styled-components';

const DelimiterWrapper = styled.div`
position: relative;
min-height: 10px;
&:before {
content: '';
position: absolute;
top: 9px;
left: 0;
right: 0;
z-index: 1;
height: 1px;
margin: 0 var(--margins);
box-shadow: ${shadows.bottom};
}
div {
position: absolute;
left: -5px;
top: 0;
z-index: 2;
background: var(--background-color);
padding: 0 5px;
${labelText};
font-size: 11px;
&:empty {
display: none;
}
}
`;

export const DelimiterElement: React.FC<Props> = ({ delimiter }) => {
if (!delimiter) {
return null;
}

return (
<DelimiterWrapper>
<div>{delimiter.name}</div>
</DelimiterWrapper>
);
};
3 changes: 3 additions & 0 deletions packages/client/src/app/components/form-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {

import { ErrorBoundary } from './boundaries/ErrorBoundary';
import { useVisibility } from './hooks/use-visibility';
import { DelimiterElement } from './delimiter';

export type UpdateValue<T> = (value: T) => void;

Expand Down Expand Up @@ -55,6 +56,8 @@ export const FormComponent: React.FC<Props> = ({
return (
<ErrorBoundary message={`...${handle} <${type}>`}>
<Suspense>
<DelimiterElement delimiter={property.delimiter} />

<FormControl
value={value as GenericValue}
property={property}
Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/app/components/layout/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export const Sidebar = styled.div<WrapperProps>`
background: ${colors.gray050};
overflow-y: auto;
--background-color: ${colors.gray050};
--margins: -18px;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ export const PropertyEditorWrapper = styled.div`
flex-direction: column;
gap: ${spacings.xl};
background: ${colors.white};
padding: ${spacings.xl};
background: ${colors.white};
overflow-y: auto;
${scrollBar};
--background-color: ${colors.white};
--margins: -24px;
h1 {
padding: 0;
margin-top: -11px;
Expand Down
6 changes: 6 additions & 0 deletions packages/client/src/types/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export type OptionGroup = {

export type OptionCollection = Array<Option | OptionGroup>;

export type Delimiter = {
name?: string;
icon?: string;
};

type BaseProperty<T, PT extends PropertyType> = {
type: PT;
handle: string;
Expand All @@ -78,6 +83,7 @@ type BaseProperty<T, PT extends PropertyType> = {
messages?: Message[];
visible?: boolean;
visibilityFilters?: VisibilityFilter[];
delimiter?: Delimiter;
middleware?: Middleware[];
category?: string;
section?: string;
Expand Down
22 changes: 22 additions & 0 deletions packages/plugin/src/Attributes/Property/Delimiter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Solspace\Freeform\Attributes\Property;

use Solspace\Freeform\Library\Serialization\Normalizers\CustomNormalizerInterface;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Delimiter implements CustomNormalizerInterface
{
public function __construct(
public ?string $name = null,
public ?string $icon = null,
) {}

public function normalize(): array
{
return [
'name' => $this->name,
'icon' => $this->icon,
];
}
}
1 change: 1 addition & 0 deletions packages/plugin/src/Attributes/Property/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class Property

/** @var VisibilityFilter[] */
public array $visibilityFilters = [];
public ?Delimiter $delimiter = null;

public bool $visible = true;
public bool $translatable = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Solspace\Freeform\Attributes\Property\DefaultValue;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Edition;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\Options\OptionCollection;
Expand Down Expand Up @@ -135,6 +136,7 @@ public function getEditableProperties(object|string $object): PropertyCollection
$this->processValidators($property, $attribute);
$this->processMiddleware($property, $attribute);
$this->processVisibilityFilters($property, $attribute);
$this->processDelimiters($property, $attribute);
$this->processDateProperties($attribute);
$this->processLimitations($property, $attribute);
$this->processMessages($property, $attribute);
Expand Down Expand Up @@ -369,6 +371,11 @@ private function processVisibilityFilters(\ReflectionProperty $property, Propert
$attribute->visibilityFilters = AttributeHelper::findAttributes($property, VisibilityFilter::class);
}

private function processDelimiters(\ReflectionProperty $property, Property $attribute): void
{
$attribute->delimiter = AttributeHelper::findAttribute($property, Delimiter::class);
}

private function processDateProperties(Property $attribute): void
{
if (!$attribute instanceof DatePicker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
use Solspace\Freeform\Attributes\Property\Input;
Expand All @@ -40,6 +41,7 @@ class ActiveCampaignV3 extends BaseActiveCampaignIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Contacts')]
#[Input\Boolean(
label: 'Map to Contact',
instructions: 'Should map to the Contact endpoint.',
Expand All @@ -65,6 +67,7 @@ class ActiveCampaignV3 extends BaseActiveCampaignIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Deals')]
#[Input\Boolean(
label: 'Map to Deal',
instructions: 'Should map to the Deal endpoint.',
Expand All @@ -90,6 +93,7 @@ class ActiveCampaignV3 extends BaseActiveCampaignIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Accounts')]
#[Input\Boolean(
label: 'Map to Account',
instructions: 'Should map to the Account endpoint.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapItem;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
Expand Down Expand Up @@ -41,6 +42,7 @@ class HubSpotV3 extends BaseHubSpotIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Deals')]
#[Input\Boolean(
label: 'Map to Deals',
instructions: 'Should map to the Deals endpoint.',
Expand All @@ -66,6 +68,7 @@ class HubSpotV3 extends BaseHubSpotIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Contacts')]
#[Input\Boolean(
label: 'Map to Contacts',
instructions: 'Should map to the Contacts endpoint.',
Expand All @@ -91,6 +94,7 @@ class HubSpotV3 extends BaseHubSpotIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Companies')]
#[Input\Boolean(
label: 'Map to Companies',
instructions: 'Should map to the Companies endpoint.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
use Solspace\Freeform\Attributes\Property\Input;
Expand All @@ -30,6 +31,7 @@ class InsightlyV31 extends BaseInsightlyIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Leads')]
#[Input\Boolean(
label: 'Map to Leads',
instructions: 'Should map to the Leads endpoint.',
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin/src/Integrations/CRM/Keap/Versions/KeapV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
use Solspace\Freeform\Attributes\Property\Input;
Expand All @@ -40,6 +41,7 @@ class KeapV2 extends BaseKeapIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Contacts')]
#[Input\Boolean(
label: 'Map to Contacts',
instructions: 'Should map to the Contacts endpoint.',
Expand All @@ -61,6 +63,7 @@ class KeapV2 extends BaseKeapIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Tags')]
#[Input\Boolean(
label: 'Map to Tags',
instructions: 'Should map to the Tags endpoint.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
use Solspace\Freeform\Attributes\Property\Input;
Expand All @@ -40,6 +41,7 @@ class PipedriveV1 extends BasePipedriveIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Leads')]
#[Input\Boolean(
label: 'Map to Leads',
instructions: 'Should map to the Leads endpoint.',
Expand All @@ -64,6 +66,7 @@ class PipedriveV1 extends BasePipedriveIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Deals')]
#[Input\Boolean(
label: 'Map to Deals',
instructions: 'Should map to the Deals endpoint.',
Expand Down Expand Up @@ -103,6 +106,7 @@ class PipedriveV1 extends BasePipedriveIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Organizations')]
#[Input\Boolean(
label: 'Map to Organization',
instructions: 'Should map to the Organization endpoint.',
Expand All @@ -128,6 +132,7 @@ class PipedriveV1 extends BasePipedriveIntegration

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Persons')]
#[Input\Boolean(
label: 'Map to Person',
instructions: 'Should map to the Person endpoint.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use craft\elements\Asset;
use GuzzleHttp\Client;
use Solspace\Freeform\Attributes\Integration\Type;
use Solspace\Freeform\Attributes\Property\Delimiter;
use Solspace\Freeform\Attributes\Property\Flag;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapItem;
use Solspace\Freeform\Attributes\Property\Implementations\FieldMapping\FieldMapping;
Expand Down Expand Up @@ -47,6 +48,7 @@ class SalesforceV58 extends BaseSalesforceIntegration implements SalesforceInteg

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Leads')]
#[Input\Boolean(
label: 'Map to Leads',
instructions: 'Map submission data to create Leads in Salesforce.',
Expand Down Expand Up @@ -132,6 +134,7 @@ class SalesforceV58 extends BaseSalesforceIntegration implements SalesforceInteg

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Opportunities')]
#[Input\Boolean(
label: 'Map to Opportunities',
instructions: 'Map submission data to create Opportunities in Salesforce.',
Expand Down Expand Up @@ -188,6 +191,7 @@ class SalesforceV58 extends BaseSalesforceIntegration implements SalesforceInteg

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Accounts')]
#[Input\Boolean(
label: 'Map to Accounts',
instructions: 'Map submission data to create Accounts in Salesforce.',
Expand Down Expand Up @@ -233,6 +237,7 @@ class SalesforceV58 extends BaseSalesforceIntegration implements SalesforceInteg

#[Flag(self::FLAG_INSTANCE_ONLY)]
#[VisibilityFilter('Boolean(enabled)')]
#[Delimiter('Contacts')]
#[Input\Boolean(
label: 'Map to Contacts',
instructions: 'Map submission data to create Contacts in Salesforce.',
Expand Down
Loading

0 comments on commit 80dae07

Please sign in to comment.