IdProps.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil';
  2. import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';
  3. import { useService } from 'bpmn-js-properties-panel';
  4. import { isIdValid } from '../utils/ValidationUtil';
  5. /**
  6. * @typedef { import('@bpmn-io/properties-panel').EntryDefinition } Entry
  7. */
  8. /**
  9. * @returns {Array<Entry>} entries
  10. */
  11. export function IdProps() {
  12. return [
  13. {
  14. id: 'id',
  15. component: Id,
  16. isEdited: isTextFieldEntryEdited,
  17. },
  18. ];
  19. }
  20. function Id(props) {
  21. const { element } = props;
  22. const modeling = useService('modeling');
  23. const debounce = useService('debounceInput');
  24. const translate = useService('translate');
  25. const setValue = (value) => {
  26. modeling.updateProperties(element, {
  27. id: value,
  28. });
  29. };
  30. const getValue = (element) => {
  31. return element.businessObject.id;
  32. };
  33. const validate = (value) => {
  34. const businessObject = getBusinessObject(element);
  35. return isIdValid(businessObject, value, translate);
  36. };
  37. return TextFieldEntry({
  38. element,
  39. id: 'id',
  40. label: translate(is(element, 'bpmn:Participant') ? 'Participant ID' : 'ID'),
  41. getValue,
  42. setValue,
  43. debounce,
  44. validate,
  45. });
  46. }