Skip to content

Commit 79cb92a

Browse files
JHoellitenthedominikriemer
authored
Add / Edit Assets during Dashboard Creation Edit (apache#3846)
Co-authored-by: Philipp Zehnder <tenthe@users.noreply.github.com> Co-authored-by: Dominik Riemer <dominik.riemer@gmail.com>
1 parent 9f3b9b9 commit 79cb92a

File tree

8 files changed

+333
-18
lines changed

8 files changed

+333
-18
lines changed

streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/dashboard/DataLakeDashboardResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ public ResponseEntity<Void> deleteDashboard(@PathVariable("dashboardId") String
104104

105105
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
106106
@PreAuthorize("this.hasWriteAuthority()")
107-
public ResponseEntity<Void> createDashboard(@RequestBody DashboardModel dashboardModel) {
108-
getResourceManager().create(dashboardModel, getAuthenticatedUserSid());
109-
return ok();
107+
public ResponseEntity<DashboardModel> createDashboard(@RequestBody DashboardModel dashboardModel) {
108+
var response = getResourceManager().create(dashboardModel, getAuthenticatedUserSid());
109+
return ok(response);
110110
}
111111

112+
112113
private DataExplorerResourceManager getResourceManager() {
113114
return getSpResourceManager().manageDataExplorer();
114115
}

ui/cypress/support/utils/dataExplorer/DataExplorerBtns.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class DataLakeBtns {
2727
return cy.dataCy('save-data-view-btn').click();
2828
}
2929

30+
public static saveDashboard() {
31+
return cy.dataCy('save-data-view').click();
32+
}
33+
3034
public static editDataViewButton(widgetName: string) {
3135
GeneralUtils.openMenuForRow(widgetName);
3236
return cy

ui/cypress/support/utils/dataExplorer/DataExplorerUtils.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,54 @@ export class DataExplorerUtils {
114114

115115
cy.wait(1000);
116116
}
117+
public static addAssetsToDashboard(assetNameList) {
118+
cy.dataCy('sp-show-dashboard-asset-checkbox')
119+
.find('input[type="checkbox"]')
120+
.then($checkbox => {
121+
if (!$checkbox.prop('checked')) {
122+
cy.wrap($checkbox).click();
123+
}
124+
});
117125

126+
cy.get('mat-tree.asset-tree', { timeout: 10000 }).should('exist');
127+
assetNameList.forEach(assetName => {
128+
console.log(assetName);
129+
cy.get('mat-tree.asset-tree')
130+
.find('.mat-tree-node')
131+
.contains(assetName)
132+
.click();
133+
});
134+
}
135+
136+
public static createDashboard(name) {
137+
// Create new data view
138+
cy.dataCy('open-new-dashboard-dialog').click();
139+
140+
// Configure data view
141+
cy.dataCy('data-view-name').type(name);
142+
}
143+
public static createDashboardWithLinkedAssets(
144+
dataView,
145+
name,
146+
assetNameList,
147+
) {
148+
DataExplorerUtils.goToDatalake();
149+
150+
DataExplorerUtils.addDataViewAndTableWidget(dataView, 'Persist');
151+
152+
DataExplorerUtils.saveDataViewConfiguration();
153+
154+
DataExplorerUtils.goToDashboard();
155+
156+
//ADD Assets
157+
DataExplorerUtils.createDashboard(name);
158+
DataExplorerUtils.addAssetsToDashboard(assetNameList);
159+
DataExplorerUtils.saveDashboard();
160+
}
161+
162+
public static saveDashboard() {
163+
return cy.dataCy('save-data-view').click();
164+
}
118165
public static addDataViewAndTableWidget(
119166
dataViewName: string,
120167
dataSet: string,
@@ -144,6 +191,11 @@ export class DataExplorerUtils {
144191
);
145192
}
146193

194+
public static renameDashboard(newName: string) {
195+
cy.dataCy('data-view-name').clear().type(newName);
196+
cy.dataCy('data-view-name').should('have.value', newName);
197+
}
198+
147199
public static loadRandomDataSetIntoDataLake() {
148200
PrepareTestDataUtils.loadDataIntoDataLake('fileTest/random.csv');
149201
}
@@ -186,6 +238,11 @@ export class DataExplorerUtils {
186238
cy.dataCy('edit-dashboard-' + dashboardName).click();
187239
}
188240

241+
public static editDashboardSettings(dashboardName: string) {
242+
GeneralUtils.openMenuForRow(dashboardName);
243+
cy.dataCy('edit-dashboard-settings-' + dashboardName).click();
244+
}
245+
189246
public static editDataView(dataViewName: string) {
190247
// Click edit button
191248
// following only works if single view is available
@@ -225,7 +282,9 @@ export class DataExplorerUtils {
225282
.contains(assetName)
226283
.click();
227284
});
285+
}
228286

287+
public static saveAssetLinkFromChart() {
229288
cy.dataCy('asset-dialog-confirm-delete', { timeout: 10000 }).click({
230289
force: true,
231290
});
@@ -606,5 +665,6 @@ export class DataExplorerUtils {
606665
//Save
607666
DataExplorerUtils.saveToAddAssets();
608667
DataExplorerUtils.addToAsset(assetNames);
668+
DataExplorerUtils.saveAssetLinkFromChart();
609669
}
610670
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
import { AssetBtns } from '../../support/utils/asset/AssetBtns';
19+
import { AssetUtils } from '../../support/utils/asset/AssetUtils';
20+
import { DataExplorerUtils } from '../../support/utils/dataExplorer/DataExplorerUtils';
21+
22+
describe('Test add Assets To Dashboard', () => {
23+
const assetName1 = 'TestAsset1';
24+
const assetName2 = 'TestAsset2';
25+
const assetName3 = 'TestAsset3';
26+
beforeEach('Setup Test', () => {
27+
cy.initStreamPipesTest();
28+
AssetUtils.goToAssets();
29+
AssetUtils.addAndSaveAsset(assetName3);
30+
AssetUtils.addAndSaveAsset(assetName2);
31+
AssetUtils.addAndSaveAsset(assetName1);
32+
DataExplorerUtils.loadDataIntoDataLake('datalake/sample.csv');
33+
});
34+
35+
it('Create Dashboard and add Assets', () => {
36+
const dataView = 'TestView';
37+
38+
const name = 'Dashboard1';
39+
40+
const assetNameList = [assetName1, assetName2];
41+
DataExplorerUtils.createDashboardWithLinkedAssets(
42+
dataView,
43+
name,
44+
assetNameList,
45+
);
46+
47+
//Go Back to Asset
48+
AssetUtils.goToAssets();
49+
AssetUtils.checkAmountOfAssetsGreaterThan(0);
50+
51+
AssetUtils.editAsset(assetName1);
52+
AssetBtns.assetLinksTab().click();
53+
54+
//Check if Link is there
55+
AssetUtils.checkAmountOfLinkedResources(1);
56+
});
57+
58+
it('Edit Dashboard and edit Asset Links', () => {
59+
const dataView = 'TestView';
60+
61+
const name = 'Dashboard1';
62+
63+
const assetNameList = [assetName1, assetName2];
64+
DataExplorerUtils.createDashboardWithLinkedAssets(
65+
dataView,
66+
name,
67+
assetNameList,
68+
);
69+
DataExplorerUtils.editDashboardSettings(name);
70+
DataExplorerUtils.renameDashboard('NEW');
71+
const assetNameList2 = [assetName2, assetName3];
72+
DataExplorerUtils.addToAsset(assetNameList2);
73+
DataExplorerUtils.saveDashboard();
74+
75+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName1, 1);
76+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName3, 1);
77+
78+
// Test Renaming
79+
AssetUtils.checkResourceNamingByAssetName(assetName1, 'NEW');
80+
});
81+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
import { AssetUtils } from '../../support/utils/asset/AssetUtils';
20+
import { DataExplorerUtils } from '../../support/utils/dataExplorer/DataExplorerUtils';
21+
22+
describe('Creates a new adapter with a linked asset', () => {
23+
const assetName1 = 'TestAsset1';
24+
const assetName2 = 'TestAsset2';
25+
const assetName3 = 'TestAsset3';
26+
27+
beforeEach('Setup Test', () => {
28+
cy.initStreamPipesTest();
29+
AssetUtils.goToAssets();
30+
AssetUtils.addAndSaveAsset(assetName3);
31+
AssetUtils.addAndSaveAsset(assetName2);
32+
AssetUtils.addAndSaveAsset(assetName1);
33+
});
34+
35+
it('Add Assets during Chart generation', () => {
36+
DataExplorerUtils.createDataViewWithAssets([assetName1, assetName2]);
37+
//Test
38+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName1, 1);
39+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName2, 1);
40+
});
41+
42+
it('Edit Assets during Chart generation', () => {
43+
DataExplorerUtils.createDataViewWithAssets([assetName1, assetName2]);
44+
//Test
45+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName1, 1);
46+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName2, 1);
47+
48+
// Go To Chart and Edit
49+
DataExplorerUtils.goToDatalake();
50+
DataExplorerUtils.editDataView('NewWidget');
51+
DataExplorerUtils.renameWidget('Rename');
52+
53+
DataExplorerUtils.saveToAddAssets();
54+
DataExplorerUtils.addToAsset([assetName1, assetName3]);
55+
DataExplorerUtils.saveAssetLinkFromChart();
56+
57+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName2, 1);
58+
AssetUtils.checkAmountOfLinkedResourcesByAssetName(assetName3, 1);
59+
AssetUtils.checkResourceNamingByAssetName(assetName2, 'Rename');
60+
});
61+
});

