Merge pull request #2027 from umap-project/tableditor-direct-import

chore: import TableEditor directly from layer
This commit is contained in:
Yohan Boniface 2024-07-31 22:53:19 +02:00 committed by GitHub
commit 5a0b75fd33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 107 deletions

View file

@ -19,6 +19,7 @@ import {
import { translate } from '../i18n.js' import { translate } from '../i18n.js'
import { DataLayerPermissions } from '../permissions.js' import { DataLayerPermissions } from '../permissions.js'
import { Point, LineString, Polygon } from './features.js' import { Point, LineString, Polygon } from './features.js'
import TableEditor from '../tableeditor.js'
export const LAYER_TYPES = [DefaultLayer, Cluster, Heat, Choropleth, Categorized] export const LAYER_TYPES = [DefaultLayer, Cluster, Heat, Choropleth, Categorized]
@ -1090,7 +1091,7 @@ export class DataLayer {
tableEdit() { tableEdit() {
if (!this.isVisible()) return if (!this.isVisible()) return
const editor = new U.TableEditor(this) const editor = new TableEditor(this)
editor.open() editor.open()
} }

View file

@ -22,7 +22,6 @@ import Slideshow from './slideshow.js'
import { SyncEngine } from './sync/engine.js' import { SyncEngine } from './sync/engine.js'
import Dialog from './ui/dialog.js' import Dialog from './ui/dialog.js'
import { EditPanel, FullPanel, Panel } from './ui/panel.js' import { EditPanel, FullPanel, Panel } from './ui/panel.js'
import TableEditor from './tableeditor.js'
import Tooltip from './ui/tooltip.js' import Tooltip from './ui/tooltip.js'
import URLs from './urls.js' import URLs from './urls.js'
import * as Utils from './utils.js' import * as Utils from './utils.js'
@ -72,7 +71,6 @@ window.U = {
Share, Share,
Slideshow, Slideshow,
SyncEngine, SyncEngine,
TableEditor,
Tooltip, Tooltip,
URLs, URLs,
Utils, Utils,

View file

@ -1,104 +0,0 @@
describe('L.TableEditor', () => {
let path = '/map/99/datalayer/edit/62/',
datalayer
before(async () => {
await fetchMock.mock(
/\/datalayer\/62\/\?.*/,
JSON.stringify(RESPONSES.datalayer62_GET)
)
this.options = {
umap_id: 99,
}
map = initMap({ umap_id: 99 })
const datalayer_options = defaultDatalayerData()
await map.initDataLayers([datalayer_options])
datalayer = map.getDataLayerByUmapId(62)
enableEdit()
})
after(() => {
fetchMock.restore()
clickCancel()
resetMap()
})
describe('#open()', () => {
var button
it('should exist table click on edit mode', () => {
button = qs(
'#browse_data_toggle_' + L.stamp(datalayer) + ' .icon-table'
)
expect(button).to.be.ok
})
it('should open table button click', () => {
happen.click(button)
expect(qs('.panel.full.on div.table')).to.be.ok
expect(qsa('.panel.full.on div.table form').length).to.eql(3) // One per feature.
expect(qsa('.panel.full.on div.table input').length).to.eql(3) // One per feature and per property.
})
})
describe('#properties()', () => {
var feature
before(() => {
var firstIndex = datalayer._index[0]
feature = datalayer._layers[firstIndex]
})
it('should create new property column', () => {
var newPrompt = () => {
return 'newprop'
}
var oldPrompt = window.prompt
window.prompt = newPrompt
var button = qs('.panel.full.on .add-property')
expect(button).to.be.ok
happen.click(button)
expect(qsa('.panel.full.on div.table input').length).to.eql(6) // One per feature and per property.
window.prompt = oldPrompt
})
it('should populate feature property on fill', () => {
var input = qs(
'form#umap-feature-properties_' + L.stamp(feature) + ' input[name=newprop]'
)
changeInputValue(input, 'the value')
expect(feature.properties.newprop).to.eql('the value')
})
it('should update property name on update click', () => {
var newPrompt = () => {
return 'newname'
}
var oldPrompt = window.prompt
window.prompt = newPrompt
var button = qs('.panel.full.on div.thead div.tcell:last-of-type .umap-edit')
expect(button).to.be.ok
happen.click(button)
expect(qsa('.panel.full.on div.table input').length).to.eql(6)
expect(feature.properties.newprop).to.be.undefined
expect(feature.properties.newname).to.eql('the value')
window.prompt = oldPrompt
})
it('should update property on delete click', () => {
var oldConfirm,
newConfirm = () => {
return true
}
oldConfirm = window.confirm
window.confirm = newConfirm
var button = qs(
'.panel.full.on div.thead div.tcell:last-of-type .umap-delete'
)
expect(button).to.be.ok
happen.click(button)
FEATURE = feature
expect(qsa('.panel.full.on div.table input').length).to.eql(3)
expect(feature.properties.newname).to.be.undefined
window.confirm = oldConfirm
})
})
})