Skip to content

Commit 1b761c3

Browse files
RelloAndyScherzinger
authored andcommitted
fix: resolve test feedbacks
Signed-off-by: Rello <github@scherello.de>
1 parent 686e041 commit 1b761c3

4 files changed

Lines changed: 146 additions & 3 deletions

File tree

‎lib/Service/ViewService.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,24 @@ public function deleteColumnDataFromViews(int $columnId, Table $table): void {
609609
columnSettings: new ColumnSettings($applicableViewColumnInformationRecords),
610610
filterSet: FilterSet::createFromInputArray($applicableFilterArray),
611611
sortRuleSet: SortRuleSet::createFromInputArray($filteredSortingRules),
612+
viewSettings: $this->removeColumnFromViewSettings($view->getViewSettingsObject(), $columnId),
612613
);
613614

614615
$this->update($view->getId(), $viewUpdateInput);
615616
}
616617
}
617618

619+
private function removeColumnFromViewSettings(ViewSettings $viewSettings, int $columnId): ViewSettings {
620+
return new ViewSettings(
621+
cardBackgroundSource: $viewSettings->getCardBackgroundSource() === $columnId
622+
? null
623+
: $viewSettings->getCardBackgroundSource(),
624+
cardTitleSource: $viewSettings->getCardTitleSource() === $columnId
625+
? null
626+
: $viewSettings->getCardTitleSource(),
627+
);
628+
}
629+
618630
protected function removeColumnFromFilters(array $originalFilterSetArray, int $columnId): array {
619631
$applicableFilterSetArray = [];
620632
foreach ($originalFilterSetArray as $filterGroupArray) {

‎lib/UserMigration/TablesMigrator.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,35 @@ private function importViews(IImportSource $importSource, array $tableIdMap, arr
356356
}
357357
unset($setting);
358358
}
359+
$view = $this->remapViewCardSources($view, $columnIdMap);
359360
$this->viewService->importView($newTableId, $view, $userId);
360361
}
361362
}
362363
}
363364

