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

feat: support diff functions for some properties #5279

Closed
wants to merge 5 commits into from
Closed
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
21 changes: 15 additions & 6 deletions apollo-portal/src/main/resources/static/config/diff.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ <h4 class="modal-title">{{'Config.Diff.Title' | translate }}
</label>
</div>
<div class="col-sm-12 diff-content">
<table class="table table-bordered table-striped table-hover" ng-show="isTableDiff">
<thead>
<!--表格对比 properties mode-->
<table class="table table-bordered table-striped table-hover table-fixed" ng-show="isTableDiff">
<thead>
<tr>
<td>Key</td>
<td width="10%">Key</td>
<td ng-repeat="cluster in syncData.syncToNamespaces">
Value ( {{'Common.Environment' | translate }} : <label ng-bind="cluster.env"></label> , {{'Common.Cluster' | translate }} : <label ng-bind="cluster.clusterName"></label> )
</td>
Expand All @@ -142,16 +143,24 @@ <h4 class="modal-title">{{'Config.Diff.Title' | translate }}
<tbody>
<tr ng-repeat="(key, itemsKeyedByCluster) in itemsKeyedByKey" ng-if="(searchKey === '' || key.indexOf(searchKey) !== -1 ) && (!onlyShowDiffKeys || (onlyShowDiffKeys && !allNamespaceValueEqualed[key]))">
<td width="15%" ng-bind="key"></td>
<td ng-repeat="cluster in syncData.syncToNamespaces"
ng-bind="(itemsKeyedByCluster[cluster.env + ':' + cluster.clusterName + ':' + cluster.namespaceName] || {}).value">
<td ng-bind="(itemsKeyedByCluster[syncData.firstClusterKey] || {}).value"></td>
<td ng-repeat="cluster in syncData.syncToNamespaces.slice(1)">
<span ng-if="itemsKeyedByCluster[cluster.compositedKey]" >
<apollodiff old-str="(itemsKeyedByCluster[syncData.firstClusterKey] || {}).value"
new-str="(itemsKeyedByCluster[cluster.compositedKey] || {}).value"
apollo-id="'clusterDiff:' + key + ':' + cluster.compositedKey">
</apollodiff>
</span>
</td>
<td ng-show="showCommentDiff"
ng-repeat="cluster in syncData.syncToNamespaces"
ng-bind="(itemsKeyedByCluster[cluster.env + ':' + cluster.clusterName + ':' + cluster.namespaceName] || {}).comment">
ng-bind="(itemsKeyedByCluster[cluster.compositedKey] || {}).comment">
</td>
</tr>
</tbody>
</table>

