-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from jetstreamapp/feat/663
Add Tab Visibility to Permissions Editor
- Loading branch information
Showing
14 changed files
with
1,154 additions
and
198 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
174 changes: 158 additions & 16 deletions
174
apps/jetstream/src/app/components/manage-permissions/ManagePermissionsEditor.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
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
85 changes: 85 additions & 0 deletions
85
...tream/src/app/components/manage-permissions/ManagePermissionsEditorTabVisibilityTable.tsx
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,85 @@ | ||
import { useNonInitialEffect } from '@jetstream/shared/ui-utils'; | ||
import { MapOf } from '@jetstream/types'; | ||
import { AutoFullHeightContainer, ColumnWithFilter, DataTable } from '@jetstream/ui'; | ||
import { forwardRef, useCallback, useImperativeHandle, useState } from 'react'; | ||
import { resetGridChanges, updateRowsFromColumnAction } from './utils/permission-manager-table-utils'; | ||
import { | ||
DirtyRow, | ||
FieldPermissionTypes, | ||
ManagePermissionsEditorTableRef, | ||
PermissionManagerTableContext, | ||
PermissionTableSummaryRow, | ||
PermissionTableTabVisibilityCell, | ||
} from './utils/permission-manager-types'; | ||
|
||
function getRowKey(row: PermissionTableTabVisibilityCell) { | ||
return row.key; | ||
} | ||
|
||
// summary row is just a placeholder for rendered content | ||
const SUMMARY_ROWS: PermissionTableSummaryRow[] = [{ type: 'HEADING' }, { type: 'ACTION' }]; | ||
|
||
export interface ManagePermissionsEditorTabVisibilityTableProps { | ||
columns: ColumnWithFilter<PermissionTableTabVisibilityCell, PermissionTableSummaryRow>[]; | ||
rows: PermissionTableTabVisibilityCell[]; | ||
totalCount: number; | ||
onFilter: (value: string) => void; | ||
onBulkUpdate: (rows: PermissionTableTabVisibilityCell[], indexes?: number[]) => void; | ||
onDirtyRows?: (values: MapOf<DirtyRow<PermissionTableTabVisibilityCell>>) => void; | ||
} | ||
|
||
export const ManagePermissionsEditorTabVisibilityTable = forwardRef<any, ManagePermissionsEditorTabVisibilityTableProps>( | ||
({ columns, rows, totalCount, onFilter, onBulkUpdate, onDirtyRows }, ref) => { | ||
const [dirtyRows, setDirtyRows] = useState<MapOf<DirtyRow<PermissionTableTabVisibilityCell>>>({}); | ||
|
||
useImperativeHandle<any, ManagePermissionsEditorTableRef>(ref, () => ({ | ||
resetChanges() { | ||
resetGridChanges({ rows, type: 'tabVisibility' }); | ||
setDirtyRows({}); | ||
}, | ||
})); | ||
|
||
useNonInitialEffect(() => { | ||
dirtyRows && onDirtyRows && onDirtyRows(dirtyRows); | ||
}, [dirtyRows, onDirtyRows]); | ||
|
||
function handleColumnAction(action: 'selectAll' | 'unselectAll' | 'reset', columnKey: string) { | ||
const [id, typeLabel] = columnKey.split('-'); | ||
onBulkUpdate(updateRowsFromColumnAction('tabVisibility', action, typeLabel as FieldPermissionTypes, id, rows)); | ||
} | ||
|
||
const handleRowsChange = useCallback( | ||
(rows: PermissionTableTabVisibilityCell[], { indexes }) => { | ||
onBulkUpdate(rows, indexes); | ||
}, | ||
[onBulkUpdate] | ||
); | ||
|
||
return ( | ||
<div> | ||
<AutoFullHeightContainer fillHeight setHeightAttr bottomBuffer={15}> | ||
<DataTable | ||
columns={columns} | ||
data={rows} | ||
getRowKey={getRowKey} | ||
topSummaryRows={SUMMARY_ROWS} | ||
onRowsChange={handleRowsChange} | ||
context={ | ||
{ | ||
type: 'tabVisibility', | ||
totalCount, | ||
onFilterRows: onFilter, | ||
onColumnAction: handleColumnAction, | ||
onBulkAction: onBulkUpdate, | ||
} as PermissionManagerTableContext | ||
} | ||
rowHeight={24} | ||
summaryRowHeight={38} | ||
/> | ||
</AutoFullHeightContainer> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default ManagePermissionsEditorTabVisibilityTable; |
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
Oops, something went wrong.