Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/datagrid bugs #1472

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions e2e/tests/plugin-datagrid.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { expect, test } from '@playwright/test'

test.describe.configure({ mode: 'serial' })

const ADD_ROW_LABEL = 'Add data row'
const CLEAR_TABLE_LABEL = 'Clear table content'
const DEFAULT_EXAMPLE_PAGE =
'http://localhost:3000/view/?documentId=dmss://DemoDataSource/$Default'
const DEFAULT_EXAMPLE_CONTENT_AREA = 'enabled:dmss://DemoDataSource/$Default'
const NUMERIC_EXAMPLE_PAGE =
'http://localhost:3000/view/?documentId=dmss://DemoDataSource/$Numeric'
const NUMERIC_EXAMPLE_CONTENT_AREA = 'enabled:dmss://DemoDataSource/$Numeric'

test('Unknown dimensions', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeVisible()
await expect(table.getByRole('textbox').first()).toHaveValue('Dodge')
await table.getByRole('textbox').first().fill('Not Dodge')
await expect(table.getByRole('textbox').first()).toHaveValue('Not Dodge')
})

test('Set dimensions', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page
.getByRole('button', { name: 'Set dimensions', exact: true })
.click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeHidden()
await expect(table.getByRole('textbox').nth(16)).toHaveValue('Ford')
})

test('Vertical (Set dimensions)', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page
.getByRole('button', { name: 'Vertical (Set dimensions)', exact: true })
.click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeHidden()
await expect(table.getByRole('textbox').nth(4)).toHaveValue('Ford')
await expect(table.getByRole('textbox').nth(15)).toHaveValue(
'1D3MX48D48B28FPJU'
)
})

test('Vertical (Unknown dimensions)', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page
.getByRole('button', { name: 'Vertical (Unknown dimensions)', exact: true })
.click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeVisible()
await expect(table.getByRole('textbox').nth(4)).toHaveValue('Ford')
await expect(table.getByRole('textbox').nth(10)).toHaveValue(
'Extended Cab Pickup'
)
})

test('Custom labels', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page.getByRole('button', { name: 'Custom labels', exact: true }).click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeHidden()
await expect(table.getByText('John')).toBeVisible()
await expect(table.getByText('Manufacturer')).toBeVisible()
})

test('Hidden labels', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page.getByRole('button', { name: 'Hidden labels', exact: true }).click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')

await expect(table.getByText('A', { exact: true })).toBeHidden()
await expect(table.getByText('2', { exact: true })).toBeHidden()
})

test('No-edit columns and rows', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page
.getByRole('button', { name: 'No-edit columns and rows', exact: true })
.click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeHidden()
})

test('Non-editable', async ({ page }) => {
await page.goto(DEFAULT_EXAMPLE_PAGE)
await page.getByRole('button', { name: 'Non-editable', exact: true }).click()
const contentArea = page.getByTestId(DEFAULT_EXAMPLE_CONTENT_AREA)
const table = contentArea.getByRole('table')
await expect(contentArea.getByLabel(ADD_ROW_LABEL)).toBeHidden()
await expect(contentArea.getByLabel(CLEAR_TABLE_LABEL)).toBeHidden()
await expect(table.getByRole('textbox').first()).toHaveValue('Dodge')
await expect(table.getByRole('textbox').first()).toHaveAttribute('readonly')
})

test('Integer is number input in data grid', async ({ page }) => {
await page.goto(NUMERIC_EXAMPLE_PAGE)
const contentArea = page.getByTestId(NUMERIC_EXAMPLE_CONTENT_AREA)
await expect(contentArea).toBeVisible()
const table = contentArea.getByRole('table')
await expect(table).toBeVisible()
await expect(table.locator('input').first()).toHaveValue('1000')
await expect(table.locator('input').first()).toHaveAttribute('type', 'number')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Numeric",
"type": "CORE:Blueprint",
"attributes": [
{
"name": "type",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "name",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "data",
"type": "CORE:BlueprintAttribute",
"attributeType": "integer",
"dimensions": "*,*"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"_id": "Numeric",
"name": "Numeric",
"type": "./blueprints/Numeric",
"data": [
[1000, 2000, 4000, 8000],
[1000, 2000, 3000, 5000],
[1000, 2000, 3000, 4000],
[999, 888, 666, 555]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "CORE:RecipeLink",
"_blueprintPath_": "/plugins/data_grid/numeric/blueprints/Numeric",
"initialUiRecipe": {
"name": "ViewSelector",
"type": "CORE:UiRecipe",
"config": {
"type": "PLUGINS:dm-core-plugins/view_selector/ViewSelectorConfig",
"items": [
{
"type": "PLUGINS:dm-core-plugins/view_selector/ViewSelectorItem",
"label": "Numeric",
"viewConfig": {
"type": "CORE:InlineRecipeViewConfig",
"recipe": {
"name": "Numeric",
"type": "CORE:UiRecipe",
"description": "Single multidimensional primitive",
"config": {
"type": "PLUGINS:dm-core-plugins/data_grid/DataGridPluginConfig",
"fieldNames": ["data"]
},
"plugin": "@development-framework/dm-core-plugins/data_grid"
},
"scope": "self"
}
}
]
},
"plugin": "@development-framework/dm-core-plugins/view_selector/tabs"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
"name": "columnLabels",
"type": "CORE:BlueprintAttribute",
"description": "Define column labels or use predefined columns. Predefined values are ABC, ZYX, 123 and you can select those by using the spread operator ['...ABC']. You can also merge the two like this: ['custom field', 'custom field2', '...ABC']",
"description": "Define column labels or use predefined columns. Predefined values are ABC, ZYX, 123 and you can select those by using the spread operator ['...ABC'].",
"attributeType": "string",
"default": ["...ABC"],
"dimensions": "*",
Expand All @@ -72,17 +72,10 @@
"default": true,
"optional": true
},
{
"name": "movableRows",
"type": "CORE:BlueprintAttribute",
"attributeType": "boolean",
"default": true,
"optional": true
},
{
"name": "rowLabels",
"type": "CORE:BlueprintAttribute",
"description": "Define row labels or use predefined rows. Predefined values are ABC, ZYX, 123and you can select those by using the spread operator ['...ABC']. You can also merge the two like this: ['custom field', 'custom field2', '...ABC']",
"description": "Define row labels or use predefined rows. Predefined values are ABC, ZYX, 123and you can select those by using the spread operator ['...ABC'].",
"attributeType": "string",
"default": ["...123"],
"dimensions": "*",
Expand Down
13 changes: 12 additions & 1 deletion packages/dm-core-plugins/src/data-grid/DataCell/DataCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export function DataCell(props: DataCellProps) {
? '-'
: Number.parseFloat(value)
}
if (attributeType === 'integer') {
return value === ''
? undefined
: value === '-'
? '-'
: Number.parseInt(value, 10)
}
if (attributeType === 'boolean') {
return checked
}
Expand Down Expand Up @@ -62,7 +69,11 @@ export function DataCell(props: DataCellProps) {
onChange={(event) => updateValue(event, rowIndex, cellIndex)}
attributeType={attributeType}
readOnly={!config.editable}
type={attributeType === 'number' ? 'number' : 'text'}
type={
attributeType === 'number' || attributeType === 'integer'
? 'number'
: 'text'
}
/>
)}
</Styled.Cell>
Expand Down
Loading
Loading