<!--纯文本对比 text mode-->
<apollodiff ng-show="!isTableDiff" old-str="syncData.syncToNamespaces[0].originTextInfo"
new-str="syncData.syncToNamespaces[1].originTextInfo" apollo-id="'releaseStrDiff'">
</apollodiff>
Expand Down
17 changes: 10 additions & 7 deletions apollo-portal/src/main/resources/static/config/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ <h6 class="col-md-5 text-right" ng-bind="releaseHistory.releaseTimeFormatted"></
<section ng-show="history.viewType=='diff'">
<h4 class="section-title">{{'Config.History.ChangedItem' | translate }}</h4>
<div ng-show="history.changes && history.changes.length > 0">
<table class="no-margin table table-striped table-hover table-bordered">
<table class="no-margin table table-striped table-hover table-bordered table-fixed">
<thead>
<tr>
<th>{{'Config.History.ChangeType' | translate }}</th>
<th>{{'Config.History.ChangeKey' | translate }}</th>
<th width="10%">{{'Config.History.ChangeType' | translate }}</th>
<th width="12%">{{'Config.History.ChangeKey' | translate }}</th>
<th>{{'Config.History.ChangeOldValue' | translate }}</th>
<th>{{'Config.History.ChangeNewValue' | translate }}</th>
</tr>
Expand All @@ -188,11 +188,14 @@ <h4 class="section-title">{{'Config.History.ChangedItem' | translate }}</h4>
<span
ng-bind="change.entity.firstEntity.value.length > 250 ? '...' :''"></span>
</td>
<td class="cursor-pointer" width="35%"
<td class="cursor-pointer left-overflow" width="35%"
ng-click="showText(change.entity.secondEntity.value)">
<span ng-bind="change.entity.secondEntity.value | limitTo: 250"></span>
<span
ng-bind="change.entity.secondEntity.value.length > 250 ? '...' :''"></span>
<span>
<apollodiff old-str="change.entity.firstEntity.value"
new-str="change.entity.secondEntity.value"
apollo-id="'diff:' + change.entity.firstEntity.key">
</apollodiff>
</span>
</td>
</tr>
</tbody>
Expand Down
18 changes: 9 additions & 9 deletions apollo-portal/src/main/resources/static/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@
"Component.Publish.ToSeeChange": "查看变更",
"Component.Publish.CompareWithMasterValue": "与主版本对比",
"Component.Publish.CompareWithPublishedValue": "与已发布对比",
"Component.Publish.PublishedValue": "待发布的值",
"Component.Publish.Changes": "Changes",
"Component.Publish.PublishedValue": "已发布的值",
"Component.Publish.Changes": "改动",
"Component.Publish.Key": "Key",
"Component.Publish.NoPublishedValue": "未发布的值",
"Component.Publish.NoPublishedValue": "待发布的值",
"Component.Publish.ModifyUser": "修改人",
"Component.Publish.ModifyTime": "修改时间",
"Component.Publish.NewAdded": "新",
Expand All @@ -310,8 +310,8 @@
"Component.Publish.ItemNoChange": "配置没有变化",
"Component.Publish.GrayItemNoChange": "灰度配置没有变化",
"Component.Publish.NoGrayItems": "没有灰度的配置项",
"Component.Publish.Release": "Release Name",
"Component.Publish.ReleaseComment": "Comment",
"Component.Publish.Release": "版本名称",
"Component.Publish.ReleaseComment": "说明",
"Component.Publish.OpPublish": "发布",
"Component.Rollback.To": "回滚到",
"Component.Rollback.Tips": "此操作将会回滚到上一个发布版本,且当前版本作废,但不影响正在修改的配置。可在发布历史页面查看当前生效的版本",
Expand Down Expand Up @@ -731,11 +731,11 @@
"Config.History.ChangedItemTips": "查看此次发布与上次版本的变更",
"Config.History.AllItem": "全部配置",
"Config.History.AllItemTips": "查看此次发布的所有配置信息",
"Config.History.ChangeType": "Type",
"Config.History.ChangeType": "类型",
"Config.History.ChangeKey": "Key",
"Config.History.ChangeValue": "Value",
"Config.History.ChangeOldValue": "Old Value",
"Config.History.ChangeNewValue": "New Value",
"Config.History.ChangeValue": "",
"Config.History.ChangeOldValue": "旧值",
"Config.History.ChangeNewValue": "新值",
"Config.History.ChangeTypeNew": "新增",
"Config.History.ChangeTypeModify": "修改",
"Config.History.ChangeTypeDelete": "删除",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@ diff_item_module.controller("DiffItemController",
function parseSyncSourceData() {
var syncData = {
syncToNamespaces: [],
syncItems: []
syncItems: [],
firstClusterKey: "",
};
var namespaceName = $scope.pageContext.namespaceName;
selectedClusters.forEach(function (cluster) {
if (cluster.checked) {
cluster.clusterName = cluster.name;
cluster.namespaceName = namespaceName;
cluster.compositedKey = cluster.env + ':' + cluster.clusterName + ':' + cluster.namespaceName;
syncData.syncToNamespaces.push(cluster);
}
});

syncData.firstClusterKey = selectedClusters[0].compositedKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for selectedClusters array.

The current implementation assumes selectedClusters[0] exists, which could lead to runtime errors if the array is empty.

- syncData.firstClusterKey = selectedClusters[0].compositedKey;
+ syncData.firstClusterKey = selectedClusters.length > 0 ? selectedClusters[0].compositedKey : "";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
syncData.firstClusterKey = selectedClusters[0].compositedKey;
syncData.firstClusterKey = selectedClusters.length > 0 ? selectedClusters[0].compositedKey : "";

return syncData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ directive_module.directive('apollodiff',
part.removed ? 'red' : 'grey';
span = document.createElement('span');
span.style.color = color;
span.style.display = 'block';
pre = part.added ? '+' :
part.removed ? '-' : '';
span.appendChild(document.createTextNode(pre + part.value));
Expand Down
15 changes: 14 additions & 1 deletion apollo-portal/src/main/resources/static/styles/common-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ p, td, span {
color: #797979;
}

pre, .pre {
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}

.pre {
white-space: pre;
}

.hover:hover {
background: #f5f5f5;
cursor: pointer
Expand Down Expand Up @@ -1172,4 +1176,13 @@ table th {
#consumer-list .create-btn img {
width: 16px;
height: 16px;
}

.left-overflow {
overflow-x: auto;
text-align: left;
}

.table-fixed{
table-layout: fixed;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<pre class="no-radius" id="{{apolloId}}">
<pre class="no-radius pre" id="{{apolloId}}">
<!--
~ Copyright 2024 Apollo Authors
~
Expand Down
Loading
Loading