Skip to content

Commit

Permalink
Merge pull request #1842 from apuliasoft/inputpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafoscili authored Apr 3, 2024
2 parents 92c8479 + 74e9b49 commit 3c4c54d
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 4 deletions.
33 changes: 32 additions & 1 deletion packages/ketchup/src/assets/input-panel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const data = {
let data = {
columns: [
{
name: 'NAM',
Expand Down Expand Up @@ -127,3 +127,34 @@ const data = {

const inputPanel = document.getElementById('input-panel');
inputPanel.data = data;

const inputPanelCallback = [
{
eventName: 'kup-autocomplete-input',
eventCallback: (e) => {
const newdata = {
...data,
rows: data.rows.map((row) => {
const keys = Object.keys(row.cells);
const updatedCells = keys.reduce((acc, key) => {
let updatedValue = e.state.find(
(state) => state.column.name === key
).cell.value;
return {
...acc,
[key]: {
...row.cells[key],
value: updatedValue,
},
};
}, {});
return { ...row, cells: updatedCells };
}),
};
const inputPanel = document.getElementById('input-panel');
inputPanel.data = newdata;
},
},
];

inputPanel.valueChangeCb = inputPanelCallback;
25 changes: 23 additions & 2 deletions packages/ketchup/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { FImageData } from "./f-components/f-image/f-image-declarations";
import { KupImageClickEventPayload } from "./components/kup-image/kup-image-declarations";
import { KupImageListDataNode, KupImageListEventPayload } from "./components/kup-image-list/kup-image-list-declarations";
import { KupTreeColumnMenuEventPayload, KupTreeColumnRemoveEventPayload, KupTreeContextMenuEventPayload, KupTreeDynamicMassExpansionEventPayload, KupTreeExpansionMode, KupTreeNode, KupTreeNodeButtonClickEventPayload, KupTreeNodeCollapseEventPayload, KupTreeNodeExpandEventPayload, KupTreeNodeSelectedEventPayload, TreeNodePath } from "./components/kup-tree/kup-tree-declarations";
import { KupInputPanelData } from "./components/kup-input-panel/kup-input-panel-declarations";
import { InputPanelEventsCallback, KupInputPanelData } from "./components/kup-input-panel/kup-input-panel-declarations";
import { KupLazyRender } from "./components/kup-lazy/kup-lazy-declarations";
import { KupNavBarStyling } from "./components/kup-nav-bar/kup-nav-bar-declarations";
import { KupNumericPickerEventPayload } from "./components/kup-numeric-picker/kup-numeric-picker-declarations";
Expand Down Expand Up @@ -94,7 +94,7 @@ export { FImageData } from "./f-components/f-image/f-image-declarations";
export { KupImageClickEventPayload } from "./components/kup-image/kup-image-declarations";
export { KupImageListDataNode, KupImageListEventPayload } from "./components/kup-image-list/kup-image-list-declarations";
export { KupTreeColumnMenuEventPayload, KupTreeColumnRemoveEventPayload, KupTreeContextMenuEventPayload, KupTreeDynamicMassExpansionEventPayload, KupTreeExpansionMode, KupTreeNode, KupTreeNodeButtonClickEventPayload, KupTreeNodeCollapseEventPayload, KupTreeNodeExpandEventPayload, KupTreeNodeSelectedEventPayload, TreeNodePath } from "./components/kup-tree/kup-tree-declarations";
export { KupInputPanelData } from "./components/kup-input-panel/kup-input-panel-declarations";
export { InputPanelEventsCallback, KupInputPanelData } from "./components/kup-input-panel/kup-input-panel-declarations";
export { KupLazyRender } from "./components/kup-lazy/kup-lazy-declarations";
export { KupNavBarStyling } from "./components/kup-nav-bar/kup-nav-bar-declarations";
export { KupNumericPickerEventPayload } from "./components/kup-numeric-picker/kup-numeric-picker-declarations";
Expand Down Expand Up @@ -2587,6 +2587,12 @@ export namespace Components {
* @default null
*/
"data": KupInputPanelData;
/**
* Used to retrieve component's props values.
* @param descriptions - When provided and true, the result will be the list of props with their description.
* @returns List of props as object, each key will be a prop.
*/
"getProps": (descriptions?: boolean) => Promise<GenericObject>;
/**
* Creates a hidden submit button in order to submit the form with enter.
* @default false
Expand All @@ -2596,11 +2602,21 @@ export namespace Components {
* This method is used to trigger a new render of the component.
*/
"refresh": () => Promise<void>;
/**
* Sets the props to the component.
* @param props - Object containing props that will be set to the component.
*/
"setProps": (props: GenericObject) => Promise<void>;
/**
* Sets the callback function on submit form
* @default null
*/
"submitCb": (e: SubmitEvent) => unknown;
/**
* Sets the callback function on value change event
* @default null
*/
"valueChangeCb": InputPanelEventsCallback[];
}
interface KupLazy {
/**
Expand Down Expand Up @@ -7394,6 +7410,11 @@ declare namespace LocalJSX {
* @default null
*/
"submitCb"?: (e: SubmitEvent) => unknown;
/**
* Sets the callback function on value change event
* @default null
*/
"valueChangeCb"?: InputPanelEventsCallback[];
}
interface KupLazy {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,23 @@ export type InputPanelCells = {
row?: KupInputPanelRow;
};

export type InputPanelEvent = {
state: { cell: KupDataCell; column: KupDataColumn }[];
data: {
field: string;
value: number | string | object;
};
};

export type InputPanelEventsCallback = {
eventName: string;
eventCallback: (e: InputPanelEvent) => unknown;
};

export enum KupInputPanelProps {
customStyle = 'Custom style of the component.',
data = 'Actual data of the input panel.',
hiddenSubmitButton = 'Creates a hidden submit button in order to submit the form with enter.',
submitCb = 'Sets the callback function on submit form',
valueChangeCb = 'Sets the callback function on value change event',
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
import {
DataAdapterFn,
InputPanelCells,
InputPanelEvent,
InputPanelEventsCallback,
KupInputPanelCell,
KupInputPanelColumn,
KupInputPanelData,
Expand Down Expand Up @@ -84,6 +86,12 @@ export class KupInputPanel {
* @default null
*/
@Prop() submitCb: (e: SubmitEvent) => unknown = null;

/**
* Sets the callback function on value change event
* @default null
*/
@Prop() valueChangeCb: InputPanelEventsCallback[] = [];
//#endregion

//#region STATES
Expand Down Expand Up @@ -184,6 +192,7 @@ export class KupInputPanel {
'form--column': !horizontal,
};

// We create a form for each row in data
return (
<form
class={classObj}
Expand Down Expand Up @@ -231,7 +240,10 @@ export class KupInputPanel {
const cell = row.cells[column.name];
const mappedCell = {
...cell,
data: this.#mapData(cell, column),
data: {
...this.#mapData(cell, column),
id: column.name,
},
slotData: this.#slotData(cell, column),
isEditable: cell.editable,
};
Expand Down Expand Up @@ -404,6 +416,24 @@ export class KupInputPanel {
componentDidLoad() {
this.kupReady.emit({ comp: this, id: this.rootElement.id });
this.#kupManager.debug.logLoad(this, true);

this.valueChangeCb.map((cbData) => {
this.rootElement.addEventListener(cbData.eventName, (e: any) => {
const inputPanelEvent: InputPanelEvent = {
state: this.inputPanelCells.find((data) =>
data.cells.find(
(cell) => cell.column.name === e.detail.id
)
).cells,
data: {
field: e.detail.id,
value: e.detail.inputValue || e.detail.value,
},
};

cbData.eventCallback(inputPanelEvent);
});
});
}

componentWillRender() {
Expand Down
45 changes: 45 additions & 0 deletions packages/ketchup/src/components/kup-input-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,51 @@
| `kup-input-panel-ready` | When component load is complete | `CustomEvent<KupEventPayload>` |


## Methods

### `getProps(descriptions?: boolean) => Promise<GenericObject>`

Used to retrieve component's props values.

#### Parameters

| Name | Type | Description |
| -------------- | --------- | -------------------------------------------------------------------------------------- |
| `descriptions` | `boolean` | - When provided and true, the result will be the list of props with their description. |

#### Returns

Type: `Promise<GenericObject>`

List of props as object, each key will be a prop.

### `refresh() => Promise<void>`

This method is used to trigger a new render of the component.

#### Returns

Type: `Promise<void>`



### `setProps(props: GenericObject) => Promise<void>`

Sets the props to the component.

#### Parameters

| Name | Type | Description |
| ------- | --------------- | ------------------------------------------------------------ |
| `props` | `GenericObject` | - Object containing props that will be set to the component. |

#### Returns

Type: `Promise<void>`




## Dependencies

### Depends on
Expand Down

0 comments on commit 3c4c54d

Please sign in to comment.