Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use property odataName in entities table #807

Merged
merged 1 commit into from
May 24, 2023
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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odataName: property.odataName ?? property.name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property.name is the default odataName. The defaults are merged with property using ...property, so if property specifies its own odataName, it will overwrite the default.

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