Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
add [properties] - link data type display (#73)
Daniel Kweondf9414bc2b66
diff --git a/js/app/packages/core/component/Properties/api/converters.ts b/js/app/packages/core/component/Properties/api/converters.tsindex 31d46b4a65..76e4169c0d 100644--- a/js/app/packages/core/component/Properties/api/converters.ts+++ b/js/app/packages/core/component/Properties/api/converters.ts@@ -110,12 +110,18 @@ export function toApiFormat(};case 'LINK':- if (apiValues.value === null) {+ if (!apiValues.values || apiValues.values.length === 0) {return null;}+ if (isMultiSelect) {+ return {+ type: 'multi_link',+ urls: apiValues.values,+ };+ }return {- type: 'string',- value: apiValues.value,+ type: 'link',+ url: apiValues.values[0],};default:@@ -290,11 +296,12 @@ export function fromApiFormat(if (propertyValue &&'type' in propertyValue &&- propertyValue.type === 'String' &&+ propertyValue.type === 'Link' &&'value' in propertyValue) {const linkVal = propertyValue.value;- if (linkVal && typeof linkVal === 'string') {+ // Link values are always returned as arrays from the API+ if (Array.isArray(linkVal)) {return { ...baseProperty, valueType: 'LINK', value: linkVal };}}diff --git a/js/app/packages/core/component/Properties/components/CreatePropertyModal.tsx b/js/app/packages/core/component/Properties/components/CreatePropertyModal.tsxindex 1632dab24a..58608e8a07 100644--- a/js/app/packages/core/component/Properties/components/CreatePropertyModal.tsx+++ b/js/app/packages/core/component/Properties/components/CreatePropertyModal.tsx@@ -331,7 +331,10 @@ export function CreatePropertyModal(props: CreatePropertyModalProps) {const shouldShowMultiSelect = createMemo(() => {const { type } = parseDataTypeValue(selectedDataType());return (- type === 'select_string' || type === 'select_number' || type === 'entity'+ type === 'select_string' ||+ type === 'select_number' ||+ type === 'entity' ||+ type === 'link');});diff --git a/js/app/packages/core/component/Properties/components/PropertiesList.tsx b/js/app/packages/core/component/Properties/components/PropertiesList.tsxindex 13361e17eb..1b53074d05 100644--- a/js/app/packages/core/component/Properties/components/PropertiesList.tsx+++ b/js/app/packages/core/component/Properties/components/PropertiesList.tsx@@ -30,9 +30,14 @@ export function PropertiesList(props: PropertiesListProps) {const handleValueClick = (property: Property, anchor?: HTMLElement) => {if (property.valueType === 'DATE') {openModal('date-picker', property, anchor);- } else {+ } else if (+ property.valueType === 'SELECT_STRING' ||+ property.valueType === 'SELECT_NUMBER' ||+ property.valueType === 'ENTITY'+ ) {openModal('edit-property', property, anchor);}+ // LINK, STRING, NUMBER, BOOLEAN handle their own inline editing};return (diff --git a/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx b/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsxnew file mode 100644index 0000000000..cac45406ce--- /dev/null+++ b/js/app/packages/core/component/Properties/components/property-display/LinkValue.tsx@@ -0,0 +1,348 @@+import { useBlockId } from '@core/block';+import { useUnfurl } from '@core/signal/unfurl';+import LinkIcon from '@icon/regular/link.svg';+import XIcon from '@icon/regular/x.svg';+import type { EntityType } from '@service-properties/generated/schemas/entityType';+import { proxyResource } from '@service-unfurl/client';+import type { Component } from 'solid-js';+import { createSignal, For, Show } from 'solid-js';+import { createStore } from 'solid-js/store';+import { savePropertyValue } from '../../api/propertyValues';+import type { Property } from '../../types';+import { extractDomain, isValidUrl, normalizeUrl } from '../../utils';++type LinkValueProps = {+ property: Property;+ canEdit: boolean;+ entityType: EntityType;+ onRefresh?: () => void;+};++const [badLinks, setBadLinks] = createStore<Record<string, true>>({});++export const LinkValue: Component<LinkValueProps> = (props) => {+ const blockId = useBlockId();+ const [isAdding, setIsAdding] = createSignal(false);+ const [inputValue, setInputValue] = createSignal('');+ const [error, setError] = createSignal<string | null>(null);+ const [hoveredLink, setHoveredLink] = createSignal<string | null>(null);+ const [isSaving, setIsSaving] = createSignal(false);++ const isReadOnly = () => props.property.isMetadata || !props.canEdit;+ const linkValues = (props.property.value || []) as string[];++ const startAdding = () => {+ if (isReadOnly()) return;+ setIsAdding(true);+ setInputValue('');+ setError(null);+ };++ const cancelAdding = () => {+ setIsAdding(false);+ setInputValue('');+ setError(null);+ };++ const handleAddLink = async () => {+ const value = inputValue().trim();+ if (!value) {+ cancelAdding();+ return;+ }++ const normalized = normalizeUrl(value);+ if (!isValidUrl(normalized)) {+ setError('Please enter a valid URL');+ return;+ }++ if (linkValues.includes(normalized)) {+ setError('This URL has already been added');+ return;+ }++ setIsSaving(true);+ setError(null);++ try {+ let newValues: string[];+ if (props.property.isMultiSelect) {+ newValues = [...linkValues, normalized];+ } else {+ newValues = [normalized];+ }++ const result = await savePropertyValue(+ blockId,+ props.entityType,+ props.property,+ {+ valueType: 'LINK',+ values: newValues,+ }+ );++ if (result.ok) {+ cancelAdding();+ props.onRefresh?.();+ } else {+ setError('Failed to save link');+ }+ } catch (_err) {+ setError('Failed to save link');+ } finally {+ setIsSaving(false);+ }+ };++ const handleRemoveLink = async (url: string) => {+ if (isReadOnly() || isSaving()) return;++ setIsSaving(true);++ try {+ const newValues = linkValues.filter((link) => link !== url);++ const result = await savePropertyValue(+ blockId,+ props.entityType,+ props.property,+ {+ valueType: 'LINK',+ values: newValues.length > 0 ? newValues : null,+ }+ );++ if (result.ok) {+ props.onRefresh?.();+ }+ } finally {+ setIsSaving(false);+ }+ };++ const handleKeyDown = (e: KeyboardEvent) => {+ if (e.key === 'Enter') {+ e.preventDefault();+ handleAddLink();+ } else if (e.key === 'Escape') {+ e.preventDefault();+ cancelAdding();+ } else if (error()) {+ setError(null);+ }+ };++ // Empty state - show input if adding, otherwise show — button+ if (linkValues.length === 0) {+ if (isAdding()) {+ return (+ <div>+ <input+ ref={(el) => {+ setTimeout(() => el.focus(), 0);+ }}+ type="text"+ value={inputValue()}+ onInput={(e) => setInputValue(e.currentTarget.value)}+ onKeyDown={handleKeyDown}+ onBlur={() => {+ setTimeout(() => {+ if (isAdding()) {+ handleAddLink();+ }+ }, 100);+ }}+ placeholder="Enter URL..."+ disabled={isSaving()}+ class="text-left text-xs px-2 py-1 border border-edge bg-transparent focus:outline-none focus:border-accent text-ink"+ />+ <Show when={error()}>+ <div class="text-failure-ink text-xs mt-1">{error()}</div>+ </Show>+ </div>+ );+ }++ return (+ <button+ onClick={startAdding}+ class={`text-left text-xs px-2 py-1 border border-edge ${+ isReadOnly()+ ? 'bg-transparent text-ink-muted cursor-default'+ : 'hover:bg-hover cursor-pointer bg-transparent text-ink'+ } inline-block max-w-full`}+ disabled={isReadOnly()}+ >+ —+ </button>+ );+ }++ // Single value+ if (!props.property.isMultiSelect || linkValues.length === 1) {+ return (+ <LinkDisplay+ url={linkValues[0]}+ onRemove={() => handleRemoveLink(linkValues[0])}+ canEdit={!isReadOnly()}+ isRemoving={isSaving()}+ hoveredLink={hoveredLink()}+ setHoveredLink={setHoveredLink}+ />+ );+ }++ // Multiple values+ return (+ <div class="flex flex-wrap gap-1 justify-start items-start w-full min-w-0">+ <For each={linkValues}>+ {(url) => (+ <LinkDisplay+ url={url}+ onRemove={() => handleRemoveLink(url)}+ canEdit={!isReadOnly()}+ isRemoving={isSaving()}+ hoveredLink={hoveredLink()}+ setHoveredLink={setHoveredLink}+ />+ )}+ </For>+ <Show when={!isReadOnly()}>+ <Show+ when={isAdding()}+ fallback={+ <button+ onClick={startAdding}+ class="text-ink-muted hover:text-ink text-xs hover:bg-hover px-2 py-1 cursor-pointer border border-edge bg-transparent inline-block shrink-0"+ >+ ++ </button>+ }+ >+ <div class="inline-block">+ <input+ ref={(el) => {+ setTimeout(() => el.focus(), 0);+ }}+ type="text"+ value={inputValue()}+ onInput={(e) => setInputValue(e.currentTarget.value)}+ onKeyDown={handleKeyDown}+ onBlur={() => {+ setTimeout(() => {+ if (isAdding()) {+ handleAddLink();+ }+ }, 100);+ }}+ placeholder="Enter URL..."+ disabled={isSaving()}+ class="text-left text-xs px-2 py-1 border border-edge bg-transparent focus:outline-none focus:border-accent text-ink"+ />+ <Show when={error()}>+ <div class="text-failure-ink text-xs mt-1">{error()}</div>+ </Show>+ </div>+ </Show>+ </Show>+ </div>+ );+};++type LinkDisplayProps = {+ url: string;+ onRemove: () => void;+ canEdit: boolean;+ isRemoving: boolean;+ hoveredLink: string | null;+ setHoveredLink: (url: string | null) => void;+};++const LinkDisplay: Component<LinkDisplayProps> = (props) => {+ const [imageError, setImageError] = createSignal(false);+ const [unfurlData] = useUnfurl(props.url);+ const domain = extractDomain(props.url);++ const handleLinkClick = (e: MouseEvent) => {+ if ((e.target as HTMLElement).closest('.remove-button')) {+ return;+ }+ e.preventDefault();+ window.open(props.url, '_blank');+ };++ const handleRemoveClick = (e: MouseEvent) => {+ e.preventDefault();+ e.stopPropagation();+ props.onRemove();+ };++ const faviconUrl = () => {+ const data = unfurlData();+ if (data?.type === 'success' && data.data.favicon_url) {+ return proxyResource(data.data.favicon_url);+ }+ return null;+ };++ const title = () => {+ const data = unfurlData();+ if (data?.type === 'success' && data.data.title) {+ return data.data.title;+ }+ return domain;+ };++ const isHovered = () => props.hoveredLink === props.url;++ return (+ <div+ class="relative inline-block max-w-[225px] shrink-0"+ onMouseEnter={() => props.setHoveredLink(props.url)}+ onMouseLeave={() => props.setHoveredLink(null)}+ >+ <button+ onClick={handleLinkClick}+ class={`text-left text-xs px-2 py-1 border border-edge cursor-pointer bg-transparent text-ink inline-flex items-center gap-2 w-full ${+ props.canEdit ? 'hover:bg-hover' : ''+ }`}+ title={props.url}+ disabled={props.isRemoving}+ >+ <div class="shrink-0 w-4 h-4 flex items-center justify-center">+ <Show+ when={faviconUrl() && !imageError() && !badLinks[faviconUrl()!]}+ fallback={<LinkIcon class="w-3.5 h-3.5 text-ink-muted" />}+ >+ <img+ src={faviconUrl()!}+ class="w-4 h-4 object-cover rounded-sm"+ crossorigin="anonymous"+ alt="favicon"+ onError={() => {+ setImageError(true);+ if (faviconUrl()) {+ setBadLinks(faviconUrl()!, true);+ }+ }}+ />+ </Show>+ </div>++ <span class="truncate flex-1 text-ink">{title()}</span>++ <Show when={props.canEdit && isHovered() && !props.isRemoving}>+ <button+ class="remove-button shrink-0 p-0.5 hover:bg-failure/20 rounded"+ onClick={handleRemoveClick}+ title="Remove link"+ >+ <XIcon class="w-3 h-3 text-ink-muted hover:text-failure-ink" />+ </button>+ </Show>+ </button>+ </div>+ );+};diff --git a/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx b/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsxindex 226f3fadfb..d4896d05b9 100644--- a/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx+++ b/js/app/packages/core/component/Properties/components/property-display/NumberValue.tsx@@ -4,7 +4,6 @@ import { Show } from 'solid-js';import { useInlineEditor } from '../../hooks';import type { Property } from '../../types';import { formatNumber } from '../../utils';-import { getEditMethod } from '../../utils/typeGuards';type NumberValueProps = {property: Property;@@ -27,7 +26,7 @@ export const NumberValue: Component<NumberValueProps> = (props) => {const supportsInline = () =>props.canEdit &&!props.property.isMetadata &&- getEditMethod(props.property.valueType) === 'inline';+ props.property.valueType === 'NUMBER';const handleClick = () => {if (supportsInline()) {diff --git a/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx b/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsxindex a9ce788565..e6889dc657 100644--- a/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx+++ b/js/app/packages/core/component/Properties/components/property-display/PropertyValue.tsx@@ -4,6 +4,7 @@ import type { Property } from '../../types';import { BooleanValue } from './BooleanValue';import { DateValue } from './DateValue';import { EntityValue } from './EntityValue';+import { LinkValue } from './LinkValue';import { NumberValue } from './NumberValue';import { SelectValue } from './SelectValue';import { TextValue } from './TextValue';@@ -83,7 +84,7 @@ export const PropertyValue: Component<PropertyValueProps> = (props) => {case 'LINK':return (- <TextValue+ <LinkValueproperty={props.property}canEdit={canEdit}entityType={entityType}diff --git a/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx b/js/app/packages/core/component/Properties/components/property-display/TextValue.tsxindex 33193c25e9..5627caec17 100644--- a/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx+++ b/js/app/packages/core/component/Properties/components/property-display/TextValue.tsx@@ -4,7 +4,6 @@ import { Show } from 'solid-js';import { useInlineEditor } from '../../hooks';import type { Property } from '../../types';import { formatPropertyValue } from '../../utils';-import { getEditMethod } from '../../utils/typeGuards';type TextValueProps = {property: Property;@@ -26,7 +25,7 @@ export const TextValue: Component<TextValueProps> = (props) => {const supportsInline = () =>props.canEdit &&!props.property.isMetadata &&- getEditMethod(props.property.valueType) === 'inline';+ props.property.valueType === 'STRING';const handleClick = () => {if (supportsInline()) {diff --git a/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts b/js/app/packages/core/component/Properties/hooks/useInlineEditor.tsindex 02223aa9bb..4256d88994 100644--- a/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts+++ b/js/app/packages/core/component/Properties/hooks/useInlineEditor.ts@@ -36,7 +36,7 @@ export function useInlineEditor(const val = property.value;if (val === undefined) return '';- // This hook only works with string and number properties+ // This hook works with string and number properties// For these types, val is a single value, not an arrayreturn formatPropertyValue(property, val as string | number);};diff --git a/js/app/packages/core/component/Properties/types.ts b/js/app/packages/core/component/Properties/types.tsindex c2f84ef8b0..b1ff0a9114 100644--- a/js/app/packages/core/component/Properties/types.ts+++ b/js/app/packages/core/component/Properties/types.ts@@ -67,7 +67,7 @@ export type Property = {| { valueType: 'SELECT_STRING'; value?: string[] }| { valueType: 'SELECT_NUMBER'; value?: string[] }| { valueType: 'ENTITY'; value?: EntityReference[] }- | { valueType: 'LINK'; value?: string }+ | { valueType: 'LINK'; value?: string[] });/**@@ -170,7 +170,7 @@ export type PropertyApiValues =| { valueType: 'SELECT_STRING'; values: string[] | null }| { valueType: 'SELECT_NUMBER'; values: string[] | null }| { valueType: 'ENTITY'; refs: EntityReference[] | null }- | { valueType: 'LINK'; value: string | null };+ | { valueType: 'LINK'; values: string[] | null };// Result type for API responsesexport type ApiError = {@@ -181,6 +181,3 @@ export type ApiError = {export type Result<T, E = ApiError> =| { ok: true; value: T }| { ok: false; error: E };--// Edit method types-export type EditMethod = 'inline' | 'multi' | 'modal' | 'no_edit';diff --git a/js/app/packages/core/component/Properties/utils.ts b/js/app/packages/core/component/Properties/utils.tsindex 9962feca24..1c8f37908f 100644--- a/js/app/packages/core/component/Properties/utils.ts+++ b/js/app/packages/core/component/Properties/utils.ts@@ -43,6 +43,64 @@ export function formatBoolean(value: boolean): string {return value ? 'True' : 'False';}+/**+ * Extract domain from a URL for display+ */+export function extractDomain(url: string): string {+ try {+ const urlObj = new URL(url);+ return urlObj.hostname;+ } catch {+ return url;+ }+}++/**+ * Normalize a URL by adding https:// if no protocol is present+ */+export function normalizeUrl(url: string): string {+ const trimmed = url.trim();+ if (!trimmed) return '';++ // Check if URL has a protocol+ if (!/^https?:\/\//i.test(trimmed)) {+ return `https://${trimmed}`;+ }++ return trimmed;+}++/**+ * Validate if a string is a valid URL+ * Requires a proper domain with TLD (e.g., example.com)+ */+export function isValidUrl(url: string): boolean {+ try {+ const urlObj = new URL(url);++ // Check if hostname has at least one dot (for TLD) or is localhost+ const hostname = urlObj.hostname;+ if (hostname === 'localhost' || hostname === '127.0.0.1') {+ return true;+ }++ // Must have at least one dot for TLD+ if (!hostname.includes('.')) {+ return false;+ }++ // Must have something before and after the dot+ const parts = hostname.split('.');+ if (parts.some((part) => part.length === 0)) {+ return false;+ }++ return true;+ } catch {+ return false;+ }+}+/*** Format a property value for display* Handles all value types including looking up select options by ID@@ -155,10 +213,10 @@ export const getPropertyDataTypeDropdownOptions = () => [{ value: 'number' as const, label: 'Input (Number)' },{ value: 'boolean' as const, label: 'Checkbox' },{ value: 'date' as const, label: 'Date' },- // { value: 'link' as const, label: 'Link' }, // Not yet supported- { value: 'select_string' as const, label: 'Select' },- { value: 'select_number' as const, label: 'Select (Number)' },- { value: 'entity:USER' as const, label: 'People' },+ { value: 'link' as const, label: 'Link' },+ { value: 'select_string' as const, label: 'Option' },+ { value: 'select_number' as const, label: 'Option (Number)' },+ { value: 'entity:USER' as const, label: 'User' },{ value: 'entity:DOCUMENT' as const, label: 'Document' },{ value: 'entity:CHANNEL' as const, label: 'Channel' },{ value: 'entity:PROJECT' as const, label: 'Project' },@@ -190,24 +248,17 @@ export const getPropertyDefinitionTypeDisplay = (property: {// Normalize to lowercase for comparison with dropdown optionsconst dataTypeLower = data_type.toLowerCase();- const specificEntityTypeLower = specific_entity_type?.toLowerCase();// Get the base label from dropdown optionsconst dropdownOptions = getPropertyDataTypeDropdownOptions();let display: string;- if (dataTypeLower === 'entity' && specificEntityTypeLower) {+ if (dataTypeLower === 'entity') {// For specific entity types, find the matching dropdown option- // Try both uppercase and lowercase for backwards compatibility- const option = dropdownOptions.find(- (opt) =>- opt.value === `entity:${specificEntityTypeLower.toUpperCase()}` ||- opt.value === `entity:${specificEntityTypeLower}`- );- display = option?.label || `Entity (${specificEntityTypeLower})`;- } else if (dataTypeLower === 'link') {- // Handle the new LINK type- display = 'Link';+ display =+ dropdownOptions.find(+ (opt) => opt.value === `entity:${specific_entity_type}`+ )?.label || `${dataTypeLower[0].toUpperCase() + dataTypeLower.slice(1)}`;} else {// For other types, find the matching dropdown optionconst option = dropdownOptions.find((opt) => opt.value === dataTypeLower);@@ -219,10 +270,10 @@ export const getPropertyDefinitionTypeDisplay = (property: {}// Add multi indicator- if (dataTypeLower === 'select_string' || dataTypeLower === 'select_number') {- display = `${is_multi_select === true ? 'Multi' : 'Single'} ${display}`;+ if (['select_string', 'select_number', 'link'].includes(dataTypeLower)) {+ display = `${is_multi_select === true ? 'Multi' : 'Single'} ${display}`;} else if (dataTypeLower === 'entity') {- display = `${is_multi_select === true ? 'Multi' : 'Single'} Select ${display}`;+ display = `${is_multi_select === true ? 'Multi' : 'Single'}-Select ${display}`;}return display;diff --git a/js/app/packages/core/component/Properties/utils/index.ts b/js/app/packages/core/component/Properties/utils/index.tsindex 7999775bbe..4d896893eb 100644--- a/js/app/packages/core/component/Properties/utils/index.ts+++ b/js/app/packages/core/component/Properties/utils/index.ts@@ -18,4 +18,3 @@ export {} from '../utils';export * from './entityConversion';export * from './errorHandling';-export * from './typeGuards';diff --git a/js/app/packages/core/component/Properties/utils/typeGuards.ts b/js/app/packages/core/component/Properties/utils/typeGuards.tsdeleted file mode 100644index f82f652b34..0000000000--- a/js/app/packages/core/component/Properties/utils/typeGuards.ts+++ /dev/null@@ -1,29 +0,0 @@-import type { EditMethod, ValueType } from '../types';--/**- * Get the edit method for a property value type- */-export function getEditMethod(valueType: ValueType): EditMethod {- switch (valueType) {- case 'STRING':- case 'NUMBER':- return 'inline';-- case 'BOOLEAN':- return 'inline'; // Toggle is a form of inline editing-- case 'SELECT_STRING':- case 'SELECT_NUMBER':- case 'ENTITY':- return 'multi';-- case 'DATE':- return 'modal';-- case 'LINK':- return 'inline';-- default:- return 'no_edit';- }-}