Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.

Refactor data-viewer to rely on css not js, improve UX #142

Merged
merged 2 commits into from
Sep 24, 2020
Merged
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
62 changes: 21 additions & 41 deletions client/components/data-viewer.vue
Original file line number Diff line number Diff line change
@@ -1,64 +1,38 @@
<template>
<div class="data-viewer">
<a
href="#"
class="view-full-screen"
@click.stop.prevent="viewFullScreen"
></a>
<prism language="json" ref="codebox">{{ preview }}</prism>
<prism language="json" ref="codebox" class="code" :style="maxLinesStl">{{
fullview
}}</prism>
<a href="#" class="view-full-screen" @click.stop.prevent="viewFullScreen">
</a>
</div>
</template>

<script>
import 'prismjs';
import 'prismjs/components/prism-json';
import Prism from 'vue-prism-component';
import getStringElipsis from '~helpers/get-string-elipsis';

export default {
name: 'data-viewer',
props: ['compact', 'highlight', 'item', 'title'],
props: {
item: [Object, Array, String, Number],
title: String,
maxLines: { type: Number, default: 3 },
},
data() {
return {};
},
created() {
this.checkOverflow = () => {
const el = this.$refs.codebox;

if (!el) {
return;
}

const hasMoreJson = this.fullview.length > this.preview.length;

const overflowed =
el.scrollWidth > el.offsetWidth + 2 ||
el.scrollHeight > el.offsetHeight + 2;

const action = hasMoreJson || overflowed ? 'add' : 'remove';

this.$el.classList[action]('overflow');
};
window.addEventListener('resize', this.checkOverflow);
['item', 'highlight', 'compact'].forEach((e) =>
this.$watch(e, this.checkOverflow)
);
this.$watch(() => this.$route, this.checkOverflow);
},
mounted() {
this.checkOverflow();
},
computed: {
fullview() {
return this.item ? JSON.stringify(this.item, null, 2) : '';
},
preview() {
return this.item ? getStringElipsis(this.fullview) : '';
maxLinesStl() {
return {
'max-height': `${0.8 + this.maxLines}rem`,
};
},
},
beforeDestroy() {
window.removeEventListener('resize', this.checkOverflow);
},
methods: {
viewFullScreen() {
this.$modal.show(
Expand Down Expand Up @@ -97,7 +71,13 @@ export default {

.data-viewer
position relative
&:not(.overflow) a.view-full-screen
display flex
max-width: 40vw;
.code
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
&:not(:hover) a.view-full-screen
display none
a.view-full-screen
position absolute
Expand Down
9 changes: 4 additions & 5 deletions client/components/detail-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { preKeys } from '~constants';

export default {
name: 'detail-list',
props: ['compact', 'highlight', 'item', 'title'],
props: ['item', 'title'],
components: {
'data-viewer': DataViewer,
},
Expand All @@ -17,7 +17,7 @@ export default {
},
},
render(h) {
const { highlight, compact, title } = this;
const { title } = this;

function dd(kvp) {
if (kvp.routeLink) {
Expand All @@ -29,9 +29,8 @@ export default {
h('data-viewer', {
props: {
item: kvp.value,
compact,
highlight,
title: `${title} - ${kvp.key}`,
maxLines: 3,
},
}),
]
Expand All @@ -41,7 +40,7 @@ export default {
return h(
'dl',
{ class: 'details' },
this.item.kvps.map(kvp =>
this.item.kvps.map((kvp) =>
h('div', { attrs: { 'data-prop': kvp.key } }, [
h('dt', null, kvp.key),
h('dd', null, dd(kvp)),
Expand Down
4 changes: 0 additions & 4 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export const ENVIRONMENT_LIST = [
// },
];

export const MAXIMUM_JSON_CHARACTER_LIMIT = 100;
export const MAXIMUM_JSON_MESSAGE =
'\n * to see more open full screen mode from top right arrow.';

export const NOTIFICATION_TYPE_ERROR = 'error';
export const NOTIFICATION_TYPE_ERROR_MESSAGE_DEFAULT =
'An unexpected error has occurred. Please try again. If problems persist contact temporal-support.';
Expand Down
11 changes: 0 additions & 11 deletions client/helpers/get-string-elipsis.js

This file was deleted.

34 changes: 0 additions & 34 deletions client/helpers/get-string-elipsis.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion client/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export { default as getEnvironmentLocation } from './get-environment-location';
export { default as getErrorMessage } from './get-error-message';
export { default as getKeyValuePairs } from './get-key-value-pairs';
export { default as getStartTimeIsoString } from './get-start-time-iso-string';
export { default as getStringElipsis } from './get-string-elipsis';
export { default as http } from './http';
export { default as injectMomentDurationFormat } from './inject-moment-duration-format';
export { default as jsonTryParse } from './json-try-parse';
Expand Down
1 change: 0 additions & 1 deletion client/routes/workflow/history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
: item.eventFullDetails
"
:compact="compactDetails && !item.expanded"
:highlight="events.length < 100"
/>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion client/routes/workflow/summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@
<div class="workflow-result" v-if="resultView" data-cy="workflow-result">
<dt>Result</dt>
<dd>
<data-viewer :item="resultView" :title="workflowId + ' Result'" />
<data-viewer
:item="resultView"
:title="workflowId + ' Result'"
:maxLines="10"
/>
</dd>
</div>
<div class="workflow-id" data-cy="workflow-id">
Expand Down Expand Up @@ -122,6 +126,7 @@
v-if="input !== undefined"
:item="input"
:title="workflowId + ' Input'"
:maxLines="10"
/>
</dd>
</div>
Expand Down