@procore/labs-custom-workflows v3.17.0
Custom Workflows
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
.
Prop | Type | Description |
---|---|---|
isLoading | boolean | Loading state for fetching workflows API |
error | any | Thrown error from workflows API |
transitionStatus | TransitionStatus | Workflow'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
.
Prop | Type | Description |
---|---|---|
isLoading | boolean | Loading state for fetching workflows API |
error | any | Thrown error from workflows API |
enabledWorkflowableTypes | string[] | 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.
Prop | Type | Description |
---|---|---|
companyId | number | Company ID |
projectId? | number | Project ID |
workflowableType | string | Workflowable 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).
Prop | Type | Description |
---|---|---|
currentStepOccurrence | CurrentStepOccurrence / undefined | The workflow's current step occurrence ('name', 'due_at') |
item | Item | The item's name and URL path ('name', 'url') |
timeZone | string | The user's time zone |
urgency | Urgency / undefined | Indication of the state of the instance (overdue, blocked, in progress, complete, warning) |
urgencyMessage | string / undefined | User friendly message of urgency |
workflowManager | WorkflowManager / undefined | Assigned workflow manager ('name', 'login', 'job_title') |
placement? | Placement | CORE popover placement |
size? | ButtonSizes | CORE button size |
zIndex? | string / number | CORE 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).
Prop | Type | Description |
---|---|---|
title | string | Workflow Panel title |
Workflow Panel Provider
Prop | Type | Description |
---|---|---|
metadata | Metadata | Workflow panel metadata |
config? | Configuration | Optional panel configuration |
Types
Metadata
Prop | Description |
---|---|
company | Company id and name |
project? | Project id and name |
workflowableObject | Workflowable Object id and type |
userId | User id |
timeZone | User time zone |
pusherApiKey | Pusher API key |
Configuration
Prop | Description |
---|---|
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
Prop | Type | Description |
---|---|---|
workflowPanelStatuses | WorkflowPanelStatuses | Workflow instance API statuses as booleans: ready , success , loading , error . ready indicates the workflow panel has mounted and ready to be used. |
workflowInstance | Instance | Workflow instance object |
showWorkflowPanel | boolean | Panel open state |
toggleWorkflowPanel | void | Show/hide the panel |
reloadInstance | Promise<void> | Rehydrates the workflow instance / panel |
isWorkflowV1InstancePresent | boolean | Legacy Workflow instance exists |
v1WorkflowHistory | WorkflowV1InstanceHistory[] | Legacy workflow instance history |
v1WorkflowPanelStatuses | V1WorkflowPanelStatuses | Legacy workflow instance API statuses as booleans: success , loading , error . |
hasAssignees | boolean | Check if current step has assignees |
hasFailedActionOccurrences | boolean | Check if current step has failed action occurrences |
instancePermissions | InstancePermissions | (Internal use) determines permissions of user interaction in Panel |
toolConfigurations | ToolConfiguration[] | (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>
);
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago