-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44 Added a simple table editor, with CSV import/export
- Loading branch information
1 parent
ecf6409
commit 8d366d5
Showing
13 changed files
with
438 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** @jsx jsx */ | ||
/** @jsxFrag React.Fragment */ | ||
|
||
import { jsx } from '@emotion/react'; | ||
import React from 'react'; | ||
import { EditorModel } from '../../../model/editormodel'; | ||
import { MMELTable } from '../../../serialize/interface/supportinterface'; | ||
import { checkId, defaultItemSorter } from '../../../utils/ModelFunctions'; | ||
import { createTable } from '../../../utils/EditorFactory'; | ||
import { IListItem, IManageHandler } from '../../common/fields'; | ||
import ListManagePage from '../../common/listmanagement/listmanagement'; | ||
import TableItemEditPage from './TableItemEdit'; | ||
|
||
const TableEditPage: React.FC<{ | ||
model: EditorModel; | ||
setModel: (model: EditorModel) => void; | ||
}> = function ({ model, setModel }) { | ||
function matchFilter(x: MMELTable, filter: string) { | ||
return ( | ||
filter === '' || | ||
x.id.toLowerCase().includes(filter) || | ||
x.title.toLowerCase().includes(filter) | ||
); | ||
} | ||
|
||
function getTableListItems(filter: string): IListItem[] { | ||
return Object.values(model.tables) | ||
.filter(x => matchFilter(x, filter)) | ||
.map(x => ({ id: x.id, text: x.title })) | ||
.sort(defaultItemSorter); | ||
} | ||
|
||
function removeTableListItem(ids: string[]) { | ||
for (const id of ids) { | ||
delete model.tables[id]; | ||
} | ||
setModel(model); | ||
} | ||
|
||
function addTable(x: MMELTable): boolean { | ||
if (checkId(x.id, model.tables)) { | ||
model.tables[x.id] = { ...x }; | ||
setModel(model); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function updateTable(oldid: string, x: MMELTable): boolean { | ||
if (oldid !== x.id) { | ||
if (checkId(x.id, model.tables)) { | ||
delete model.tables[oldid]; | ||
model.tables[x.id] = { ...x }; | ||
setModel(model); | ||
return true; | ||
} | ||
return false; | ||
} else { | ||
model.tables[oldid] = { ...x }; | ||
setModel(model); | ||
return true; | ||
} | ||
} | ||
|
||
function getTableById(id: string): MMELTable { | ||
const table = model.tables[id]; | ||
if (table === undefined) { | ||
return createTable(''); | ||
} | ||
return table; | ||
} | ||
|
||
const tablehandler: IManageHandler<MMELTable> = { | ||
filterName: 'Table filter', | ||
itemName: 'View tables', | ||
Content: TableItemEditPage, | ||
initObj: createTable(''), | ||
model: model, | ||
getItems: getTableListItems, | ||
removeItems: removeTableListItem, | ||
addItem: obj => addTable(obj), | ||
updateItem: (oldid, obj) => updateTable(oldid, obj), | ||
getObjById: getTableById, | ||
}; | ||
|
||
return <ListManagePage {...tablehandler} />; | ||
}; | ||
|
||
export default TableEditPage; |
Oops, something went wrong.