Skip to content

Commit

Permalink
#4708 Add copy links to stream info pane
Browse files Browse the repository at this point in the history
  • Loading branch information
stroomdev66 committed Jan 23, 2025
1 parent 86d8e42 commit fdaba5b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,23 @@ public static SafeHtml render(final String value) {
return sb.toSafeHtml();
}

public static void render(final String value, final SafeHtmlBuilder sb) {
public static void render(final String value,
final SafeHtmlBuilder sb) {
if (value == null) {
sb.append(SafeHtmlUtils.EMPTY_SAFE_HTML);
} else {
render(value, SafeHtmlUtils.fromString(value), sb);
}
}

public static void render(final String value,
final SafeHtml safeHtml,
final SafeHtmlBuilder sb) {
if (value == null) {
sb.append(SafeHtmlUtils.EMPTY_SAFE_HTML);
} else {
final SafeHtml textSafeHtml = TEMPLATE
.div("docRefLinkText", SafeHtmlUtils.fromString(value));
.div("docRefLinkText", safeHtml);

final String containerClasses = String.join(
" ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Focus;
Expand Down Expand Up @@ -264,6 +266,8 @@ protected void onBind() {
registerHandler(dataView.getTabBar().addSelectionHandler(event ->
onNewTabSelected(event.getSelectedItem())));
registerHandler(dataView.getTabBar().addShowMenuHandler(e -> getEventBus().fireEvent(e)));
registerHandler(htmlPresenter.getWidget().addDomHandler(e ->
CopyTextUtil.onClick(e.getNativeEvent()), MouseDownEvent.getType()));
}

private void onNewTabSelected(final TabData tab) {
Expand Down Expand Up @@ -331,8 +335,8 @@ private void updateEditorDisplay() {
// a sub-set of the data (i.e. from DataDisplaySupport) and it makes no sense to
// see hex of this sub-set when the sub-set location is reliant on chars being decodeable.
if (INFO_TAB_NAME.equals(currentTabName)
|| ERROR_TAB_NAME.equals(currentTabName)
|| currentSourceLocation.getDataRange() != null) {
|| ERROR_TAB_NAME.equals(currentTabName)
|| currentSourceLocation.getDataRange() != null) {
textPresenter.getViewAsHexOption().setOff();
textPresenter.getViewAsHexOption().setUnavailable();
} else {
Expand All @@ -343,8 +347,8 @@ private void updateEditorDisplay() {
showErrors(lastResult);
} else {
final boolean shouldFormatData = lastResult != null
&& FetchDataRequest.DisplayMode.TEXT.equals(lastResult.getDisplayMode())
&& AceEditorMode.XML.equals(editorMode);
&& FetchDataRequest.DisplayMode.TEXT.equals(lastResult.getDisplayMode())
&& AceEditorMode.XML.equals(editorMode);

textPresenter.getViewAsHexOption()
.setOn(FetchDataRequest.DisplayMode.HEX.equals(lastResult != null
Expand All @@ -363,10 +367,10 @@ private boolean isInErrorMarkerMode() {

private void refreshProgressBar(final boolean isVisible) {
if (isVisible
&& lastResult != null
&& lastResult instanceof FetchDataResult
&& lastResult.getSourceLocation() != null
&& lastResult.getSourceLocation().getDataRange() != null) {
&& lastResult != null
&& lastResult instanceof FetchDataResult
&& lastResult.getSourceLocation() != null
&& lastResult.getSourceLocation().getDataRange() != null) {

final DataRange dataRange = lastResult.getSourceLocation().getDataRange();

Expand All @@ -378,25 +382,25 @@ private void refreshProgressBar(final boolean isVisible) {
// not segments in a segmented file. Thus for most segmented streams the segment will fit in the
// data preview and thus will always see 100%
if (!DataType.SEGMENTED.equals(fetchDataResult.getDataType())
&& fetchDataResult.getOptTotalBytes().isPresent()
&& dataRange.getOptByteOffsetFrom().isPresent()
&& dataRange.getOptByteOffsetTo().isPresent()) {
&& fetchDataResult.getOptTotalBytes().isPresent()
&& dataRange.getOptByteOffsetFrom().isPresent()
&& dataRange.getOptByteOffsetTo().isPresent()) {
// progress based on know byte size and byte offsets
progressPresenter.setProgress(Progress.boundedRange(
fetchDataResult.getTotalBytes() - 1, // count to zero based bound
dataRange.getByteOffsetFrom(),
dataRange.getByteOffsetTo()));
} else if (fetchDataResult.getTotalCharacterCount() != null
&& fetchDataResult.getTotalCharacterCount().isExact()
&& dataRange.getCharOffsetFrom() != null
&& dataRange.getCharOffsetTo() != null) {
&& fetchDataResult.getTotalCharacterCount().isExact()
&& dataRange.getCharOffsetFrom() != null
&& dataRange.getCharOffsetTo() != null) {
// progress based on known char count and char offsets
progressPresenter.setProgress(Progress.boundedRange(
fetchDataResult.getTotalCharacterCount().getCount() - 1, // count to zero based bound
dataRange.getCharOffsetFrom(),
dataRange.getCharOffsetTo()));
} else if (dataRange.getCharOffsetFrom() != null
&& dataRange.getCharOffsetTo() != null) {
&& dataRange.getCharOffsetTo() != null) {
// progress based on unknown char count and char offsets
progressPresenter.setProgress(Progress.unboundedRange(
dataRange.getCharOffsetFrom(),
Expand Down Expand Up @@ -595,13 +599,13 @@ private void showInvalidStreamErrorMsg() {
final long currentPartNo = getCurrentPartIndex() + 1;
final long currentRecordNo = getCurrentRecordIndex() + 1;
textPresenter.setErrorText("Error: Invalid stream ID "
+ (currentMetaId != null
+ (currentMetaId != null
? currentMetaId
: "null")
+ ":"
+ currentPartNo
+ ":"
+ currentRecordNo, "");
+ ":"
+ currentPartNo
+ ":"
+ currentRecordNo, "");
itemNavigatorPresenter.setDisplay(noNavigatorData);
dataView.setSourceLinkVisible(false, false);
showTextPresenter();
Expand Down Expand Up @@ -629,7 +633,7 @@ private void setEffectiveChildStreamType(final String streamTypeName,
// GWT.log(currentStreamType + " - " + currentChildDataType + " - " + availableChildStreamTypes);

if (effectiveChildStreamType != null
&& availableChildStreamTypes.contains(effectiveChildStreamType)) {
&& availableChildStreamTypes.contains(effectiveChildStreamType)) {
if (!Objects.equals(currentSourceLocation.getChildType(), effectiveChildStreamType)) {
currentSourceLocation = currentSourceLocation.copy()
.withChildStreamType(effectiveChildStreamType)
Expand Down Expand Up @@ -680,7 +684,7 @@ private void updateFromResource(final boolean fireEvents, final SourceLocation s

final FetchDataRequest request = new FetchDataRequest(builder.build());
if (StreamTypeNames.ERROR.equals(currentStreamType)
&& isInErrorMarkerMode()) {
&& isInErrorMarkerMode()) {
request.setDisplayMode(FetchDataRequest.DisplayMode.MARKER);
} else {
if (textPresenter.getViewAsHexOption().isOnAndAvailable()) {
Expand All @@ -707,7 +711,7 @@ private boolean isSameStreamAndPartAsLastTime() {
.orElse(null);

final boolean isSame = Objects.equals(getCurrentMetaId(), lastId)
&& Objects.equals(getCurrentPartIndex(), lastPartNo);
&& Objects.equals(getCurrentPartIndex(), lastPartNo);
// GWT.log(lastId + ":" + lastPartNo
// + " => "
// + getCurrentMetaId() + ":" + getCurrentPartIndex()
Expand Down Expand Up @@ -1010,20 +1014,20 @@ private void refreshTextPresenterContent() {
.map(childType -> " (" + childType + ")")
.orElse("");
final String title = "Unable to display stream ["
+ lastResult.getSourceLocation().getIdentifierString()
+ "]"
+ childStreamText
+ " as "
+ (lastResult.getDisplayMode() != null
+ lastResult.getSourceLocation().getIdentifierString()
+ "]"
+ childStreamText
+ " as "
+ (lastResult.getDisplayMode() != null
? lastResult.getDisplayMode().name().toLowerCase()
: "text");
final String errorText = String.join("\n", lastResult.getErrors());
setErrorText(title, errorText);
textPresenter.setControlsVisible(playButtonVisible);
} else {
final boolean shouldFormatData = lastResult != null
&& FetchDataRequest.DisplayMode.TEXT.equals(lastResult.getDisplayMode())
&& AceEditorMode.XML.equals(editorMode);
&& FetchDataRequest.DisplayMode.TEXT.equals(lastResult.getDisplayMode())
&& AceEditorMode.XML.equals(editorMode);

textPresenter.setMode(editorMode);
textPresenter.setText(data, shouldFormatData);
Expand Down Expand Up @@ -1070,10 +1074,10 @@ private void refreshHighlights(final AbstractFetchDataResult result) {
// matches that of the current page, and that the stream number matches
// the stream number of the current page.
if (highlights != null
&& Objects.equals(getCurrentMetaId(), highlightMetaId)
&& partIndex == highlightPartIndex
&& result != null
&& Objects.equals(result.getStreamTypeName(), highlightChildDataType)) {
&& Objects.equals(getCurrentMetaId(), highlightMetaId)
&& partIndex == highlightPartIndex
&& result != null
&& Objects.equals(result.getStreamTypeName(), highlightChildDataType)) {
// Set the content to be displayed in the source view with a
// highlight.
textPresenter.setHighlights(highlights);
Expand Down Expand Up @@ -1144,7 +1148,7 @@ private void handleMetaInfoResult(final List<DataInfoSection> dataInfoSections)

private SafeHtml toHtmlLineBreaks(final String str) {
if (str != null) {
HtmlBuilder sb = new HtmlBuilder();
final HtmlBuilder sb = new HtmlBuilder();
// Change any line breaks html line breaks
final String[] lines = str.split("\n");
for (int i = 0; i < lines.length; i++) {
Expand All @@ -1154,7 +1158,11 @@ private SafeHtml toHtmlLineBreaks(final String str) {
}
sb.append(line);
}
return sb.toSafeHtml();

final SafeHtmlBuilder copyLinkHtml = new SafeHtmlBuilder();
CopyTextUtil.render(str, sb.toSafeHtml(), copyLinkHtml);

return copyLinkHtml.toSafeHtml();
} else {
return null;
}
Expand Down Expand Up @@ -1205,17 +1213,17 @@ private void showErrors(final SourceLocation sourceLocation,
? (" as " + displayMode.name().toLowerCase())
: "";
final String title = "Unable to display source ["
+ sourceLocation.getIdentifierString()
+ "]"
+ childStreamText
+ displayModeText;
+ sourceLocation.getIdentifierString()
+ "]"
+ childStreamText
+ displayModeText;

final String errorText = Stream.concat(
errors != null
? errors.stream()
: Stream.empty(),
Stream.of("You can right click this pane and select 'View as hex' to see the raw data in " +
"hexadecimal form."))
"hexadecimal form."))
.collect(Collectors.joining("\n"));

dataView.setSourceLinkVisible(false, false);
Expand Down
24 changes: 24 additions & 0 deletions unreleased_changes/20250123_105934_803__4708.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* Issue **#4708** : Add copy links to stream info pane.


```sh
# ********************************************************************************
# Issue title: I'd like the copy to clipboard icon to be available for items in the Info Pane of a Stream
# Issue link: https://github.com/gchq/stroom/issues/4708
# ********************************************************************************

# ONLY the top line will be included as a change entry in the CHANGELOG.
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
# 'Fixed nasty bug'.
#
# Examples of acceptable entries are:
#
#
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
#
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
#
# * Fix bug with no associated GitHub issue.
```

0 comments on commit fdaba5b

Please sign in to comment.