Skip to content

Commit 04d83a8

Browse files
Merge pull request #129 from microsoft/feature
1. Added functionality to plug in custom command bar items
2 parents 4872a72 + baa574f commit 04d83a8

8 files changed

Lines changed: 51371 additions & 18347 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ This starts the project on port 3000 and you are ready to play around with the E
307307
enableBulkEdit={true}
308308
enableColumnEdit={true}
309309
enableSave={true}
310+
customCommandBarItems={[
311+
{
312+
key: "CustomCommandBarItem1",
313+
name: "Custom Command Bar Item1",
314+
iconProps: { iconName: "Download" },
315+
onClick: () => {
316+
alert('Clicked');
317+
},
318+
}
319+
]}
310320
/>
311321
</Fabric>
312322
);

package-lock.json

Lines changed: 51323 additions & 18341 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"office-ui-fabric-react": "^7.0.0",
3939
"react": "^17.0.2",
4040
"react-dom": "^17.0.2",
41-
"react-scripts": "^4.0.3",
41+
"react-scripts": "5.0.0",
4242
"react-toastify": "^7.0.4",
4343
"typescript": "^4.3.5",
4444
"web-vitals": "^1.1.2",
@@ -47,12 +47,12 @@
4747
"y18n": "^3.2.2"
4848
},
4949
"devDependencies": {
50+
"immer": ">=9.0.6",
5051
"just-scripts": "^0.27.0",
5152
"just-stack-react": "^1.0.0",
52-
"immer": ">=9.0.6",
53-
"tar": ">=6.1.9",
5453
"marked": ">=4.0.10",
55-
"nth-check": ">=2.0.1"
54+
"nth-check": ">=2.0.1",
55+
"tar": ">=6.1.9"
5656
},
5757
"scripts": {
5858
"start": "react-scripts start",

src/Examples/gridconsumer/gridconsumer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ const Consumer = () => {
345345
}}
346346
onGridUpdate={onGridUpdate}
347347
enableDefaultEditMode={gridConfigOptions.enableDefaultEditMode}
348+
customCommandBarItems={[
349+
{
350+
key: "CustomCommandBarItem1",
351+
name: "Custom Command Bar Item1",
352+
iconProps: { iconName: "Download" },
353+
onClick: () => {
354+
alert('Clicked');
355+
},
356+
}
357+
]}
348358
/>
349359

350360
{teachingBubbleVisible && (

src/libs/editablegrid/editablegrid.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,10 @@ const EditableGrid = (props: Props) => {
15531553
onClick: () => ResetGridData()
15541554
});
15551555
}
1556+
1557+
if(props.customCommandBarItems && props.customCommandBarItems.length > 0){
1558+
return [...commandBarItems, ...props.customCommandBarItems];
1559+
}
15561560

15571561
return commandBarItems;
15581562
};
@@ -1593,9 +1597,18 @@ const EditableGrid = (props: Props) => {
15931597
return commandBarItems;
15941598
};
15951599

1600+
const CreateCommandBarOverflowItemsProps = () : ICommandBarItemProps[] => {
1601+
if(props.customCommandBarOverflowItems && props.customCommandBarOverflowItems.length > 0){
1602+
return [...props.customCommandBarOverflowItems];
1603+
};
1604+
1605+
return [];
1606+
};
1607+
15961608
const GridColumns = CreateColumnConfigs();
15971609
const CommandBarItemProps = CreateCommandBarItemProps();
15981610
const CommandBarFarItemProps = CreateCommandBarFarItemProps();
1611+
const CommandBarOverflowItemsProps = CreateCommandBarOverflowItemsProps();
15991612
function _getSelectionDetails() : string {
16001613
const count = _selection.getSelectedCount();
16011614
setSelectionCount(count);
@@ -1777,6 +1790,7 @@ const EditableGrid = (props: Props) => {
17771790
{props.enableCommandBar === undefined || props.enableCommandBar === true ? <CommandBar
17781791
items={CommandBarItemProps}
17791792
ariaLabel="Command Bar"
1793+
overflowItems={CommandBarOverflowItemsProps}
17801794
farItems={CommandBarFarItemProps}
17811795
/> : null}
17821796
{showSpinner ?

src/libs/editablegrid/gridexportutil.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import { ExportType } from "../types/exporttype";
55
import * as XLSX from 'xlsx';
66
import * as FileSaver from 'file-saver';
7+
declare global {
8+
interface Navigator {
9+
msSaveBlob?: (blob: any, defaultName?: string) => boolean
10+
}
11+
}
712

813
export const ExportToExcelUtil = (exportData : any[], fileName : string): void =>
914
{

src/libs/editablegrid/searchabledropdown/searchabledropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ const SearchableDropdown = (props: Props) => {
1616
const [placeholder, setPlaceHolder] = React.useState<string>();
1717

1818
useEffect(() => {
19-
setDropdownOptions(props.options);
19+
setDropdownOptions(props.options as IDropdownOption[]);
2020
setPlaceHolder(props.placeholder);
2121
}, [props.options]);
2222

2323
const onFilterTextUpdate = (ev: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, searchText: string | undefined): void => {
24-
var dropdownOptionsTmp : IDropdownOption[] = [...props.options.filter(x => x.itemType != DropdownMenuItemType.Header)];
24+
var dropdownOptionsTmp : IDropdownOption[] = [...(props.options as IDropdownOption[]).filter(x => x.itemType != DropdownMenuItemType.Header)];
2525
var matches : IDropdownOption[] = dropdownOptionsTmp.filter(x => x.text.toLowerCase().indexOf(searchText?.toLowerCase() ?? '') > -1);
2626
setPlaceHolder(`[${matches.length.toString()} match${matches.length != 1 ? 'es' : ''} found]`);
2727
setDropdownOptions(matches);

src/libs/types/editabledetailslistprops.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ICommandBarItemProps } from "office-ui-fabric-react/lib/CommandBar";
12
import { ConstrainMode } from "office-ui-fabric-react/lib/components/DetailsList";
23
import { IDetailsListProps } from "office-ui-fabric-react/lib/components/DetailsList/DetailsList";
34
import { IColumnConfig } from "./columnconfigtype";
@@ -40,4 +41,6 @@ export interface Props extends IDetailsListProps {
4041
onGridStatusMessageCallback?: any;
4142
gridCopyOptions?: IGridCopy;
4243
enableDefaultEditMode?: boolean;
44+
customCommandBarItems?: ICommandBarItemProps[];
45+
customCommandBarOverflowItems?: ICommandBarItemProps[];
4346
}

0 commit comments

Comments
 (0)