Skip to content

Commit

Permalink
Merge pull request #1985 from apuliasoft/inputpanel
Browse files Browse the repository at this point in the history
bugfix(kup-input-panel): button from shape, table single cell disabled, fix e2e tests
  • Loading branch information
lucafoscili authored Jul 10, 2024
2 parents df81790 + 6a493e8 commit c8f4c24
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 78 deletions.
138 changes: 70 additions & 68 deletions packages/ketchup/src/components/kup-input-panel/kup-input-panel.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,43 +503,44 @@ describe('kup-input-panel', () => {
const col2Title = 'Column 2';
const col2Name = 'COL2';
const col2Value = 'Row 1 column 2';
const tableData = {
type: 'SmeupDataTable',
columns: [
{
name: col1Name,
title: col1Title,
},
{
editable: false,
name: col2Name,
title: col2Title,
},
],
rows: [
{
cells: {
COL1: {
value: col1Value,
},
COL2: {
value: col2Value,
},
},
},
],
};
const data = {
columns: [
{
name: 'DAT',
name: 'DAT1',
visible: true,
},
],
rows: [
{
cells: {
DAT: {
value: {
type: 'SmeupDataTable',
columns: [
{
name: col1Name,
title: col1Title,
},
{
editable: false,
name: col2Name,
title: col2Title,
},
],
rows: [
{
cells: {
COL1: {
value: col1Value,
},
COL2: {
value: col2Value,
},
},
},
],
},
DAT1: {
value: JSON.stringify(tableData),
editable: true,
shape: 'TBL',
},
Expand Down Expand Up @@ -608,54 +609,56 @@ describe('kup-input-panel', () => {
const col2Row2Value = 'Row 2 column 2';
const col1Values = [col1Value, col1Row2Value];

const tableData = {
type: 'SmeupDataTable',
columns: [
{
name: col1Name,
title: col1Title,
isEditable: true,
},
{
name: col2Name,
title: col2Title,
isEditable: false,
},
],
rows: [
{
cells: {
COL1: {
value: col1Value,
},
COL2: {
value: col2Value,
},
},
},
{
cells: {
COL1: {
value: col1Row2Value,
},
COL2: {
value: col2Row2Value,
},
},
},
],
};

const data = {
columns: [
{
name: 'DAT',
name: 'DAT2',
visible: true,
},
],
rows: [
{
cells: {
DAT: {
value: {
type: 'SmeupDataTable',
columns: [
{
name: col1Name,
title: col1Title,
isEditable: true,
},
{
name: col2Name,
title: col2Title,
isEditable: false,
},
],
rows: [
{
cells: {
COL1: {
value: col1Value,
},
COL2: {
value: col2Value,
},
},
},
{
cells: {
COL1: {
value: col1Row2Value,
},
COL2: {
value: col2Row2Value,
},
},
},
],
},
DAT2: {
value: JSON.stringify(tableData),
editable: true,
shape: 'TBL',
},
Expand Down Expand Up @@ -688,7 +691,6 @@ describe('kup-input-panel', () => {
const colTextField = await col1.find(
'.f-cell.string-cell .f-text-field'
);
console.log('row i', i);
expect(colTextField).not.toBeNull();

const input = await colTextField.find('input');
Expand Down
35 changes: 25 additions & 10 deletions packages/ketchup/src/components/kup-input-panel/kup-input-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ export class KupInputPanel {
[FCellTypes.DATE, 'kup-date-picker'],
]);
#cellCustomRender: Map<
FCellTypes,
FCellShapes,
(cell: KupDataCell, cellId: string) => any
> = new Map<FCellTypes, (cell: KupDataCell, cellId: string) => any>([
[FCellTypes.BUTTON, this.#renderButton.bind(this)],
[FCellTypes.TABLE, this.#renderDataTable.bind(this)],
> = new Map<FCellShapes, (cell: KupDataCell, cellId: string) => any>([
[FCellShapes.BUTTON_LIST, this.#renderButton.bind(this)],
[FCellShapes.TABLE, this.#renderDataTable.bind(this)],
]);
//#endregion

Expand Down Expand Up @@ -296,9 +296,7 @@ export class KupInputPanel {
return;
}

const cellType = dom.ketchup.data.cell.getType(cell, cell.shape);

const customRender = this.#cellCustomRender.get(cellType);
const customRender = this.#cellCustomRender.get(cell.shape);

if (customRender !== undefined) {
return customRender(cell, column.name);
Expand Down Expand Up @@ -583,7 +581,7 @@ export class KupInputPanel {

const dataAdapterMap = new Map<FCellTypes, DataAdapterFn>([
[FCellTypes.AUTOCOMPLETE, this.#CMBandACPAdapter.bind(this)],
[FCellTypes.BUTTON, this.#BTNAdapter.bind(this)],
[FCellTypes.BUTTON_LIST, this.#BTNAdapter.bind(this)],
[FCellTypes.CHART, this.#GRAAdapter.bind(this)],
[FCellTypes.CHIP, this.#CHIAdapter.bind(this)],
[FCellTypes.CHECKBOX, this.#CHKAdapter.bind(this)],
Expand Down Expand Up @@ -800,7 +798,7 @@ export class KupInputPanel {
id: string
) {
try {
const data = JSON.parse(cell.value);
let data = JSON.parse(cell.value);

if (!data) {
this.#kupManager.debug.logMessage(
Expand All @@ -820,7 +818,24 @@ export class KupInputPanel {
return null;
}

return data;
return {
...data,
rows: data.rows.map((row) => ({
...row,
cells: Object.keys(row.cells).reduce(
(cell, key) => ({
...cell,
[key]: {
...row.cells[key],
data: {
disabled: row.cells[key].editable === false,
},
},
}),
{}
),
})),
};
} catch (e) {
this.#kupManager.debug.logMessage(
this,
Expand Down

0 comments on commit c8f4c24

Please sign in to comment.