3.17.0 • Published 1 year ago

@procore/labs-custom-workflows v3.17.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

Custom Workflows status

Provides custom workflows capabilities to procore tools

Background

Creating an interactive UI to connect all stakeholders in construction to review/approve work items with automated tasks to reduce manual work and increase overall efficiency.

Start here to learn more about workflows.

Installation

yarn add @procore/labs-custom-workflows

This package requires Node 12+.

Dependencies

The following packages are listed as external peer dependencies:

  • @procore/core-react
  • @procore/core-icons
  • @procore/labs-toast-alert
  • react
  • react-dom
  • styled-components

The package will not bundle the code, and requires the app client to provide it as a dependency. The external peer dep is to assure React Context is consistent in a client's React tree, the child consumers can reference the correct parent provider. If the package uses latest features or bug fixes and a new minimum version of core-react is required, it should be considered a breaking change as the peer dependency version must be met.

Usage

useFetchWorkflowTransitionStatus

A custom hook to fetch the current workflow version/transition status of the specified tool type. This hook consumes the workflow's transition status API.

Provide companyId and workflowableType.

PropTypeDescription
isLoadingbooleanLoading state for fetching workflows API
erroranyThrown error from workflows API
transitionStatusTransitionStatusWorkflow's transition status object

useFetchEnabledWorkflowableTypes

A custom hook to fetch workflowable object types enabled for workflows v2. It is recommended to use this hook with WorkflowToolSettings component. See code snippet exmaple below.

Provide companyId and workflowableTypes.

PropTypeDescription
isLoadingbooleanLoading state for fetching workflows API
erroranyThrown error from workflows API
enabledWorkflowableTypesstring[]Enabled workflowable object types

Workflow Tool Settings

A preset configuration table that returns available presets associated with the provided project id and workflowable object type to handle configuring workflow instances (Storybook).

Prerequisite

You will need to create a PR to add and configure your tool's workflowable object type here for the backend.

PropTypeDescription
companyIdnumberCompany ID
projectId?numberProject ID
workflowableTypestringWorkflowable object type
filters?Record<string, string>Optional filters for the Workflows Presets#index API

Example

import { I18nProvider, Spinner } from '@procore/core-react';
import { ToastAlertProvider } from '@procore/labs-toast-alert';
import {
  WorkflowToolSettings,
  useFetchEnabledWorkflowableTypes,
} from '@procore/labs-custom-workflows';

const workflowableObjectType = 'Billings::Requisition';

const {
  isLoading,
  enabledWorkflowableTypes,
} = useFetchEnabledWorkflowableTypes({
  companyId,
  workflowableTypes: [workflowableObjectType],
});

const showWorkflowSettings = enabledWorkflowableTypes.includes(
  workflowableObjectType
);

if (isLoading) {
  return <Spinner />;
}

if (!showWorkflowSettings) {
  return null;
}

return (
  <I18nProvider>
    <ToastAlertProvider>
      <WorkflowToolSettings
        companyId={1}
        projectId={2}
        workflowableType={workflowableObjectType}
        filters={{ classification: '-1' }}
      />
    </ToastAlertProvider>
  </I18nProvider>
);

Workflow Popover

A popover to get contextual details about an item’s workflow status. The data to hydrate this component is provided (here).

PropTypeDescription
currentStepOccurrenceCurrentStepOccurrence / undefinedThe workflow's current step occurrence ('name', 'due_at')
itemItemThe item's name and URL path ('name', 'url')
timeZonestringThe user's time zone
urgencyUrgency / undefinedIndication of the state of the instance (overdue, blocked, in progress, complete, warning)
urgencyMessagestring / undefinedUser friendly message of urgency
workflowManagerWorkflowManager / undefinedAssigned workflow manager ('name', 'login', 'job_title')
placement?PlacementCORE popover placement
size?ButtonSizesCORE button size
zIndex?string / numberCORE popover z-index

Example

import { WorkflowPopover } from '@procore/labs-custom-workflows';

<I18nProvider>
  <ZIndex>
    <WorkflowPopover
      currentStepOccurrence={{
        name: 'Financial Review',
        due_at: '2022-06-01T18:02:00.550Z',
      }}
      item={{
        name: 'Invoice #123',
        url:
          'https:/app.procore.com/1/project/commitments/work_order_contracts/1/requisitions/1',
      }}
      timeZone={'America/Los_Angeles'}
      urgency={2} // 0 - Blocked, 1 - Overdue, 2 - Warning, 3 - InProgress, 4 - Complete
      urgencyMessage={'Due today'}
      workflowManager={{
        name: 'Marcia Example',
        login: 'marcia@example.com',
        job_title: 'Project Manager',
      }}
    />
  </ZIndex>
