Skip to main content

SiteDetails Components

Components for managing site records in the Data viewer. Includes site creation dialogs, detail editing forms, field renderers, and associated buildings tables.

Components

ComponentFileDescription
AddSiteAddSite.tsxDialog for creating a new site with name input
AssociatedBuildingsTableAssociatedBuildings.tsxTable displaying buildings linked to a site with attach/create functionality
FieldRendererFieldRenderer.tsxRenders appropriate input controls based on field type
SiteDetailsSiteDetails.tsxMain detail view with tabbed sections for site properties

AddSite

Dialog component that initiates site creation by capturing the site name.

Props

PropTypeRequiredDescription
newItemNamestringYesCurrent value of the site name input
setNewItemNameReact.Dispatch<React.SetStateAction<string>>YesSetter for updating the site name

Permissions

Requires permission: { action: "create", subject: "Site" }

The trigger button is disabled when the user lacks create permission.

Usage

import AddSite from '@collabdt/core/components/viewers/Data/siteDetails/AddSite'

const [siteName, setSiteName] = useState('')

<AddSite newItemName={siteName} setNewItemName={setSiteName} />

Behavior

  • Opens a dialog with a text input for site name
  • On submit, creates a temporary site object with id: -1
  • Sets the temporary site as selected and switches view to detail mode
  • Shows error toast if name is empty

AssociatedBuildingsTable

Displays buildings associated with a site. Supports searching, filtering, attaching existing buildings, and creating new buildings from geocoded addresses.

Props

PropTypeRequiredDescription
buildingsBuilding[]YesArray of buildings currently associated with the site
onRowClick(building: Building) => voidNoCallback when a building row is clicked
siteIdnumberNoID of the parent site
onAttachBuilding(building: Building) => voidNoCallback when a building is attached
editingbooleanNoWhether the parent form is in edit mode
setEditing(editing: boolean) => voidNoSetter to enable edit mode

Features

  • Search: Filter displayed buildings by name, address, municipality, subdivision, or project type
  • Advanced Filters: Apply complex filter conditions via FiltersDialog
  • Attach Existing: Search and attach buildings already in the organization
  • Create & Attach: Geocode an address and create a new building record, then attach it
  • Preview State: Newly attached buildings show immediately before save

Dependencies

  • useBuildings — fetches all available buildings
  • useCreateBuilding — creates new building records
  • useUser — retrieves current user's organization
  • fetchSuggestions / parseLocation — geocoding utilities

Usage

import AssociatedBuildingsTable from '@collabdt/core/components/viewers/Data/siteDetails/AssociatedBuildings'

<AssociatedBuildingsTable
buildings={site.siteBuildings}
siteId={site.id}
onAttachBuilding={handleAttach}
editing={isEditing}
setEditing={setIsEditing}
/>

FieldRenderer

Renders the appropriate input control for a site property based on its type (text, number, date, enum, file, checkbox, array).

Props

PropTypeRequiredDescription
propertystringYesProperty key being rendered
valueanyYesCurrent value of the property
handleInputChange(property: string, value: any) => voidYesCallback when value changes
isTextAreaField(property: string) => booleanYesPredicate for textarea fields
isFileField(property: string) => booleanYesPredicate for file upload fields
isDateField(property: string) => booleanNoPredicate for date fields
isEnumField(property: string) => booleanNoPredicate for enum fields
getEnumType(property: string) => string | nullNoReturns enum type name for a property
isNumberField(property: string) => booleanNoPredicate for numeric fields
isFullWidthField(property: string) => booleanNoPredicate for full-width layout

Supported Enum Types

  • SiteEnergySource
  • SiteAssessmentConditions
  • SiteProjectPhase
  • SiteProjectType
  • SiteLandUse
  • CountrySubdivisionData — populated from map context

Permissions

Input controls are disabled when user lacks { action: "update", subject: "Site" }.

Usage

<FieldRenderer
property="siteProjectPhase"
value={site.siteProjectPhase}
handleInputChange={handleChange}
isTextAreaField={isTextAreaField}
isFileField={isFileField}
isEnumField={isEnumField}
getEnumType={getEnumType}
/>

SiteDetails

Main detail panel for viewing and editing a site. Organized into tabbed sections defined by useSiteHeaders.

Props

PropTypeRequiredDescription
selectedSiteSite & { siteBuildings?: Building[] }NoThe site being viewed/edited
setSelectedSite(site: Site) => voidNoSetter for updating selected site
editingbooleanNoWhether the form is in edit mode
setEditing(editing: boolean) => voidNoSetter for edit mode
setActiveChanges(hasChanges: boolean) => voidNoSetter indicating unsaved changes
sitesSite[]NoList of all sites (unused in current implementation)
activeTabstringNoCurrently active tab key
setActiveTab(tab: string) => voidNoSetter for active tab

Ref Methods

The component exposes a ref with the following method:

MethodDescription
saveChanges()Persists pending edits via updateSite or createSite

Behavior

  • New Site: When selectedSite.id < 0, automatically enters edit mode and calls createSite on save
  • Existing Site: Calls updateSite with changed fields on save
  • Associated Buildings Tab: Renders AssociatedBuildingsTable with connect/disconnect tracking

Usage

import SiteDetails, { SiteDetailsRef } from '@collabdt/core/components/viewers/Data/siteDetails/SiteDetails'

const detailsRef = useRef<SiteDetailsRef>(null)

<SiteDetails
ref={detailsRef}
selectedSite={selectedSite}
setSelectedSite={setSelectedSite}
editing={editing}
setEditing={setEditing}
activeTab={activeTab}
setActiveTab={setActiveTab}
/>

// Save from parent
await detailsRef.current?.saveChanges()