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

Restore support for non-composite data view ids #979

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions internal/kibana/data_view/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,16 @@ func convertSourceFilter(item string, meta utils.ListMeta) kbapi.DataViewsSource
}

func (model dataViewModel) getViewIDAndSpaceID() (viewID string, spaceID string) {
viewID = model.ID.ValueString()
spaceID = model.SpaceID.ValueString()

resourceID := model.ID.ValueString()
composite, _ := clients.CompositeIdFromStr(resourceID)
viewID = composite.ResourceId
spaceID = composite.ClusterId
maybeCompositeID, _ := clients.CompositeIdFromStr(resourceID)
if maybeCompositeID != nil {
viewID = maybeCompositeID.ResourceId
spaceID = maybeCompositeID.ClusterId
}

return
}

Expand Down
35 changes: 35 additions & 0 deletions internal/kibana/data_view/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,38 @@ func TestToAPIUpdateModel(t *testing.T) {
})
}
}

func Test_dataViewModel_getViewIDAndSpaceID(t *testing.T) {
tests := []struct {
name string
model dataViewModel
expectedViewID string
expectedSpaceID string
}{
{
name: "gets the view and space id from the composite id if set",
model: dataViewModel{
ID: types.StringValue("space-id/view-id"),
},
expectedViewID: "view-id",
expectedSpaceID: "space-id",
},
{
name: "gets the view and space id from the data view if id is not a valid composite id",
model: dataViewModel{
ID: types.StringValue("view-id"),
SpaceID: types.StringValue("space-id"),
},
expectedViewID: "view-id",
expectedSpaceID: "space-id",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viewID, spaceID := tt.model.getViewIDAndSpaceID()
require.Equal(t, tt.expectedViewID, viewID)
require.Equal(t, tt.expectedSpaceID, spaceID)
})
}
}
Loading