-
Notifications
You must be signed in to change notification settings - Fork 245
feat(compass-crud): enable resizable column widths in document table view COMPASS-2218 #7573
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
Changes from 9 commits
7dd05c8
4cc8c83
107aacd
3ef14b4
da65852
26194e4
2021e77
7f9b1c5
24f08bc
7240a65
1ec1c9a
2fbe466
3273d6c
69b2cad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React from 'react'; | ||
| import { mount } from 'enzyme'; | ||
| import type { ReactWrapper } from 'enzyme'; | ||
| import HadronDocument from 'hadron-document'; | ||
| import { expect } from 'chai'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| import DocumentTableView, { | ||
| DocumentTableView as RawDocumentTableView, | ||
| } from './document-table-view'; | ||
|
|
||
| describe('<DocumentTableView />', function () { | ||
| describe('#render', function () { | ||
| context('when the documents have objects for ids', function () { | ||
| const docs = [{ _id: '6909a21e9e548506e786c1e5', name: 'test-1' }]; | ||
| const hadronDocs = docs.map((doc) => new HadronDocument(doc)); | ||
|
|
||
| let component: ReactWrapper; | ||
| beforeEach(function () { | ||
| component = mount( | ||
| <DocumentTableView | ||
| docs={hadronDocs} | ||
| ns={'database.collection'} | ||
| namespace={'database.collection'} | ||
| pathChanged={sinon.spy()} | ||
| table={{ | ||
| doc: null, | ||
| editParams: null, | ||
| path: [], | ||
| types: [], | ||
| }} | ||
| store={{ | ||
| gridStore: { | ||
| listen: sinon.spy(), | ||
| }, | ||
| }} | ||
| resetColumns={sinon.spy()} | ||
| tableData={{ | ||
| columnWidths: { | ||
| name: 1337, | ||
| }, | ||
| }} | ||
| start={1} | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| component?.unmount(); | ||
| }); | ||
|
|
||
| it('columnWidths data is applied to the relevant grid column', async function () { | ||
| // Ensure we wait for GridReadyEvent so columnApi is set | ||
| await new Promise(setImmediate); | ||
|
|
||
| const instance = component.find(RawDocumentTableView).instance(); | ||
| expect(instance).to.not.be.undefined; | ||
|
|
||
| const columnState = instance.columnApi.getColumnState(); | ||
| const nameCol = columnState.find((column) => column.colId === 'name'); | ||
| const idCol = columnState.find((column) => column.colId === '_id'); | ||
|
|
||
| expect(nameCol.width).to.equal(1337); | ||
| expect(idCol.width).to.equal(200); // Default width is 200 | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,10 @@ import { createStore } from 'redux'; | |
|
|
||
| type TabState = Record<string, Record<string, unknown>>; | ||
|
|
||
| export type TableDataObject = { | ||
| columnWidths: Record<string, number>; | ||
| }; | ||
|
||
|
|
||
| const SET_STATE = 'compass-workspaces/workspace-tab-state-provider/SET_STATE'; | ||
|
|
||
| const CLEANUP_TAB_STATE = | ||
|
|
@@ -67,6 +71,9 @@ export const TabStateStoreContext = React.createContext< | |
| ); | ||
|
|
||
| const WorkspaceTabIdContext = React.createContext<string | null>(null); | ||
| const WorkspaceTabTableDataContext = React.createContext<TableDataObject>({ | ||
| columnWidths: {}, | ||
| }); | ||
|
|
||
| /** | ||
| * Exported for testing purposes only | ||
|
|
@@ -82,14 +89,18 @@ export const TabStoreProvider: React.FunctionComponent = ({ children }) => { | |
|
|
||
| export const WorkspaceTabStateProvider = ({ | ||
| id, | ||
| tableData, | ||
| children, | ||
| }: { | ||
| id: string; | ||
| tableData: TableDataObject; | ||
| children: React.ReactChild; | ||
| }) => { | ||
| return ( | ||
| <WorkspaceTabIdContext.Provider value={id}> | ||
| <TabStoreProvider>{children}</TabStoreProvider> | ||
| <WorkspaceTabTableDataContext.Provider value={tableData}> | ||
| <TabStoreProvider>{children}</TabStoreProvider> | ||
| </WorkspaceTabTableDataContext.Provider> | ||
| </WorkspaceTabIdContext.Provider> | ||
| ); | ||
| }; | ||
|
|
@@ -107,6 +118,10 @@ export function useWorkspaceTabId() { | |
| return tabId; | ||
| } | ||
|
|
||
| export function useWorkspaceTabTableData() { | ||
| return useContext(WorkspaceTabTableDataContext); | ||
| } | ||
|
|
||
| const useStore: () => TabStateStore = createStoreHook(TabStateStoreContext); | ||
|
|
||
| const useSelector: TypedUseSelectorHook<TabState> = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.