-
Notifications
You must be signed in to change notification settings - Fork 0
Add visibility management for spreadsheet columns #55
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
Changes from 3 commits
029b3ee
888a429
524a531
497666b
e30f074
9f2ec23
7982f3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -51,5 +51,8 @@ public record ColumnInfos( | |||||
String filterValue, | ||||||
|
||||||
@Schema(description = "Filter tolerance for numeric comparisons") | ||||||
Double filterTolerance | ||||||
Double filterTolerance, | ||||||
|
||||||
@Schema(description = "Column visibility", defaultValue = "true") | ||||||
Boolean visible | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not using the primitive type if null isn't a value we support?
Suggested change
|
||||||
) { } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.studyconfig.server.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* DTO for updating column state (visibility and order) | ||
* @author Achour BERRAHMA <achour.berrahma at rte-france.com> | ||
*/ | ||
@Schema(name = "ColumnStateUpdateDto", description = "Column state update information") | ||
public record ColumnStateUpdateInfos( | ||
|
||
@NotNull(message = "Column UUID is mandatory") | ||
@Schema(description = "Column UUID") | ||
UUID columnId, | ||
|
||
@NotNull(message = "Visible state is mandatory") | ||
@Schema(description = "Column visibility state") | ||
Boolean visible, | ||
|
||
@NotNull(message = "Order is mandatory") | ||
@Schema(description = "New position in the column order (0-based index)") | ||
Integer order | ||
|
||
) { } |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -61,4 +61,7 @@ public class ColumnEntity { | |||||
@Column(name = "filter_tolerance") | ||||||
private Double filterTolerance; | ||||||
|
||||||
@Column(name = "visible", nullable = false) | ||||||
@Builder.Default | ||||||
private Boolean visible = true; | ||||||
|
private Boolean visible = true; | |
private boolean visible = true; |
You can also set the default value at SQL level:
@ColumnDefault(false)
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -333,6 +333,7 @@ public void updateColumn(UUID id, UUID columnId, ColumnInfos dto) { | |||||||||||||||||||||
columnEntity.setFilterType(dto.filterType()); | ||||||||||||||||||||||
columnEntity.setFilterValue(dto.filterValue()); | ||||||||||||||||||||||
columnEntity.setFilterTolerance(dto.filterTolerance()); | ||||||||||||||||||||||
columnEntity.setVisible(dto.visible() != null ? dto.visible() : true); | ||||||||||||||||||||||
|
||||||||||||||||||||||
spreadsheetConfigRepository.save(entity); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -352,13 +353,41 @@ public void reorderColumns(UUID id, List<UUID> columnOrder) { | |||||||||||||||||||||
SpreadsheetConfigEntity entity = findEntityById(id); | ||||||||||||||||||||||
List<ColumnEntity> columns = entity.getColumns(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
reorderColumns(columnOrder, columns); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
private static void reorderColumns(List<UUID> columnOrder, List<ColumnEntity> columns) { | ||||||||||||||||||||||
columns.sort((c1, c2) -> { | ||||||||||||||||||||||
int idx1 = columnOrder.indexOf(c1.getUuid()); | ||||||||||||||||||||||
int idx2 = columnOrder.indexOf(c2.getUuid()); | ||||||||||||||||||||||
return Integer.compare(idx1, idx2); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IntelliJ simplify as
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
@Transactional | ||||||||||||||||||||||
public void updateColumnStates(UUID id, List<ColumnStateUpdateInfos> columnStates) { | ||||||||||||||||||||||
SpreadsheetConfigEntity entity = findEntityById(id); | ||||||||||||||||||||||
List<ColumnEntity> columns = entity.getColumns(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
Map<UUID, ColumnEntity> columnMap = columns.stream() | ||||||||||||||||||||||
.collect(Collectors.toMap(ColumnEntity::getUuid, column -> column)); | ||||||||||||||||||||||
|
||||||||||||||||||||||
for (ColumnStateUpdateInfos state : columnStates) { | ||||||||||||||||||||||
ColumnEntity column = columnMap.get(state.columnId()); | ||||||||||||||||||||||
if (column == null) { | ||||||||||||||||||||||
throw new EntityNotFoundException(COLUMN_NOT_FOUND + state.columnId()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
column.setVisible(state.visible()); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Reorder columns based on the provided states | ||||||||||||||||||||||
List<UUID> orderedColumnIds = columnStates.stream() | ||||||||||||||||||||||
.sorted(Comparator.comparingInt(ColumnStateUpdateInfos::order)) | ||||||||||||||||||||||
.map(ColumnStateUpdateInfos::columnId) | ||||||||||||||||||||||
.toList(); | ||||||||||||||||||||||
reorderColumns(orderedColumnIds, columns); | ||||||||||||||||||||||
Comment on lines
+380
to
+384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of creating an intermediate list, you can order directly in one step. |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
private SpreadsheetConfigCollectionInfos readDefaultSpreadsheetConfigCollection() throws IOException { | ||||||||||||||||||||||
try (InputStream inputStream = defaultSpreadsheetConfigCollectionResource.getInputStream()) { | ||||||||||||||||||||||
return objectMapper.readValue(inputStream, SpreadsheetConfigCollectionInfos.class); | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||||||||||||||||||||||||||||||||||||||||||||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||||||||||||||||||||||||||||||||||||||||||||||
<changeSet author="berrahmaach (generated)" id="1749213150568-4"> | ||||||||||||||||||||||||||||||||||||||||||||||
<addColumn tableName="spreadsheet_column"> | ||||||||||||||||||||||||||||||||||||||||||||||
<column name="visible" type="boolean" defaultValueBoolean="true"> | ||||||||||||||||||||||||||||||||||||||||||||||
<constraints nullable="false"/> | ||||||||||||||||||||||||||||||||||||||||||||||
</column> | ||||||||||||||||||||||||||||||||||||||||||||||
</addColumn> | ||||||||||||||||||||||||||||||||||||||||||||||
</changeSet> | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
<!-- Set default value for existing rows --> | ||||||||||||||||||||||||||||||||||||||||||||||
<changeSet author="berrahmaach" id="1749213150568-5"> | ||||||||||||||||||||||||||||||||||||||||||||||
<update tableName="spreadsheet_column"> | ||||||||||||||||||||||||||||||||||||||||||||||
<column name="visible" valueBoolean="true"/> | ||||||||||||||||||||||||||||||||||||||||||||||
<where>visible IS NULL</where> | ||||||||||||||||||||||||||||||||||||||||||||||
</update> | ||||||||||||||||||||||||||||||||||||||||||||||
</changeSet> | ||||||||||||||||||||||||||||||||||||||||||||||
|
<changeSet author="berrahmaach (generated)" id="1749213150568-4"> | |
<addColumn tableName="spreadsheet_column"> | |
<column name="visible" type="boolean" defaultValueBoolean="true"> | |
<constraints nullable="false"/> | |
</column> | |
</addColumn> | |
</changeSet> | |
<!-- Set default value for existing rows --> | |
<changeSet author="berrahmaach" id="1749213150568-5"> | |
<update tableName="spreadsheet_column"> | |
<column name="visible" valueBoolean="true"/> | |
<where>visible IS NULL</where> | |
</update> | |
</changeSet> | |
<changeSet author="berrahmaach (generated)" id="1749213150568-4"> | |
<addColumn tableName="spreadsheet_column"> | |
<column name="visible" type="boolean" defaultValueBoolean="true" valueBoolean="true" remarks="Is the column visible in the table?"> | |
<constraints nullable="false"/> | |
</column> | |
</addColumn> | |
</changeSet> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultValue
withoutnullable=true
?