365+
private function remapViewCardSources(array $view, array $columnIdMap): array {
366+
if (isset($view['viewSettings']) && is_array($view['viewSettings'])) {
367+
foreach (['cardBackgroundSource', 'cardTitleSource'] as $sourceKey) {
368+
$view['viewSettings'] = $this->remapViewCardSource($view['viewSettings'], $sourceKey, $columnIdMap);
369+
}
370+
return $view;
371+
}
372+
373+
foreach (['cardBackgroundSource', 'cardTitleSource'] as $sourceKey) {
374+
$view = $this->remapViewCardSource($view, $sourceKey, $columnIdMap);
375+
}
376+
377+
return $view;
378+
}
379+
380+
private function remapViewCardSource(array $data, string $sourceKey, array $columnIdMap): array {
381+
if (isset($data[$sourceKey]) && isset($columnIdMap[$data[$sourceKey]])) {
382+
$data[$sourceKey] = $columnIdMap[$data[$sourceKey]];
383+
}
384+
385+
return $data;
386+
}
387+
364388
/**
365389
* @param IImportSource $importSource
366390
* @param Table $newTable

‎src/pages/Context.vue‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
<div v-for="resource in contextResources" :key="resource.key">
2424
<div v-if="!resource.isView" class="resource">
2525
<TableWrapper :table="resource" :columns="columns[resource.key]" :rows="rows[resource.key]"
26-
:view-setting="viewSetting" @create-column="createColumn(false, resource)"
26+
:view-setting.sync="resourceViewSettings[resource.key]" @create-column="createColumn(false, resource)"
2727
@import-scheme="openImportSchemeModal(resource)"
2828
@import="openImportModal(resource, false)" @download-csv="downloadCSV(resource, false)"
2929
@download-filtered-csv="rows => downloadFilteredCSV(rows, resource, false)" />
3030
</div>
3131
<div v-else-if="resource.isView" class="resource">
3232
<CustomView :view="resource" :columns="columns[resource.key]" :rows="rows[resource.key]"
33-
:view-setting="viewSetting" @create-column="createColumn(true, resource)"
33+
:view-setting.sync="resourceViewSettings[resource.key]" @create-column="createColumn(true, resource)"
3434
@import="openImportModal(resource, true)" @download-csv="downloadCSV(resource, true)"
3535
@download-filtered-csv="rows => downloadFilteredCSV(rows, resource, true)" />
3636
</div>
@@ -80,7 +80,7 @@ export default {
8080
return {
8181
loading: true,
8282
icon: null,
83-
viewSetting: {},
83+
resourceViewSettings: {},
8484
context: null,
8585
contextResources: [],
8686
errorMessage: null,
@@ -175,6 +175,7 @@ export default {
175175
this.isReloading = true
176176
this.loading = true
177177
this.contextResources = []
178+
this.resourceViewSettings = {}
178179
179180
try {
180181
await this.loadContext({ id: this.activeContextId })
@@ -220,6 +221,7 @@ export default {
220221
})
221222
table.key = (table.id).toString()
222223
table.isView = false
224+
this.$set(this.resourceViewSettings, table.key, this.createViewSetting(false, table))
223225
this.contextResources.push(table)
224226
}
225227
@@ -236,6 +238,7 @@ export default {
236238
})
237239
view.key = 'view-' + (view.id).toString()
238240
view.isView = true
241+
this.$set(this.resourceViewSettings, view.key, this.createViewSetting(true, view))
239242
this.contextResources.push(view)
240243
}
241244
}
@@ -265,6 +268,24 @@ export default {
265268
createColumn(isView, element) {
266269
emit('tables:column:create', { isView, element })
267270
},
271+
createViewSetting(isView, element) {
272+
const viewSetting = {
273+
layout: isView ? (element?.layout ?? 'table') : 'table',
274+
}
275+
276+
if (isView) {
277+
viewSetting.viewSettings = {
278+
cardBackgroundSource: element?.viewSettings?.cardBackgroundSource ?? null,
279+
cardTitleSource: element?.viewSettings?.cardTitleSource ?? null,
280+
}
281+
}
282+
283+
if (element?.sort?.length) {
284+
viewSetting.presetSorting = [...element.sort]
285+
}
286+
287+
return viewSetting
288+
},
268289
async downloadCSV(element, isView) {
269290
const access = await this.validateExportAccess({
270291
id: element.id,

‎tests/unit/TablesMigratorTest.php‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,90 @@ public function rollBack(): void {
286286
$newTable->getSort()
287287
);
288288
}
289+
290+
public function testImportRemapsViewCardSources(): void {
291+
$user = $this->createMock(IUser::class);
292+
$importSource = $this->createMock(IImportSource::class);
293+
$output = new NullOutput();
294+
295+
$user->method('getUID')->willReturn('user1');
296+
$importSource->method('getMigratorVersion')->willReturn(1);
297+
298+
$tableData = [
299+
'id' => 1,
300+
'title' => 'Test',
301+
];
302+
$columns = [
303+
['id' => 10, 'tableId' => 1],
304+
['id' => 11, 'tableId' => 1],
305+
];
306+
$views = [
307+
[
308+
'tableId' => 1,
309+
'title' => 'Nested settings',
310+
'columnSettings' => [['columnId' => 10, 'order' => 0]],
311+
'viewSettings' => [
312+
'cardBackgroundSource' => 10,
313+
'cardTitleSource' => 11,
314+
],
315+
],
316+
[
317+
'tableId' => 1,
318+
'title' => 'Legacy settings',
319+
'columnSettings' => [['columnId' => 11, 'order' => 0]],
320+
'cardBackgroundSource' => 11,
321+
'cardTitleSource' => 10,
322+
],
323+
];
324+
325+
$importSource->method('getFileContents')->willReturnCallback(static function (string $file) use ($tableData, $columns, $views): string {
326+
return match ($file) {
327+
'tables.json' => json_encode([$tableData]),
328+
'columns.json' => json_encode($columns),
329+
'views.json' => json_encode($views),
330+
default => json_encode([]),
331+
};
332+
});
333+
334+
$newTable = new Table();
335+
$newTable->setId(100);
336+
$this->tableService->method('importTable')->willReturn($newTable);
337+
$this->columnService->method('importColumn')->willReturnOnConsecutiveCalls(20, 21);
338+
$this->rowService->method('importRow')->willReturn(1);
339+
340+
$this->tableMapper->method('getDBConnection')->willReturn(new class {
341+
public function beginTransaction(): void {
342+
}
343+
public function commit(): void {
344+
}
345+
public function rollBack(): void {
346+
}
347+
});
348+
349+
$importedViews = [];
350+
$this->viewService->expects($this->exactly(2))
351+
->method('importView')
352+
->with(
353+
$this->identicalTo(100),
354+
$this->callback(static function (array $view) use (&$importedViews): bool {
355+
$importedViews[] = $view;
356+
return true;
357+
}),
358+
$this->identicalTo('user1'),
359+
);
360+
361+
$this->migrator->import($user, $importSource, $output);
362+
363+
$this->assertSame(
364+
[
365+
'cardBackgroundSource' => 20,
366+
'cardTitleSource' => 21,
367+
],
368+
$importedViews[0]['viewSettings']
369+
);
370+
$this->assertSame(20, $importedViews[0]['columnSettings'][0]['columnId']);
371+
$this->assertSame(21, $importedViews[1]['cardBackgroundSource']);
372+
$this->assertSame(20, $importedViews[1]['cardTitleSource']);
373+
$this->assertSame(21, $importedViews[1]['columnSettings'][0]['columnId']);
374+
}
289375
}

0 commit comments

Comments
 (0)