Skip to content
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

Rest grid model menu actions type #3392

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions desktop/cmp/record/RecordActionBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

import {Column, GridModel} from '@xh/hoist/cmp/grid';
import {hoistCmp} from '@xh/hoist/core';
import {RecordActionSpec, RecordAction, StoreRecord, StoreSelectionModel} from '@xh/hoist/data';
import {buttonGroup, ButtonGroupProps} from '@xh/hoist/desktop/cmp/button';
import {RecordAction, RecordActionLike, StoreRecord, StoreSelectionModel} from '@xh/hoist/data';
import {toolbarSep} from '@xh/hoist/desktop/cmp/toolbar';
import {button, buttonGroup, ButtonGroupProps} from '@xh/hoist/desktop/cmp/button';
import '@xh/hoist/desktop/register';
import {throwIf} from '@xh/hoist/utils/js';
import {isEmpty} from 'lodash';
import {recordActionButton, RecordActionButtonProps} from './impl/RecordActionButton';

export interface RecordActionBarProps extends ButtonGroupProps {
/** Actions to include. */
actions: Array<RecordActionSpec | RecordAction>;
actions: Array<RecordActionLike>;

/** The StoreRecord to associate with the actions. Required if selModel is omitted. */
record?: StoreRecord;
Expand Down Expand Up @@ -65,14 +66,17 @@ export const [RecordActionBar, recordActionBar] = hoistCmp.withFactory<RecordAct
return buttonGroup({
vertical,
items: actions.filter(Boolean).map(action =>
recordActionButton({
action: action instanceof RecordAction ? action : new RecordAction(action),
record,
selModel,
gridModel,
column,
...buttonProps
})
action !== '-'
? recordActionButton({
action:
action instanceof RecordAction ? action : new RecordAction(action),
record,
selModel,
gridModel,
column,
...buttonProps
})
: button({text: toolbarSep(), disabled: true})
),
...rest
});
Expand Down
14 changes: 7 additions & 7 deletions desktop/cmp/rest/RestGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {BaseFieldConfig} from '@xh/hoist/cmp/form';
import {GridConfig, GridModel} from '@xh/hoist/cmp/grid';
import {HoistModel, managed, PlainObject, ElementSpec, XH} from '@xh/hoist/core';
import '@xh/hoist/desktop/register';
import {RecordAction, RecordActionSpec, StoreRecord} from '@xh/hoist/data';
import {RecordActionLike, StoreRecord} from '@xh/hoist/data';
import {Icon} from '@xh/hoist/icon/Icon';
import {pluralize, throwIf, withDefault} from '@xh/hoist/utils/js';
import {isFunction} from 'lodash';
Expand All @@ -27,13 +27,13 @@ export interface RestGridConfig extends GridConfig {
readonly?: boolean;

/** Actions to display in the toolbar. Defaults to add, edit, delete. */
toolbarActions?: Array<RecordAction | RecordActionSpec>;
toolbarActions?: Array<RecordActionLike>;

/** actions to display in the grid context menu. Defaults to add, edit, delete. */
menuActions?: Array<RecordAction | RecordActionSpec>;
menuActions?: Array<RecordActionLike>;

/** Actions to display in the form toolbar. Defaults to delete. */
formActions?: Array<RecordAction | RecordActionSpec>;
formActions?: Array<RecordActionLike>;

/** Warning to display before actions on a selection of records. */
actionWarning?: {
Expand Down Expand Up @@ -89,9 +89,9 @@ export class RestGridModel extends HoistModel {
//----------------
readonly: boolean;
editors: RestGridEditor[];
toolbarActions: Array<RecordAction | RecordActionSpec>;
menuActions: Array<RecordAction | RecordActionSpec>;
formActions: Array<RecordAction | RecordActionSpec>;
toolbarActions: Array<RecordActionLike>;
menuActions: Array<RecordActionLike>;
formActions: Array<RecordActionLike>;
prepareCloneFn: (input: {record: StoreRecord; clone: PlainObject}) => void;
unit: string;
filterFields: string[] = null;
Expand Down