Skip to content

Commit

Permalink
feat: make FEEL popup links configurable
Browse files Browse the repository at this point in the history
* removes existing links
* links to be added through configuration instead
  • Loading branch information
philippfromme committed Oct 18, 2024
1 parent cfab33a commit 52b372a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 70 deletions.
5 changes: 4 additions & 1 deletion src/PropertiesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const DEFAULT_TOOLTIP = {};
* @param {TooltipConfig} [props.tooltipConfig]
* @param {Function} [props.tooltipLoaded]
* @param {HTMLElement} [props.feelPopupContainer]
* @param {Function} [props.getFeelPopupLinks]
* @param {Object} [props.eventBus]
*/
export default function PropertiesPanel(props) {
Expand All @@ -132,6 +133,7 @@ export default function PropertiesPanel(props) {
tooltipConfig,
tooltipLoaded,
feelPopupContainer,
getFeelPopupLinks,
eventBus
} = props;

Expand Down Expand Up @@ -243,7 +245,8 @@ export default function PropertiesPanel(props) {
<FeelPopupRoot
element={ element }
eventBus={ eventBus }
popupContainer={ feelPopupContainer }>
popupContainer={ feelPopupContainer }
getPopupLinks={ getFeelPopupLinks }>
<div class="bio-properties-panel">
<Header
element={ element }
Expand Down
6 changes: 5 additions & 1 deletion src/assets/properties-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,14 @@ textarea.bio-properties-panel-input {
}

.bio-properties-panel-feel-popup__title-link {
margin-left: auto;
margin-left: 8px;
display: flex;
}

.bio-properties-panel-feel-popup__title-link:first-of-type {
margin-left: auto;
}

.bio-properties-panel-feel-popup__title-link svg {
width: var(--popup-header-line-height);
height: var(--popup-header-line-height);
Expand Down
39 changes: 15 additions & 24 deletions src/components/entries/FEEL/FeelPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Popup } from '../../Popup';
import CodeEditor from './FeelEditor';

import TemplatingEditor from '../templating/TemplatingEditor';
import { HelpIcon } from '../../icons';
import { LaunchIcon } from '../../icons';

export const FEEL_POPUP_WIDTH = 700;
export const FEEL_POPUP_HEIGHT = 250;
Expand All @@ -31,7 +31,8 @@ export default function FEELPopupRoot(props) {
const {
element,
eventBus = { fire() {}, on() {}, off() {} },
popupContainer
popupContainer,
getPopupLinks = () => []
} = props;

const prevElement = usePrevious(element);
Expand Down Expand Up @@ -121,6 +122,7 @@ export default function FEELPopupRoot(props) {
<FeelPopupComponent
onClose={ handleClose }
container={ popupContainer }
getLinks={ getPopupLinks }
sourceElement={ sourceElement }
emit={ emit }
{ ...popupConfig } />
Expand All @@ -133,6 +135,7 @@ export default function FEELPopupRoot(props) {
function FeelPopupComponent(props) {
const {
container,
getLinks,
id,
hostLanguage,
onInput,
Expand Down Expand Up @@ -218,28 +221,16 @@ function FeelPopupComponent(props) {
closeButtonTooltip="Save and close"
onClose={ onClose }
draggable>
{type === 'feel' && (
<a
rel="noreferrer"
href="https://docs.camunda.io/docs/components/modeler/feel/what-is-feel/"
target="_blank"
class="bio-properties-panel-feel-popup__title-link">
Learn FEEL expressions
<HelpIcon />
</a>
)
}
{type === 'feelers' && (
<a
rel="noreferrer"
href="https://docs.camunda.io/docs/components/modeler/forms/configuration/forms-config-templating-syntax/"
target="_blank"
class="bio-properties-panel-feel-popup__title-link">
Learn templating
<HelpIcon />
</a>
)
}
<>
{
getLinks(type).map((link, index) => {
return <a key={ index } rel="noreferrer" href={ link.href } target="_blank" class="bio-properties-panel-feel-popup__title-link">
{ link.title}
<LaunchIcon />
</a>;
})
}
</>
</Popup.Title>
<Popup.Body>
<div
Expand Down
5 changes: 5 additions & 0 deletions src/components/icons/Launch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/components/icons/help.svg

This file was deleted.

6 changes: 3 additions & 3 deletions src/components/icons/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { default as ArrowIcon } from './Arrow.svg';
export { default as CloseIcon } from './Close.svg';
export { default as CreateIcon } from './Create.svg';
export { default as DeleteIcon } from './Delete.svg';
export { default as DragIcon } from './Drag.svg';
export { default as ExternalLinkIcon } from './ExternalLink.svg';
export { default as FeelIcon } from './Feel.svg';
export { default as HelpIcon } from './help.svg';
export { default as PopupIcon } from './Popup.svg';
export { default as CloseIcon } from './Close.svg';
export { default as LaunchIcon } from './Launch.svg';
export { default as PopupIcon } from './Popup.svg';
87 changes: 47 additions & 40 deletions test/spec/components/FeelPopup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import TestContainer from 'mocha-test-container-support';
import EventBus from 'diagram-js/lib/core/EventBus';

import {
query as domQuery
query as domQuery,
queryAll as domQueryAll
} from 'min-dom';

import {
Expand Down Expand Up @@ -78,6 +79,49 @@ describe('<FeelPopup>', function() {
});


it('should render links', async function() {

// given
const parent = document.createElement('div');

// when
createFeelPopup({
popupContainer: parent,
getPopupLinks: (type) => {
if (type === 'foo') {
return [
{ href: 'https://foo.com/', title: 'Foo' },
{ href: 'https://bar.com/', title: 'Bar' }
];
}

return [];
},
type: 'foo'
}, container);

const childComponent = domQuery('.child-component', container);

const btn = domQuery('button', childComponent);

// when
await act(() => {
btn.click();
});

// then
const links = domQueryAll('.bio-properties-panel-feel-popup__title-link', parent);

expect(links.length).to.equal(2);

expect(links[0].href).to.equal('https://foo.com/');
expect(links[0].textContent).to.equal('Foo');

expect(links[1].href).to.equal('https://bar.com/');
expect(links[1].textContent).to.equal('Bar');
});


it('should restore focus on source element', async function() {

// given
Expand Down Expand Up @@ -412,25 +456,6 @@ describe('<FeelPopup>', function() {
});


it('should link to <feel> documentation', async function() {

// given
createFeelPopup({ type: 'feel' }, container);

const childComponent = domQuery('.child-component', container);
const btn = domQuery('button', childComponent);

// when
await act(() => {
btn.click();
});

// then
const link = domQuery('.bio-properties-panel-feel-popup__title-link', document.body);
expect(link).to.exist;
});


it('should focus <feel> editor', async function() {

// given
Expand Down Expand Up @@ -587,25 +612,6 @@ describe('<FeelPopup>', function() {
});


it('should link to <feelers> documentation', async function() {

// given
createFeelPopup({ type: 'feelers' }, container);

const childComponent = domQuery('.child-component', container);
const btn = domQuery('button', childComponent);

// when
await act(() => {
btn.click();
});

// then
const link = domQuery('.bio-properties-panel-feel-popup__title-link', document.body);
expect(link).to.exist;
});


it('should focus <feelers> editor', async function() {

// given
Expand Down Expand Up @@ -738,13 +744,14 @@ describe('<FeelPopup>', function() {
function createFeelPopup(props, container) {
const {
popupContainer,
getPopupLinks,
element = noopElement,
eventBus = new EventBus(),
type
} = props;

return render(
<FEELPopupRoot popupContainer={ popupContainer } element={ element } eventBus={ eventBus }>
<FEELPopupRoot popupContainer={ popupContainer } getPopupLinks={ getPopupLinks } element={ element } eventBus={ eventBus }>
<ChildComponent type={ type } />
</FEELPopupRoot>,
{ container }
Expand Down

0 comments on commit 52b372a

Please sign in to comment.