Skip to content

Commit 5ccf02e

Browse files
authored
Issue 54062: Strip folder name from displayed name from file field (#7123)
1 parent d674799 commit 5ccf02e

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

api/src/org/labkey/api/data/AbstractFileDisplayColumn.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public void renderGridCellContents(RenderContext ctx, HtmlWriter out)
7777
/** @return the short name of the file (not including full path) */
7878
protected abstract String getFileName(RenderContext ctx, Object value);
7979

80+
protected String getFileName(RenderContext ctx, Object value, boolean isDisplay)
81+
{
82+
return getFileName(ctx, value);
83+
}
84+
8085
protected abstract InputStream getFileContents(RenderContext ctx, Object value) throws FileNotFoundException;
8186

8287
protected void renderIconAndFilename(RenderContext ctx, HtmlWriter out, String fileValue, boolean link, boolean thumbnail)
@@ -99,7 +104,7 @@ protected void renderIconAndFilename(RenderContext ctx, HtmlWriter out, String f
99104
// equivalent of DisplayColumn.renderURL.
100105
// Don't want to call renderUrl (DataColumn.renderUrl) to skip unnecessary displayValue check
101106
StringExpression s = compileExpression(ctx.getViewContext());
102-
String displayName = getFileName(ctx, fileValue);
107+
String displayName = getFileName(ctx, fileValue, true);
103108
boolean unavailable = displayName.endsWith(UNAVAILABLE_FILE_SUFFIX);
104109
String url = null == s || unavailable ? null : s.eval(ctx);
105110
boolean isImage = isImage(fileValue);

api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ public static boolean filePathExist(String path, Container container, User user)
288288

289289
@Override
290290
protected String getFileName(RenderContext ctx, Object value)
291+
{
292+
return getFileName(ctx, value, false);
293+
}
294+
295+
@Override
296+
protected String getFileName(RenderContext ctx, Object value, boolean isDisplay)
291297
{
292298
String result = value == null ? null : StringUtils.trimToNull(value.toString());
293299
if (result != null)
@@ -335,6 +341,10 @@ protected String getFileName(RenderContext ctx, Object value)
335341
result = relativize(f, FileContentService.get().getFileRoot(container, fileRootType));
336342
if (result != null)
337343
{
344+
// Issue 54062: Strip folder name from displayed name
345+
if (isDisplay)
346+
result = f.getName();
347+
338348
valid = true;
339349
break;
340350
}
@@ -438,13 +448,13 @@ else if (f.isDirectory())
438448
@Override
439449
public Object getDisplayValue(RenderContext ctx)
440450
{
441-
return getFileName(ctx, super.getDisplayValue(ctx));
451+
return getFileName(ctx, super.getDisplayValue(ctx), true);
442452
}
443453

444454
@Override
445455
public Object getJsonValue(RenderContext ctx)
446456
{
447-
return getDisplayValue(ctx);
457+
return getFileName(ctx, super.getDisplayValue(ctx));
448458
}
449459

450460
@Override

study/test/src/org/labkey/test/tests/study/StudyDatasetFileFieldTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,7 @@ public void testFileField() throws IOException, CommandException
146146
.selectDatasetByName(datasetName)
147147
.clickViewData();
148148

149-
String expectedText;
150-
151-
if (SystemUtils.IS_OS_WINDOWS)
152-
expectedText = "datasetdata\\sample.txt";
153-
else
154-
expectedText = "datasetdata/sample.txt";
149+
String expectedText = "sample.txt";
155150

156151
assertElementPresent("Did not find the expected sample.txt from the imported dataset.", Locator.tagContainingText("a", expectedText), 1);
157152
downloadedFile = doAndWaitForDownload(() -> waitAndClick(WAIT_FOR_JAVASCRIPT, Locator.tagWithAttribute("a", "title", "Download attached file"), 0));

0 commit comments

Comments
 (0)