Skip to content

Commit

Permalink
support formatting data client side in markdown and support greater t…
Browse files Browse the repository at this point in the history
…han and less than for metadata column filters w/ burnettk
  • Loading branch information
jasquat committed Oct 20, 2023
1 parent 53e41f0 commit ee8af5d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ def _run_extension(
script_engine=CustomBpmnScriptEngine(use_restricted_script_engine=False),
process_id_to_run=process_id_to_run,
)
save_to_db = process_instance.persistence_level != "none"
if body and "extension_input" in body:
processor.do_engine_steps(save=False, execution_strategy_name="run_current_ready_tasks")
processor.do_engine_steps(save=save_to_db, execution_strategy_name="run_current_ready_tasks")
next_task = processor.next_task()
next_task.update_data(body["extension_input"])
processor.do_engine_steps(save=False, execution_strategy_name="greedy")
processor.do_engine_steps(save=save_to_db, execution_strategy_name="greedy")
except (
ApiError,
ProcessInstanceIsNotEnqueuedError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ def run_process_instance_report(
join_conditions.append(instance_metadata_alias.value == filter_for_column["field_value"])
elif filter_for_column["operator"] == "not_equals":
join_conditions.append(instance_metadata_alias.value != filter_for_column["field_value"])
elif filter_for_column["operator"] == "greater_than_or_equal_to":
join_conditions.append(instance_metadata_alias.value >= filter_for_column["field_value"])
elif filter_for_column["operator"] == "less_than":
join_conditions.append(instance_metadata_alias.value < filter_for_column["field_value"])
elif filter_for_column["operator"] == "contains":
join_conditions.append(instance_metadata_alias.value.like(f"%{filter_for_column['field_value']}%"))
elif filter_for_column["operator"] == "is_empty":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import {
REFRESH_TIMEOUT_SECONDS,
titleizeString,
truncateString,
isANumber,
formatDurationForDisplay,
formatDateTime,
} from '../helpers';
import { useUriListForPermissions } from '../hooks/UriListForPermissions';

Expand Down Expand Up @@ -1697,24 +1697,6 @@ export default function ProcessInstanceListTable({
return value;
};

const formatDateTime = (_row: ProcessInstance, value: any) => {
if (value === undefined || value === null) {
return value;
}
let dateInSeconds = value;
if (!isANumber(value)) {
const timeArgs = value.split('T');
dateInSeconds = convertDateAndTimeStringsToSeconds(
timeArgs[0],
timeArgs[1]
);
}
if (dateInSeconds) {
return convertSecondsToFormattedDateTime(dateInSeconds);
}
return null;
};

const formattedColumn = (row: ProcessInstance, column: ReportColumn) => {
const reportColumnFormatters: Record<string, any> = {
id: formatProcessInstanceId,
Expand Down
18 changes: 18 additions & 0 deletions spiffworkflow-frontend/src/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,21 @@ export const formatDurationForDisplay = (_row: any, value: any) => {
}
return durationTimes.join(' ');
};

export const formatDateTime = (_row: any, value: any) => {
if (value === undefined || value === null) {
return value;
}
let dateInSeconds = value;
if (!isANumber(value)) {
const timeArgs = value.split('T');
dateInSeconds = convertDateAndTimeStringsToSeconds(
timeArgs[0],
timeArgs[1]
);
}
if (dateInSeconds) {
return convertSecondsToFormattedDateTime(dateInSeconds);
}
return null;
};
77 changes: 73 additions & 4 deletions spiffworkflow-frontend/src/routes/Extension.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { Button } from '@carbon/react';
import MDEditor from '@uiw/react-md-editor';
import { useParams, useSearchParams } from 'react-router-dom';
Expand All @@ -7,7 +7,11 @@ import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import { ProcessFile, ProcessModel } from '../interfaces';
import HttpService from '../services/HttpService';
import useAPIError from '../hooks/UseApiError';
import { recursivelyChangeNullAndUndefined } from '../helpers';
import {
formatDateTime,
formatDurationForDisplay,
recursivelyChangeNullAndUndefined,
} from '../helpers';
import CustomForm from '../components/CustomForm';
import { BACKEND_BASE_URL } from '../config';
import {
Expand Down Expand Up @@ -41,13 +45,50 @@ export default function Extension() {

const { addError, removeError } = useAPIError();

const spiffConversionFunctions: { [key: string]: Function } = useMemo(() => {
return {
convert_seconds_to_date_time_for_display: formatDateTime,
convert_seconds_to_duration_for_display: formatDurationForDisplay,
};
}, []);

const checkForSpiffConversions = useCallback(
(markdown: string) => {
const replacer = (
match: string,
spiffConversion: string,
originalValue: string
) => {
if (spiffConversion in spiffConversionFunctions) {
return spiffConversionFunctions[spiffConversion](
undefined,
originalValue
);
}
console.warn(
`attempted: ${match}, but ${spiffConversion} is not a valid conversion function`
);

return match;
};
return markdown.replaceAll(
/SPIFF_CONVERSION:::(\w+)\(([^)]+)\)/g,
replacer
);
},
[spiffConversionFunctions]
);

const setConfigsIfDesiredSchemaFile = useCallback(
// eslint-disable-next-line sonarjs/cognitive-complexity
(extensionUiSchemaFile: ProcessFile | null, pm: ProcessModel) => {
const processLoadResult = (result: any) => {
setFormData(result.task_data);
if (result.rendered_results_markdown) {
setMarkdownToRenderOnLoad(result.rendered_results_markdown);
const newMarkdown = checkForSpiffConversions(
result.rendered_results_markdown
);
setMarkdownToRenderOnLoad(newMarkdown);
}
};

Expand Down Expand Up @@ -99,6 +140,7 @@ export default function Extension() {
params.page_identifier,
searchParams,
filesByName,
checkForSpiffConversions,
]
);

Expand All @@ -125,6 +167,30 @@ export default function Extension() {
targetUris.extensionPath,
]);

// this relies on the MDEditor rendering the markdown before
// this useEffect triggers which may or may not alwasy be the case
// so we may need to change implementation to a search/replace
// before renddering any markdown.
useEffect(() => {
const convertField = (className: string, conversionFunction: any) => {
const elements = document.getElementsByClassName(className);
if (elements.length > 0) {
for (let i = 0; i < elements.length; i += 1) {
const element = elements[i];
if (element) {
const originalValue = element.innerHTML;
element.innerHTML = conversionFunction(undefined, originalValue);
}
}
}
};
convertField('convert_seconds_to_date_time_for_display', formatDateTime);
convertField(
'convert_seconds_to_duration_for_display',
formatDurationForDisplay
);
}, [markdownToRenderOnLoad, markdownToRenderOnSubmit]);

const interpolateNavigationString = (
navigationString: string,
baseData: any
Expand Down Expand Up @@ -162,7 +228,10 @@ export default function Extension() {
} else {
setProcessedTaskData(result.task_data);
if (result.rendered_results_markdown) {
setMarkdownToRenderOnSubmit(result.rendered_results_markdown);
const newMarkdown = checkForSpiffConversions(
result.rendered_results_markdown
);
setMarkdownToRenderOnSubmit(newMarkdown);
}
setFormButtonsDisabled(false);
}
Expand Down
2 changes: 1 addition & 1 deletion spiffworkflow-frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "commonjs",
"skipLibCheck": true,
"strict": true,
"target": "es2016",
"target": "es2021",
},
"include": ["src/**/*"]
}

0 comments on commit ee8af5d

Please sign in to comment.