Skip to content

Commit 87f7162

Browse files
sherfin94stepinfwd
andauthored
Feature/modal updates rebased to main (ToolJet#3465)
* modal docs * modal enhancement , added more properties * widget properties updates * revert unwanted change * bugfix close * renaming as "hideTitleBar" * migration * revert unwanted code * temp stash * updates * migration tested Co-authored-by: stepinfwd <[email protected]>
1 parent 1edcd1a commit 87f7162

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

docs/docs/widgets/modal.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ Title that should be shown on the header of the modal.
2626

2727
Size of the modal. Options are `medium`, `small` and `large`. The default is `small`. You can also programmatically configure the value by clicking on the `Fx` and set the value to `sm`, `md` or `lg`.
2828

29+
### Hide title bar
30+
To hide modal header , default is false.
31+
### Hide close button
32+
To hide modal close button , default is false.
33+
34+
### Hide on escape
35+
To disable modal hide on pressing escape key , default is true.
36+
2937
## Layout
3038

3139
### Show on desktop

frontend/src/Editor/Components/Modal.jsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const Modal = function Modal({
1717
setExposedVariable,
1818
}) {
1919
const [showModal, setShowModal] = useState(false);
20+
const { hideOnEsc, hideCloseButton, hideTitleBar } = properties;
2021
const parentRef = useRef(null);
2122

2223
const title = properties.title ?? '';
@@ -46,19 +47,23 @@ export const Modal = function Modal({
4647
keyboard={true}
4748
enforceFocus={false}
4849
animation={false}
49-
onEscapeKeyDown={() => hideModal()}
50+
onEscapeKeyDown={() => hideOnEsc && hideModal()}
5051
>
5152
{containerProps.mode === 'edit' && (
5253
<ConfigHandle id={id} component={component} setSelectedComponent={containerProps.onComponentClick} />
5354
)}
54-
<BootstrapModal.Header>
55-
<BootstrapModal.Title>{title}</BootstrapModal.Title>
56-
<div>
57-
<Button variant={darkMode ? 'secondary' : 'light'} size="sm" onClick={hideModal}>
58-
x
59-
</Button>
60-
</div>
61-
</BootstrapModal.Header>
55+
{!hideTitleBar && (
56+
<BootstrapModal.Header>
57+
<BootstrapModal.Title>{title}</BootstrapModal.Title>
58+
{!hideCloseButton && (
59+
<div>
60+
<Button variant={darkMode ? 'secondary' : 'light'} size="sm" onClick={() => hideModal()}>
61+
x
62+
</Button>
63+
</div>
64+
)}
65+
</BootstrapModal.Header>
66+
)}
6267

6368
<BootstrapModal.Body style={{ height }} ref={parentRef} id={id}>
6469
<SubContainer parent={id} {...containerProps} parentRef={parentRef} />

frontend/src/Editor/WidgetManager/widgetConfig.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ export const widgets = [
291291
},
292292
properties: {
293293
title: { type: 'code', displayName: 'Title' },
294+
hideTitleBar: { type: 'toggle', displayName: 'Hide title bar' },
295+
hideCloseButton: { type: 'toggle', displayName: 'Hide close button' },
296+
hideOnEsc: { type: 'toggle', displayName: 'Hide on escape' },
297+
294298
size: {
295299
type: 'select',
296300
displayName: 'Modal size',
@@ -316,6 +320,9 @@ export const widgets = [
316320
properties: {
317321
title: { value: 'This title can be changed' },
318322
size: { value: 'md' },
323+
hideTitleBar: { value: '{{false}}' },
324+
hideCloseButton: { value: '{{false}}' },
325+
hideOnEsc: { value: '{{true}}' },
319326
},
320327
events: [],
321328
styles: {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AppVersion } from '../src/entities/app_version.entity';
2+
import { MigrationInterface, QueryRunner } from 'typeorm';
3+
4+
export class modalProperties1656061763136 implements MigrationInterface {
5+
public async up(queryRunner: QueryRunner): Promise<void> {
6+
const entityManager = queryRunner.manager;
7+
const appVersions = await entityManager.find(AppVersion);
8+
9+
for (const version of appVersions) {
10+
const definition = version['definition'];
11+
12+
if (definition) {
13+
const components = definition['components'];
14+
15+
for (const componentId of Object.keys(components)) {
16+
const component = components[componentId];
17+
18+
if (component.component.component === 'Modal') {
19+
component.component.definition.properties.hideTitleBar = { value: false };
20+
component.component.definition.properties.hideCloseButton = { value: false };
21+
component.component.definition.properties.hideOnEsc = { value: true };
22+
components[componentId] = {
23+
...component,
24+
component: {
25+
...component.component,
26+
definition: {
27+
...component.component.definition,
28+
},
29+
},
30+
};
31+
}
32+
}
33+
34+
definition['components'] = components;
35+
version.definition = definition;
36+
37+
await entityManager.update(AppVersion, { id: version.id }, { definition });
38+
}
39+
}
40+
}
41+
42+
public async down(queryRunner: QueryRunner): Promise<void> {}
43+
}

0 commit comments

Comments
 (0)