Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim and remove spaces from ID with user alert #94

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
idToHumanReadableName,
findDataObject,
} from '../DataObjectHelpers';
import { processId } from '../../helpers';

/**
* Provides a list of data objects, and allows you to add / remove data objects, and change their ids.
Expand Down Expand Up @@ -146,7 +147,7 @@ function DataObjectTextField(props) {
element,
moddleElement: dataObject,
properties: {
id: value,
id: processId(value),
// name: doName
},
});
Expand Down
4 changes: 2 additions & 2 deletions app/spiffworkflow/eventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TextFieldEntry,
isTextFieldEntryEdited
} from '@bpmn-io/properties-panel';
import { getRoot } from './helpers';
import { getRoot, processId } from './helpers';

/* This function creates a list of a particular event type at the process level using the item list
* and add function provided by `getArray`.
Expand Down Expand Up @@ -142,7 +142,7 @@ function ItemTextField(props) {
element,
moddleElement: item,
properties: {
id: value,
id: processId(value),
name: value,
},
});
Expand Down
10 changes: 10 additions & 0 deletions app/spiffworkflow/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ export function getRoot(businessObject, moddle) {
}
return businessObject;
}


export function processId(id) {
let trimmedId = id.trim();
let processedId = trimmedId.replace(/\s+/g, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should remove any non-alphanumeric/hyphen/underscore characters?

if (id !== processedId) {
alert('ID should not contain spaces. It has been adjusted.');
}
return processedId;
}
Comment on lines +41 to +48
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing alert with a more flexible notification mechanism.

Using alert directly in a utility function can be intrusive and limits the flexibility of the application. It might be better to return a status or use a callback/event to notify the application, which can then decide how to alert the user.

Loading