Skip to content

Commit

Permalink
Add DlData component for arbitrary key/value data from user (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-white authored Dec 7, 2024
1 parent 65aaa13 commit b6098dc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
55 changes: 55 additions & 0 deletions src/components/dl-data.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!--
Copyright 2024 ODK Central Developers
See the NOTICE file at the top-level directory of this distribution and at
https://github.com/getodk/central-frontend/blob/master/NOTICE.

This file is part of ODK Central. It is subject to the license terms in
the LICENSE file found in the top-level directory of this distribution and at
https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central,
including this file, may be copied, modified, propagated, or distributed
except according to the terms contained in the LICENSE file.
-->

<!-- The DlData component renders a <dt> and <dd> for arbitrary key/value data
from the user, e.g., entity data. The key and value will be truncated if they
are too long. -->
<template>
<dt class="dl-data-dt"><span v-tooltip.text>{{ name }}</span></dt>

<dd v-if="value == null || value === ''" class="dl-data-dd empty">
{{ $t('common.emptyValue') }}
</dd>
<dd v-else class="dl-data-dd" v-tooltip.text>{{ value }}</dd>
</template>

<script setup>
defineOptions({
name: 'DlData'
});
defineProps({
// "key" would have been a nice name for this prop, but sadly that's a
// reserved name.
name: {
type: String,
required: true
},
value: String
});
</script>

<style lang="scss">
@import '../assets/scss/mixins';

.dl-data-dt { @include text-overflow-ellipsis; }

.dl-data-dd {
@include line-clamp(3);
overflow-wrap: break-word;
white-space: break-spaces;

&.empty {
@include italic;
color: #888;
}
}
</style>
22 changes: 2 additions & 20 deletions src/components/entity/data.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ except according to the terms contained in the LICENSE file.
<loading :state="dataset.initiallyLoading"/>
<dl v-if="dataExists">
<div v-for="{ name } of dataset.properties" :key="name">
<dt><span v-tooltip.text>{{ name }}</span></dt>
<dd v-if="data[name] == null || data[name] === ''" class="empty">
{{ $t('common.emptyValue') }}
</dd>
<dd v-else v-tooltip.text>{{ data[name] }}</dd>
<dl-data :name="name" :value="data[name]"/>
</div>
</dl>
</template>
Expand All @@ -36,6 +32,7 @@ except according to the terms contained in the LICENSE file.
<script setup>
import { computed } from 'vue';

import DlData from '../dl-data.vue';
import Loading from '../loading.vue';
import PageSection from '../page/section.vue';

Expand All @@ -57,23 +54,8 @@ const data = computed(() => entity.currentVersion.data);
</script>

<style lang="scss">
@import '../../assets/scss/mixins';

#entity-data {
margin-bottom: 35px;

dt { @include text-overflow-ellipsis; }

dd {
@include line-clamp(3);
overflow-wrap: break-word;
white-space: break-spaces;
}

.empty {
@include italic;
color: #888;
}
}
</style>

Expand Down

0 comments on commit b6098dc

Please sign in to comment.