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

Update group expand and collapse behavior #161

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
302 changes: 299 additions & 3 deletions provisioning/dashboards/panels.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 4,
"id": 3,
"links": [],
"panels": [
{
Expand Down Expand Up @@ -1817,6 +1817,9 @@
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
Expand All @@ -1835,18 +1838,311 @@
"overrides": []
},
"gridPos": {
"h": 8,
"h": 10,
"w": 24,
"x": 0,
"y": 49
},
"id": 14,
"options": {
"nestedObjects": [],
"tables": [
{
"expanded": true,
"items": [
{
"aggregation": "none",
"appearance": {
"alignment": "start",
"background": {
"applyToRow": false
},
"colors": {},
"header": {
"fontSize": "md"
},
"width": {
"auto": true,
"min": 20,
"value": 100
},
"wrap": true
},
"edit": {
"editor": {
"type": "string"
},
"enabled": false,
"permission": {
"mode": "",
"userRole": []
}
},
"enabled": true,
"field": {
"name": "labels",
"source": "A"
},
"filter": {
"enabled": false,
"mode": "client",
"variable": ""
},
"footer": [],
"group": true,
"label": "",
"objectId": "",
"pin": "",
"sort": {
"descFirst": false,
"enabled": false
},
"type": "auto"
},
{
"aggregation": "none",
"appearance": {
"alignment": "start",
"background": {
"applyToRow": false
},
"colors": {},
"header": {
"fontSize": "md"
},
"width": {
"auto": true,
"min": 20,
"value": 100
},
"wrap": true
},
"edit": {
"editor": {
"type": "string"
},
"enabled": false,
"permission": {
"mode": "",
"userRole": []
}
},
"enabled": true,
"field": {
"name": "title",
"source": "A"
},
"filter": {
"enabled": false,
"mode": "client",
"variable": ""
},
"footer": [],
"group": false,
"label": "",
"objectId": "",
"pin": "",
"sort": {
"descFirst": false,
"enabled": false
},
"type": "auto"
},
{
"aggregation": "none",
"appearance": {
"alignment": "start",
"background": {
"applyToRow": false
},
"colors": {},
"header": {
"fontSize": "md"
},
"width": {
"auto": true,
"min": 20,
"value": 100
},
"wrap": true
},
"edit": {
"editor": {
"type": "string"
},
"enabled": false,
"permission": {
"mode": "",
"userRole": []
}
},
"enabled": true,
"field": {
"name": "start_date",
"source": "A"
},
"filter": {
"enabled": false,
"mode": "client",
"variable": ""
},
"footer": [],
"group": false,
"label": "",
"objectId": "",
"pin": "",
"sort": {
"descFirst": false,
"enabled": false
},
"type": "auto"
},
{
"aggregation": "none",
"appearance": {
"alignment": "start",
"background": {
"applyToRow": false
},
"colors": {},
"header": {
"fontSize": "md"
},
"width": {
"auto": true,
"min": 20,
"value": 100
},
"wrap": true
},
"edit": {
"editor": {
"type": "string"
},
"enabled": false,
"permission": {
"mode": "",
"userRole": []
}
},
"enabled": true,
"field": {
"name": "description",
"source": "A"
},
"filter": {
"enabled": false,
"mode": "client",
"variable": ""
},
"footer": [],
"group": false,
"label": "",
"objectId": "",
"pin": "",
"sort": {
"descFirst": false,
"enabled": false
},
"type": "rich_text"
}
],
"name": "Test",
"pagination": {
"enabled": false,
"mode": "client"
},
"update": {
"datasource": "",
"payload": {}
}
}
],
"tabsSorting": false,
"toolbar": {
"export": false
}
},
"targets": [
{
"frame": {
"fields": [
{
"config": {},
"name": "labels",
"type": "string",
"values": []
},
{
"config": {},
"name": "title",
"type": "string",
"values": []
},
{
"config": {},
"name": "start_date",
"type": "string",
"values": []
},
{
"config": {},
"name": "description",
"type": "string",
"values": []
}
],
"meta": {
"custom": {
"customCode": "const createArray = (length, fillCell) => new Array(length).fill(fillCell)\n\nconst result = {\n ...frame,\n fields: frame.fields.map((field) => {\n if (field.name === 'labels') {\n return ({\n ...field,\n values: [createArray(4, 'Grafana 11.4'), createArray(4, 'Grafana 11.3'), createArray(4, 'Grafana 11.2'), createArray(4, 'Grafana 11.0'), createArray(4, 'Grafana 10.4'), createArray(4, 'Grafana 10.3'), createArray(4, 'Grafana 10.2'), createArray(4, 'Grafana 10.1'), createArray(4, 'Grafana 10.0')].flat()\n })\n }\n if (field.name === 'title') {\n return ({\n ...field,\n values: createArray(36, 'Title').map((item, index) => `${item} - ${index}`)\n })\n }\n if (field.name === 'start_date') {\n return ({\n ...field,\n values: createArray(36, '20-10-2024 10:00:30')\n })\n }\n if (field.name === 'description') {\n return ({\n ...field,\n values: createArray(36, '<h3>Features/ 1</h3> - Updated behavior <br/> - Added All options<br/> - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br/> - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.')\n })\n }\n return ({\n ...field,\n values: []\n })\n })\n}\n\nreturn Promise.resolve(result);",
"valuesEditor": "custom"
}
}
},
"refId": "A"
}
],
"title": "Expanded rows - auto",
"type": "volkovlabs-table-panel"
},
{
"datasource": {
"type": "marcusolsson-static-datasource",
"uid": "P1D2C73DC01F2359B"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 59
},
"id": 8,
"options": {
"columnMode": "auto",
"columns": [],
"nestedObjects": [],
"tables": [
{
"expanded": false,
"items": [
{
"aggregation": "none",
Expand Down Expand Up @@ -2047,6 +2343,6 @@
"timezone": "",
"title": "Panels",
"uid": "O4tc_E6Gz",
"version": 1,
"version": 15,
"weekStart": ""
}
13 changes: 12 additions & 1 deletion src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,18 @@ interface Props<TData> {

/**
* Table Instance
*
* @type {MutableRefObject<TableInstance<TData>>}
*/
tableInstance: MutableRefObject<TableInstance<TData>>;

/**
* Expanded By default
*
* @type {boolean}
*/
expandedByDefault: boolean;

/**
* Show Header
*
Expand Down Expand Up @@ -192,6 +201,7 @@ export const Table = <TData,>({
width,
pagination,
tableInstance,
expandedByDefault,
showHeader,
}: Props<TData>) => {
/**
Expand Down Expand Up @@ -229,7 +239,7 @@ export const Table = <TData,>({
/**
* Expanded
*/
const [expanded, setExpanded] = useState<ExpandedState>({});
const [expanded, setExpanded] = useState<ExpandedState>(expandedByDefault ? true : {});

/**
* Filtering
Expand Down Expand Up @@ -269,6 +279,7 @@ export const Table = <TData,>({
enableExpanding: true,
enableGrouping: true,
onExpandedChange: setExpanded,
autoResetExpanded: false,

/**
* Filtering
Expand Down
1 change: 1 addition & 0 deletions src/components/TablePanel/TablePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export const TablePanel: React.FC<Props> = ({
)}
<Table
key={currentTable?.name}
expandedByDefault={currentTable?.expanded ?? false}
data={tableData}
columns={columns}
tableRef={tableRef}
Expand Down
1 change: 1 addition & 0 deletions src/components/editors/TablesEditor/TablesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const TablesEditor: React.FC<Props> = ({ context: { options, data }, onCh
onChangeItems(
items.concat([
{
expanded: false,
name: newItemName,
showHeader: true,
items: [],
Expand Down
Loading
Loading