Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarrrr committed Nov 14, 2023
2 parents bc435cf + 4a9645e commit f34d3d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- Adjust background color of OuiToolTip in `next` theme ([#1004](https://github.com/opensearch-project/oui/pull/1004))
- Add new `middle-out` order prop option to `OuiPaletteColorBlind` ([#856](https://github.com/opensearch-project/oui/pull/856))
- Add new icons for OpenSearch Dashboards v2.10.0 ([#1014](https://github.com/opensearch-project/oui/pull/1014))
- Add `onFullScreenChange` to `OuiDataGrid` ([#1053](https://github.com/opensearch-project/oui/pull/1053))

### 🐛 Bug Fixes

Expand Down
5 changes: 5 additions & 0 deletions src-docs/src/views/datagrid/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ export default () => {
console.log(eventData);
});

const onFullScreenChange = useRef((eventData) => {
console.log('isFullScreen:', eventData);
});

return (
<DataContext.Provider value={raw_data}>
<OuiDataGrid
Expand All @@ -330,6 +334,7 @@ export default () => {
onChangePage: onChangePage,
}}
onColumnResize={onColumnResize.current}
onFullScreenChange={onFullScreenChange.current}
/>
</DataContext.Provider>
);
Expand Down
20 changes: 17 additions & 3 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ type CommonGridProps = CommonProps &
* A callback for when a column's size changes. Callback receives `{ columnId: string, width: number }`.
*/
onColumnResize?: OuiDataGridOnColumnResizeHandler;
/**
* A callback fired when the internal full screen state changes.
*/
onFullScreenChange?: (isFullScreen: boolean) => void;
/**
* Defines a minimum width for the grid to show all controls in its header.
*/
Expand Down Expand Up @@ -690,6 +694,7 @@ function notifyCellOfFocusState(
}

const emptyArrayDefault: OuiDataGridControlColumn[] = [];

export const OuiDataGrid: FunctionComponent<OuiDataGridProps> = (props) => {
const {
leadingControlColumns = emptyArrayDefault,
Expand All @@ -708,14 +713,15 @@ export const OuiDataGrid: FunctionComponent<OuiDataGridProps> = (props) => {
inMemory,
popoverContents,
onColumnResize,
onFullScreenChange,
minSizeForControls = MINIMUM_WIDTH_FOR_GRID_CONTROLS,
height,
width,
rowHeightsOptions,
...rest
} = props;

const [isFullScreen, setIsFullScreen] = useState(false);
const [isFullScreen, setFullScreen] = useState(false);
const [gridWidth, setGridWidth] = useState(0);

const [interactiveCellId] = useState(htmlIdGenerator()());
Expand Down Expand Up @@ -756,6 +762,14 @@ export const OuiDataGrid: FunctionComponent<OuiDataGridProps> = (props) => {
[headerIsInteractive, setHeaderIsInteractive, setFocusedCell]
);

const handleFullScreenChange = useCallback(
(isFullScreen: boolean) => {
setFullScreen(isFullScreen);
onFullScreenChange?.(isFullScreen);
},
[onFullScreenChange]
);

const handleHeaderMutation = useCallback<MutationCallback>(
(records) => {
const [{ target }] = records;
Expand All @@ -781,7 +795,7 @@ export const OuiDataGrid: FunctionComponent<OuiDataGridProps> = (props) => {
case keys.ESCAPE:
if (isFullScreen) {
event.preventDefault();
setIsFullScreen(false);
handleFullScreenChange(false);
}
break;
}
Expand Down Expand Up @@ -1000,7 +1014,7 @@ export const OuiDataGrid: FunctionComponent<OuiDataGridProps> = (props) => {
color="text"
className={controlBtnClasses}
data-test-subj="dataGridFullScrenButton"
onClick={() => setIsFullScreen(!isFullScreen)}>
onClick={() => handleFullScreenChange(!isFullScreen)}>
{isFullScreen ? fullScreenButtonActive : fullScreenButton}
</OuiButtonEmpty>
)}
Expand Down

0 comments on commit f34d3d6

Please sign in to comment.