-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExampleGridPanel.tsx
More file actions
62 lines (54 loc) · 2.24 KB
/
ExampleGridPanel.tsx
File metadata and controls
62 lines (54 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) 2023-2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
import React, { PureComponent } from 'react';
import { GridPanel, InjectedQueryModels, withQueryModels } from '@labkey/components';
// First define the properties of the component you're going to wrap with withQueryModels.
interface OwnProps {
title: string;
asPanel: boolean;
}
// Here we create a type that includes InjectedQueryModels because
// we're wrapping the component with withQueryModels which will inject
// queryModels and actions objects.
type Props = OwnProps & InjectedQueryModels;
// Here we use the name ExampleGridPanelImpl, users will not use this
// component directly, only the wrapped version below which we expose
// to users as ExampleGridPanel.
class ExampleGridPanelImpl extends PureComponent<Props> {
onRefreshGrid = () => {
const { queryModels, actions } = this.props;
const { containersModel } = queryModels;
actions.loadModel(containersModel.id);
};
// This is an example of a custom button bar element in your GridPanel that can interact with the QueryModel.
renderGridButtons = () => {
return (
<button className={'labkey-button'} onClick={this.onRefreshGrid}>
Refresh Grid
</button>
)
};
render() {
// Note that queryModels and actions come from InjectedQueryModels via withQueryModels
const { queryModels, actions, title, asPanel } = this.props;
const { containersModel } = queryModels;
return (
<GridPanel
model={containersModel}
ButtonsComponent={this.renderGridButtons}
actions={actions}
title={title}
asPanel={asPanel}
hideEmptyViewMenu={true}
/>
);
}
}
// Next wrap your component with withQueryModels, here we set the type
// to OwnProps so the returned component, ExampleGridPanel, can
// be used in a type-safe manner. In this case, if the user forgets to
// pass in a title or the asPanel property, we'll get a compiler error as intended.
export const ExampleGridPanel = withQueryModels<OwnProps>(ExampleGridPanelImpl);