Skip to content

Commit

Permalink
Use property odataName in entities table
Browse files Browse the repository at this point in the history
Closes #793.
  • Loading branch information
matthew-white committed May 23, 2023
1 parent d10b037 commit 012afe3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/entity/data-row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ except according to the terms contained in the LICENSE file.
<template>
<tr>
<td v-for="property of properties" :key="property.id">
<span v-tooltip.text>{{ entity[property.name] }}</span>
<span v-tooltip.text>{{ entity[property.odataName] }}</span>
</td>
<td><span v-tooltip.text>{{ entity.label }}</span></td>
<td>{{ entity.__id }}</td>
Expand Down
13 changes: 12 additions & 1 deletion test/components/entity/data-row.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('EntityDataRow', () => {
td[2].text().should.equal('abcd1234');
});

it('renders a cell for each field', () => {
it('renders a cell for each property', () => {
testData.extendedDatasets.createPast(1, {
name: 'trees',
properties: [
Expand Down Expand Up @@ -90,4 +90,15 @@ describe('EntityDataRow', () => {
span.text().should.equal('foobar');
await span.should.have.textTooltip();
});

it('uses the odataName of the property', () => {
testData.extendedDatasets.createPast(1, {
properties: [{ name: 'circumference.cm', odataName: 'circumference_cm' }],
entities: 1
});
testData.extendedEntities.createPast(1, {
data: { 'circumference.cm': '555' }
});
mountComponent().get('td').text().should.equal('555');
});
});
8 changes: 7 additions & 1 deletion test/data/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { comparator } from 'ramda';
import { dataStore } from './data-store';
import { extendedProjects } from './projects';

const normalizeProperty = (property) => ({
odataName: property.name,
forms: [],
...property
});

// eslint-disable-next-line import/prefer-default-export
export const extendedDatasets = dataStore({
factory: ({
Expand All @@ -23,7 +29,7 @@ export const extendedDatasets = dataStore({
name,
entities,
lastEntity,
properties,
properties: properties.map(normalizeProperty),
linkedForms,
approvalRequired
}),
Expand Down
44 changes: 29 additions & 15 deletions test/data/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,35 @@ export const extendedEntities = dataStore({
export const standardEntities = view(extendedEntities, omit(['creator']));

// Converts entity response objects to OData.
export const entityOData = (top = 250, skip = 0) => ({
'@odata.count': extendedEntities.size,
value: extendedEntities.sorted().slice(skip, skip + top)
.map(entity => ({
...entity.currentVersion.data,
label: entity.currentVersion.label,
__id: entity.uuid,
__system: {
creatorId: entity.creator.id.toString(),
creatorName: entity.creator.displayName,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt
}
}))
});
export const entityOData = (top = 250, skip = 0) => {
if (extendedDatasets.size === 0) throw new Error('dataset not found');
// There needs to be exactly one dataset for us to be able to identify the
// correct one.
if (extendedDatasets.size > 1) throw new Error('too many datasets');
const { properties } = extendedDatasets.last();
return {
'@odata.count': extendedEntities.size,
value: extendedEntities.sorted().slice(skip, skip + top).map(entity => {
const result = {
label: entity.currentVersion.label,
__id: entity.uuid,
__system: {
creatorId: entity.creator.id.toString(),
creatorName: entity.creator.displayName,
createdAt: entity.createdAt,
updatedAt: entity.updatedAt
}
};

const { data } = entity.currentVersion;
// Iterate over all dataset properties, not just those in `data`.
for (const { name, odataName } of properties)
result[odataName] = name in data ? data[name] : null;

return result;
})
};
};

// Creates a source submission along with submission audit log events.
extendedEntities.createSourceSubmission = (sourceAction, submissionOptions = {}) => {
Expand Down

0 comments on commit 012afe3

Please sign in to comment.