</I18nProvider>;

Workflow Panel

A panel for workflow participation (Storybook).

PropTypeDescription
titlestringWorkflow Panel title

Workflow Panel Provider

PropTypeDescription
metadataMetadataWorkflow panel metadata
config?ConfigurationOptional panel configuration

Types

Metadata

PropDescription
companyCompany id and name
project?Project id and name
workflowableObjectWorkflowable Object id and type
userIdUser id
timeZoneUser time zone
pusherApiKeyPusher API key

Configuration

PropDescription
initialIsHidden?The initial visibility of workflow panel, by default is false

Workflow Button

A Button component to show/hide the workflow panel. If a workflow instance doesn't exist, the button will return null.

Example

import {
  WorkflowPanelProvider,
  WorkflowPanel,
  WorkflowButton,
} from '@procore/labs-custom-workflows';

<I18nProvider>
  <ToastAlertProvider>
    <WorkflowPanelProvider
      metadata={{
        company: { id: 1, name: 'Test Company' },
        project: { id: 2, name: 'Test Project' },
        workflowableObject: { id: 3, type: 'Billings::Requisition' },
        userId: 7,
        timeZone: 'UTC',
        pusherApiKey: 'PUSHER_KEY',
      }}
    >
      <WorkflowButton />
      <WorkflowPanel title="Workflow Panel Title" />
    </WorkflowPanelProvider>
  </ToastAlertProvider>
</I18nProvider>;

useWorkflowPanelContext

PropTypeDescription
workflowPanelStatusesWorkflowPanelStatusesWorkflow instance API statuses as booleans: ready, success, loading, error. ready indicates the workflow panel has mounted and ready to be used.
workflowInstanceInstanceWorkflow instance object
showWorkflowPanelbooleanPanel open state
toggleWorkflowPanelvoidShow/hide the panel
reloadInstancePromise<void>Rehydrates the workflow instance / panel
isWorkflowV1InstancePresentbooleanLegacy Workflow instance exists
v1WorkflowHistoryWorkflowV1InstanceHistory[]Legacy workflow instance history
v1WorkflowPanelStatusesV1WorkflowPanelStatusesLegacy workflow instance API statuses as booleans: success, loading, error.
hasAssigneesbooleanCheck if current step has assignees
hasFailedActionOccurrencesbooleanCheck if current step has failed action occurrences
instancePermissionsInstancePermissions(Internal use) determines permissions of user interaction in Panel
toolConfigurationsToolConfiguration[](Internal use) list of tool configurations from the workflow configuration yaml
toolConfigurationStatuses{isError: boolean; isFetching: boolean; isLoading: boolean;}(Internal use) API statuses for toolConfigurations

Example

import { useWorkflowPanelContext } from '@procore/labs-custom-workflows';
import { DetailPage } from '@procore/core-react';

const { workflowPanelStatuses, showWorkflowPanel } = useWorkflowPanelContext();

if (!workflowPanelStatuses.ready) {
  return <Loading />;
}

return (
  <DetailPage width="md">
    <DetailPage.Main>
      <DetailPage.Header>{'Header subcomponents'}</DetailPage.Header>
      <DetailPage.Body>{'Body subcomponents'}</DetailPage.Body>
    </DetailPage.Main>
    <DetailPage.Aside open={showWorkflowPanel}>
      <WorkflowPanel title="Workflow Panel Title" />;
    </DetailPage.Aside>
  </DetailPage>
);
3.17.0

1 year ago

3.6.1

2 years ago

3.6.0

2 years ago

3.12.0

2 years ago

3.14.1

2 years ago

3.14.0

2 years ago

3.5.2

2 years ago

3.13.0

2 years ago

3.5.1

2 years ago

3.15.0

1 year ago

3.9.0

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.11.0

2 years ago

3.7.0

2 years ago

3.5.0

2 years ago

3.4.1

2 years ago

3.4.0

2 years ago

3.3.0

2 years ago

2.2.0

2 years ago

2.4.0

2 years ago

3.2.0

2 years ago

3.0.0

2 years ago

2.3.0

2 years ago

2.3.1

2 years ago

3.1.0

2 years ago

2.1.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

2.0.0

2 years ago

1.2.0

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

0.3.2

3 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.3.1

3 years ago

0.0.1

3 years ago