Skip to content

Commit

Permalink
feat: add freeze action column functionality to table view (onecx#120)
Browse files Browse the repository at this point in the history
* feat: add freeze functionality to table view

* fix: fix broken column comparison

* test: smoke tests for frozen column in interactive data view, data view and data table

* test: test config dialog and dynamic config changes

* refactor: rename variables from sticky to frozen

* fix: fix custom group column selector story
  • Loading branch information
bastianjakobi authored Feb 21, 2024
1 parent 2869bfd commit 6cecae9
Show file tree
Hide file tree
Showing 17 changed files with 576 additions and 61 deletions.
11 changes: 10 additions & 1 deletion libs/portal-integration-angular/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
"INACTIVE_COLUMNS_LABEL": "Inaktive Spalten",
"SAVE_BUTTON_LABEL": "Speichern",
"CANCEL_BUTTON_LABEL": "Abbrechen",
"DIALOG_TITLE": "Spalten für benutzerdefinierte Gruppe auswählen"
"DIALOG_TITLE": "Spalten für benutzerdefinierte Gruppe auswählen",
"CONFIGURE_ACTION_COLUMN": {
"TITLE": "Aktionsspalte konfigurieren",
"FREEZE": "Aktionsspalte immer anzeigen",
"POSITION": "Position der Aktionsspalte",
"YES": "Ja",
"NO": "Nein",
"LEFT": "Links",
"RIGHT": "Rechts"
}
},
"OCX_LIST_GRID_SORT": {
"DROPDOWN": {
Expand Down
11 changes: 10 additions & 1 deletion libs/portal-integration-angular/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
"INACTIVE_COLUMNS_LABEL": "Inactive columns",
"SAVE_BUTTON_LABEL": "Save",
"CANCEL_BUTTON_LABEL": "Cancel",
"DIALOG_TITLE": "Custom group column selection"
"DIALOG_TITLE": "Custom group column selection",
"CONFIGURE_ACTION_COLUMN": {
"TITLE": "Configure action column",
"FREEZE": "Always show action column",
"POSITION": "Position of action column",
"YES": "Yes",
"NO": "No",
"LEFT": "Left",
"RIGHT": "Right"
}
},
"OCX_LIST_GRID_SORT": {
"DROPDOWN": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@
</ng-template>
</p-pickList>

<div class="pt-4">
<p class="text-xl font-bold">{{'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.TITLE' | translate}}</p>
<div class="flex gap-6 px-3">
<div>
<p class="mb-1">{{'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.FREEZE' | translate}}</p>
<p-selectButton
[options]="frozenOptions"
[(ngModel)]="frozenActionColumnModel"
optionLabel="label"
optionValue="value"
id="frozenActionColumn"
name="frozen-action-column-select-button"
>
<ng-template let-option pTemplate> {{option.label | translate}} </ng-template>
</p-selectButton>
</div>
<div>
<p class="mb-1">{{'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.POSITION' | translate}}</p>
<p-selectButton
[options]="alignmentOptions"
[(ngModel)]="actionColumnPositionModel"
optionLabel="label"
optionValue="value"
id="actionColumnPosition"
class="mt-2"
name="action-column-position-select-button"
>
<ng-template let-option pTemplate> {{option.label | translate}} </ng-template>
</p-selectButton>
</div>
</div>
</div>

<ng-template pTemplate="footer">
<p-button
id="cancelButton"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { CustomGroupColumnSelectorComponent } from './custom-group-column-selector.component';
import { Meta, moduleMetadata, applicationConfig, StoryFn } from '@storybook/angular';
import { TranslateModule } from '@ngx-translate/core';
import { ButtonModule } from 'primeng/button';
import { importProvidersFrom } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ColumnType } from '../../../model/column-type.model';
import { DropdownModule } from 'primeng/dropdown';
import { DialogModule } from 'primeng/dialog';
import { PickListModule } from 'primeng/picklist';
import { CheckboxModule } from 'primeng/checkbox';
import { FormsModule } from '@angular/forms';
import { SelectButtonModule } from 'primeng/selectbutton';
import { StorybookTranslateModule } from '../../storybook-translate.module';


type CustomGroupColumnSelectorInputs = Pick<CustomGroupColumnSelectorComponent, 'columns' | 'displayedColumns' |'actionColumnPosition' | 'frozenActionColumn' | 'dialogTitle' | 'saveButtonLabel' | 'cancelButtonLabel' | 'activeColumnsLabel' | 'inactiveColumnsLabel'>
const CustomGroupColumnSelectorComponentSBConfig: Meta<CustomGroupColumnSelectorComponent> = {
title: 'CustomGroupColumnSelectorComponent',
component: CustomGroupColumnSelectorComponent,
decorators: [
applicationConfig({
providers: [
importProvidersFrom(BrowserModule),
importProvidersFrom(BrowserAnimationsModule),
importProvidersFrom(TranslateModule.forRoot({})),
]
}),
moduleMetadata({
declarations: [CustomGroupColumnSelectorComponent],
imports: [
DropdownModule,
DialogModule,
PickListModule,
ButtonModule,
CheckboxModule,
FormsModule,
SelectButtonModule,
StorybookTranslateModule
]
})
]
}
const Template: StoryFn = (args) => ({
props: args,
})

const defaultComponentArgs: CustomGroupColumnSelectorInputs = {
columns: [
{
id: "product",
columnType: ColumnType.STRING,
nameKey: "Product",
sortable: false,
},
{
id: "amount",
columnType: ColumnType.NUMBER,
nameKey: "Amount",
sortable: true
}
],
displayedColumns: [
{
id: "date",
columnType: ColumnType.DATE,
nameKey: "Date",
sortable: false,
},
],
frozenActionColumn: true,
actionColumnPosition: 'right',
dialogTitle: 'Column configurator',
saveButtonLabel: 'Save',
cancelButtonLabel: 'Cancel',
activeColumnsLabel: 'Active',
inactiveColumnsLabel: 'Inactive'
}

export const Default = {
render: Template,
args: {
...defaultComponentArgs,
actionColumnConfigChanged: ($event: any) => console.log("Action column config changed ", $event)
},
argTypes: {
actionColumnConfigChanged: {action: 'actionColumnConfigChanged'}
},
}

export default CustomGroupColumnSelectorComponentSBConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { TranslateService } from '@ngx-translate/core'
import { DataTableColumn } from '../../../model/data-table-column.model'

export type ColumnSelectionChangedEvent = { activeColumns: DataTableColumn[] }
export type ActionColumnChangedEvent = {
frozenActionColumn: boolean
actionColumnPosition: 'left' | 'right'
}

@Component({
selector: 'ocx-custom-group-column-selector',
Expand All @@ -18,12 +22,38 @@ export class CustomGroupColumnSelectorComponent {
@Input() cancelButtonLabel = ''
@Input() activeColumnsLabel = ''
@Input() inactiveColumnsLabel = ''
@Input() frozenActionColumn = false
@Input() actionColumnPosition: 'left' | 'right' = 'right'

@Output() columnSelectionChanged: EventEmitter<ColumnSelectionChangedEvent> = new EventEmitter()
@Output() actionColumnConfigChanged: EventEmitter<ActionColumnChangedEvent> = new EventEmitter()

hiddenColumnsModel: DataTableColumn[] = []
displayedColumnsModel: DataTableColumn[] = []
frozenActionColumnModel = false
actionColumnPositionModel: 'left' | 'right' = 'right'
visible = false
alignmentOptions = [
{
label: 'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.LEFT',
value: 'left',
},
{
label: 'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.RIGHT',
value: 'right',
},
]

frozenOptions = [
{
label: 'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.YES',
value: true,
},
{
label: 'OCX_CUSTOM_GROUP_COLUMN_SELECTOR.CONFIGURE_ACTION_COLUMN.NO',
value: false,
},
]

constructor(private translate: TranslateService) {}

Expand All @@ -32,12 +62,26 @@ export class CustomGroupColumnSelectorComponent {
this.hiddenColumnsModel = this.columns.filter(
(column) => !this.displayedColumnsModel.map((c) => c.id).includes(column.id)
)
this.frozenActionColumnModel = this.frozenActionColumn
this.actionColumnPositionModel = this.actionColumnPosition
this.visible = true
}

onSaveClick() {
this.visible = false
this.columnSelectionChanged.emit({ activeColumns: [...this.displayedColumnsModel] })
const colIdsBefore = this.displayedColumns.map(column => column.id)
const colIdsAfter = this.displayedColumnsModel.map(column => column.id)

if(!colIdsAfter.every((colId, i) => colId === colIdsBefore[i])) {
this.columnSelectionChanged.emit({ activeColumns: [...this.displayedColumnsModel] })
}

if(this.frozenActionColumn != this.frozenActionColumnModel || this.actionColumnPosition != this.actionColumnPositionModel) {
this.actionColumnConfigChanged.emit({
frozenActionColumn: this.frozenActionColumnModel,
actionColumnPosition: this.actionColumnPositionModel,
})
}
}

onCancelClick() {
Expand Down
Loading

0 comments on commit 6cecae9

Please sign in to comment.