This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create grid action that allows users of the table component add grid actions. It allows Octant to take advantage of https://clarity.design/documentation/datagrid/single-action Signed-off-by: bryanl <bryanliles@gmail.com>
- Loading branch information
Showing
9 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2020 the Octant contributors. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package component | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/vmware-tanzu/octant/pkg/action" | ||
) | ||
|
||
type GridAction struct { | ||
// Name is the name of action. It will be shown to the user. | ||
Name string `json:"name"` | ||
// ActionPath is the path of the action. | ||
ActionPath string `json:"actionPath"` | ||
// Payload is the payload that will be submitted with the action is invoked. | ||
Payload action.Payload `json:"payload"` | ||
} | ||
|
||
// GridActions add the ability to have specific actions for rows. This will allow for dynamic injection of actions | ||
// that could be dependent on the content of a grid row. | ||
type GridActions struct { | ||
base | ||
|
||
Config GridActionsConfig `json:"config"` | ||
} | ||
|
||
var _ Component = &GridActions{} | ||
|
||
// NewGridActions creates an instance of GridActions. | ||
func NewGridActions() *GridActions { | ||
a := GridActions{ | ||
base: newBase(typeGridActions, nil), | ||
} | ||
|
||
return &a | ||
} | ||
|
||
// AddAction adds an action to GridAction. | ||
func (a *GridActions) AddAction(name, actionPath string, payload action.Payload) { | ||
ga := GridAction{ | ||
Name: name, | ||
ActionPath: actionPath, | ||
Payload: payload, | ||
} | ||
|
||
a.Config.Actions = append(a.Config.Actions, ga) | ||
} | ||
|
||
type gridActionsMarshal GridActions | ||
|
||
// MarshalJSON converts the GridActions to a JSON. | ||
func (a GridActions) MarshalJSON() ([]byte, error) { | ||
m := gridActionsMarshal{ | ||
base: a.base, | ||
Config: a.Config, | ||
} | ||
|
||
m.Metadata.Type = typeGridActions | ||
return json.Marshal(&m) | ||
} | ||
|
||
// GridActionsConfig is configuration items for GridActions. | ||
type GridActionsConfig struct { | ||
// Actions is a slice that contains actions that can be performed by the user. | ||
Actions []GridAction `json:"actions"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2020 the Octant contributors. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package component | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/vmware-tanzu/octant/pkg/action" | ||
) | ||
|
||
func TestGridActions_AddAction(t *testing.T) { | ||
ga := NewGridActions() | ||
|
||
payload := action.Payload{"foo": "bar"} | ||
ga.AddAction("name", "/path", payload) | ||
|
||
expected := []GridAction{ | ||
{ | ||
Name: "name", | ||
ActionPath: "/path", | ||
Payload: payload, | ||
}, | ||
} | ||
require.Equal(t, expected, ga.Config.Actions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"actions": [ | ||
{ | ||
"name": "name", | ||
"actionPath": "/path", | ||
"payload": { | ||
"foo": "bar" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters