This repository was archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Add examples to show different configs in which datagrid action menu can be displayed #349
Open
ps37
wants to merge
1
commit into
vmware-archive:master
Choose a base branch
from
ps37:grid-action-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
projects/examples/src/components/datagrid/datagrid-action-display.example.component.html
This file contains hidden or 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,34 @@ | ||
<h4 class="example-heading">Actions displayed on top as inline bar</h4> | ||
<p> | ||
This is the default display configuration used by datagrid if no display config is provided. When displayed inline, | ||
Contextual actions that are marked as featured are shown towards the left outside the dropdown containing all the | ||
contextual actions | ||
</p> | ||
<vcd-datagrid | ||
[gridData]="gridData" | ||
(gridRefresh)="refresh($event)" | ||
[columns]="columns" | ||
[actions]="actions" | ||
[actionDisplayConfig]="topAndInlineActionDisplayConfig" | ||
[selectionType]="singleSelectionType" | ||
></vcd-datagrid> | ||
|
||
<h4 class="example-heading">Contextual actions displayed in rows as inline bar</h4> | ||
<p>Only contextual actions are displayed in rows and static actions are always displayed on top</p> | ||
<vcd-datagrid | ||
[gridData]="gridData" | ||
(gridRefresh)="refresh($event)" | ||
[columns]="columns" | ||
[actions]="actions" | ||
[actionDisplayConfig]="rowAndInlineActionDisplayConfig" | ||
></vcd-datagrid> | ||
|
||
<h4 class="example-heading">Contextual actions displayed in rows as dropdown</h4> | ||
<p>Only contextual actions are displayed in rows and static actions are always displayed on top</p> | ||
<vcd-datagrid | ||
[gridData]="gridData" | ||
(gridRefresh)="refresh($event)" | ||
[columns]="columns" | ||
[actions]="actions" | ||
[actionDisplayConfig]="rowAndDropdownActionDisplayConfig" | ||
></vcd-datagrid> |
7 changes: 7 additions & 0 deletions
7
projects/examples/src/components/datagrid/datagrid-action-display.example.component.scss
This file contains hidden or 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,7 @@ | ||
vcd-datagrid ::ng-deep .inline-actions-container { | ||
& .inline-action-dropdown { | ||
& ::ng-deep .nested-dropdown > .first-dropdown-toggle { | ||
margin-top: 0 !important; | ||
} | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
projects/examples/src/components/datagrid/datagrid-action-display.example.component.ts
This file contains hidden or 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,159 @@ | ||
/*! | ||
* Copyright 2019 VMware, Inc. | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
import { Component, ViewChild } from '@angular/core'; | ||
import { | ||
ActionDisplayConfig, | ||
ActionItem, | ||
ActionStyling, | ||
ActionType, | ||
DatagridActionDisplayConfig, | ||
DatagridComponent, | ||
DatagridContextualActionPosition, | ||
getDefaultDatagridActionDisplayConfig, | ||
GridColumn, | ||
GridDataFetchResult, | ||
GridSelectionType, | ||
GridState, | ||
TextIcon, | ||
} from '@vcd/ui-components'; | ||
|
||
interface Record { | ||
value: string; | ||
paused: boolean; | ||
} | ||
|
||
interface Blah { | ||
foo: string; | ||
bar: string; | ||
} | ||
|
||
type HandlerData = Record[] | Blah; | ||
|
||
/** | ||
* | ||
*/ | ||
@Component({ | ||
selector: 'vcd-datagrid-action-display-example', | ||
templateUrl: `./datagrid-action-display.example.component.html`, | ||
styleUrls: ['datagrid-action-display.example.component.scss'], | ||
}) | ||
export class DatagridActionDisplayExampleComponent<R extends Record> { | ||
@ViewChild(DatagridComponent, { static: true }) dg: DatagridComponent<R>; | ||
|
||
gridData: GridDataFetchResult<Record> = { | ||
items: [], | ||
}; | ||
|
||
singleSelectionType = GridSelectionType.Single; | ||
|
||
columns: GridColumn<R>[] = [ | ||
{ | ||
displayName: 'Some Value', | ||
renderer: 'value', | ||
}, | ||
]; | ||
|
||
actions: ActionItem<R, HandlerData>[] = [ | ||
{ | ||
textKey: 'Add', | ||
handler: () => { | ||
console.log('Adding stuff!'); | ||
}, | ||
class: 'add', | ||
actionType: ActionType.STATIC_FEATURED, | ||
isTranslatable: false, | ||
}, | ||
{ | ||
textKey: 'Custom handler data', | ||
handler: (rec: R[], data: Blah) => { | ||
console.log('Custom handler data ' + JSON.stringify(data)); | ||
}, | ||
handlerData: { foo: 'foo', bar: 'bar' }, | ||
class: 'b', | ||
icon: 'pause', | ||
actionType: ActionType.STATIC, | ||
isTranslatable: false, | ||
}, | ||
{ | ||
textKey: 'Contextual action', | ||
handler: () => { | ||
console.log('Contextual action output'); | ||
}, | ||
availability: (rec: R[]) => rec.length === 1, | ||
isTranslatable: false, | ||
}, | ||
{ | ||
textKey: 'power.actions', | ||
children: [ | ||
{ | ||
textKey: 'Start', | ||
handler: (rec: R[]) => { | ||
console.log('Starting ' + rec[0].value); | ||
rec[0].paused = false; | ||
}, | ||
availability: (rec: R[]) => rec.length === 1 && rec[0].paused, | ||
actionType: ActionType.CONTEXTUAL_FEATURED, | ||
isTranslatable: false, | ||
}, | ||
{ | ||
textKey: 'Stop', | ||
handler: (rec: R[]) => { | ||
console.log('Stopping ' + (rec as R[])[0].value); | ||
rec[0].paused = true; | ||
}, | ||
availability: (rec: R[]) => rec.length === 1 && !rec[0].paused, | ||
actionType: ActionType.CONTEXTUAL_FEATURED, | ||
isTranslatable: false, | ||
}, | ||
], | ||
}, | ||
{ | ||
textKey: 'grouped.actions', | ||
children: [ | ||
{ | ||
textKey: 'Contextual featured', | ||
actionType: ActionType.CONTEXTUAL_FEATURED, | ||
handler: () => null, | ||
isTranslatable: false, | ||
}, | ||
{ | ||
textKey: 'Contextual 2', | ||
handler: () => null, | ||
isTranslatable: false, | ||
}, | ||
], | ||
isTranslatable: true, | ||
}, | ||
]; | ||
|
||
topAndInlineActionDisplayConfig: DatagridActionDisplayConfig = getDefaultDatagridActionDisplayConfig(); | ||
|
||
rowAndInlineActionDisplayConfig: DatagridActionDisplayConfig = { | ||
contextual: { | ||
styling: ActionStyling.INLINE, | ||
position: DatagridContextualActionPosition.ROW, | ||
}, | ||
}; | ||
|
||
rowAndDropdownActionDisplayConfig: DatagridActionDisplayConfig = { | ||
contextual: { | ||
styling: ActionStyling.DROPDOWN, | ||
position: DatagridContextualActionPosition.ROW, | ||
}, | ||
}; | ||
|
||
refresh(eventData: GridState<R>): void { | ||
this.gridData = { | ||
items: [ | ||
{ value: 'a', paused: false }, | ||
{ value: 'b', paused: true }, | ||
{ value: 'a', paused: true }, | ||
{ value: 'b', paused: false }, | ||
], | ||
totalItems: 2, | ||
}; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
projects/examples/src/components/datagrid/datagrid-action-display.example.module.ts
This file contains hidden or 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,18 @@ | ||
/*! | ||
* Copyright 2019 VMware, Inc. | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { ClarityModule } from '@clr/angular'; | ||
import { VcdComponentsModule } from '@vcd/ui-components'; | ||
import { DatagridActionDisplayExampleComponent } from './datagrid-action-display.example.component'; | ||
|
||
@NgModule({ | ||
declarations: [DatagridActionDisplayExampleComponent], | ||
imports: [CommonModule, ClarityModule, VcdComponentsModule], | ||
exports: [DatagridActionDisplayExampleComponent], | ||
entryComponents: [DatagridActionDisplayExampleComponent], | ||
}) | ||
export class DatagridActionDisplayExampleModule {} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2021