ui/src/app/dashboard/dialogs/edit-dashboard/edit-dashboard-dialog.component.html

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,47 @@
9797
}}
9898
</mat-checkbox>
9999
</div>
100+
101+
<div class="mt-10" fxLayout="column">
102+
<label>{{ 'Add Dashboard to Assets' | translate }}</label>
103+
104+
<mat-checkbox
105+
[(ngModel)]="addToAssets"
106+
color="accent"
107+
data-cy="sp-show-dashboard-asset-checkbox"
108+
>
109+
{{
110+
'Add the current dashboard to an existing asset'
111+
| translate
112+
}}
113+
</mat-checkbox>
114+
115+
@if (addToAssets) {
116+
<div class="mt-10">
117+
<sp-asset-link-configuration
118+
[isEdit]="!createMode"
119+
[itemId]="dashboard.elementId"
120+
(selectedAssetsChange)="
121+
onSelectedAssetsChange($event)
122+
"
123+
(deselectedAssetsChange)="
124+
onDeselectedAssetsChange($event)
125+
"
126+
(originalAssetsEmitter)="
127+
onOriginalAssetsEmitted($event)
128+
"
129+
>
130+
</sp-asset-link-configuration>
131+
</div>
132+
}
133+
</div>
134+
100135
<!--<mat-checkbox [(ngModel)]="dashboard.displayHeader">Show name and description in dashboard</mat-checkbox>-->
101136
</div>
102137
</div>
103138
</div>
104139
<mat-divider></mat-divider>
105-
<div class="sp-dialog-actions actions-align-right">
106-
<button
107-
mat-button
108-
mat-flat-button
109-
class="mat-basic mr-10"
110-
(click)="onCancel()"
111-
>
112-
{{ 'Close' | translate }}
113-
</button>
140+
<div class="sp-dialog-actions actions-align-left">
114141
<button
115142
[disabled]="dvname.invalid"
116143
mat-button
@@ -121,5 +148,13 @@
121148
>
122149
{{ (createMode ? 'Create' : 'Save') | translate }}
123150
</button>
151+
<button
152+
mat-button
153+
mat-flat-button
154+
class="mat-basic mr-10"
155+
(click)="onCancel()"
156+
>
157+
{{ 'Close' | translate }}
158+
</button>
124159
</div>
125160
</div>

0 commit comments

Comments
 (0)