Skip to content

Commit

Permalink
Merge pull request #546 from t3-innovation-network/staging
Browse files Browse the repository at this point in the history
Release 06/07/24
  • Loading branch information
excelsior authored Jun 7, 2024
2 parents 18b1e14 + cdf385c commit 7a96adb
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 149 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/alignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
:predicate,
:specification,
mapping: %i(configuration_profile_user organization),
mapped_terms: %i(organization property vocabularies)
mapped_terms: [:organization, :property, { specifications: { domain: :spine } }, :vocabularies]
)
.where(
mappings: { spine_id: params[:spine_id], status: :mapped }
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/api/v1/specifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
module API
module V1
class SpecificationsController < BaseController
include ConfigurationProfileQueryable

###
# @description: Lists all the specifications
###
def index
specifications =
if current_configuration_profile
current_configuration_profile.specifications
else
Specification.all
end

if (domain = params[:domain]).present?
specifications = specifications.joins(:domain).where(domains: { pref_label: domain })
end

render json: specifications.joins(:mappings).where(mappings: { status: "mapped" }).distinct.order(name: :asc)
end

###
# @description: Create a specification with its terms. Store it from an already
# filtered JSON object
Expand Down
69 changes: 40 additions & 29 deletions app/javascript/components/property-mapping-list/PropertiesList.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from 'react';
import { compact, flatMap, sortBy, uniqBy } from 'lodash';
import { flatMap, groupBy, intersection, sortBy, uniqBy } from 'lodash';
import AlertNotice from '../shared/AlertNotice';
import fetchAlignmentsForSpine from '../../services/fetchAlignmentsForSpine';
import fetchSpineTerms from '../../services/fetchSpineTerms';
Expand All @@ -19,13 +19,13 @@ import { dateLongFormat } from 'utils/dateFormatting';
* @param {Boolean} hideSpineTermsWithNoAlignments
* @param {Object} configurationProfile
* @param {String} inputValue
* @param {Array} organizations
* @param {Array} specifications
* @param {Object} selectedDomain
* @param {String} selectedAlignmentOrderOption
* @param {Array} selectedAlignmentOrganizations
* @param {Array} selectedAlignmentSpecifications
* @param {Array} selectedPredicates
* @param {String} selectedSpineOrderOption
* @param {Array} selectedSpineOrganizations
* @param {Array} selectedSpineSpecifications
*/
export default class PropertiesList extends Component {
/**
Expand Down Expand Up @@ -68,15 +68,15 @@ export default class PropertiesList extends Component {
selectedPredicateIds = () => this.props.selectedPredicates.map((predicate) => predicate.id);

/**
* The list of ids for the selected alignment organizations
* The list of ids for the selected alignment specifications
*/
selectedAlignmentOrganizationIds = () =>
this.props.selectedAlignmentOrganizations.map((org) => org.id);
selectedAlignmentSpecificationsIds = () =>
this.props.selectedAlignmentSpecifications.map((s) => s.id);

/**
* The list of ids for the selected spine organizations
* The list of ids for the selected spine specifications
*/
selectedSpineOrganizationIds = () => this.props.selectedSpineOrganizations.map((org) => org.id);
selectedSpineSpecificationIds = () => this.props.selectedSpineSpecifications.map((s) => s.id);

/**
* Returns the list of properties filtered by the value the user typed in the searchbar
Expand All @@ -97,14 +97,15 @@ export default class PropertiesList extends Component {
property.alignments.some((alignment) =>
this.selectedPredicateIds().includes(alignment.predicateId)
) &&
/// It matches the selected alignment organizations
/// It matches the selected alignment specifications
property.alignments.some((alignment) =>
alignment.mappedTerms.some((mTerm) =>
this.selectedAlignmentOrganizationIds().includes(mTerm.organization?.id)
)
this.selectedAlignmentSpecificationsIds().includes(alignment.mapping.specification.id)
) &&
/// It matches the selected spine organizations
this.selectedSpineOrganizationIds().includes(property.organization?.id)))
/// It matches the selected spine specifications
intersection(
this.selectedSpineSpecificationIds(),
property.specifications.map((s) => s.id)
).length))
);

return implementSpineSort(filteredProps, selectedSpineOrderOption);
Expand Down Expand Up @@ -139,7 +140,7 @@ export default class PropertiesList extends Component {

if (!this.anyError(response)) {
const { alignments } = response;
const groupedAlignments = _.groupBy(alignments, 'spineTermId');
const groupedAlignments = groupBy(alignments, 'spineTermId');

spineTerms.forEach((term) => {
term.alignments = groupedAlignments[term.id] || [];
Expand Down Expand Up @@ -243,9 +244,9 @@ export default class PropertiesList extends Component {
<div className="col-8">
<PropertyAlignments
selectedAlignmentOrderOption={selectedAlignmentOrderOption}
selectedAlignmentOrganizationIds={this.selectedAlignmentOrganizationIds()}
selectedAlignmentSpecificationsIds={this.selectedAlignmentSpecificationsIds()}
selectedPredicateIds={this.selectedPredicateIds()}
selectedSpineOrganizationIds={this.selectedSpineOrganizationIds()}
selectedSpineSpecificationIds={this.selectedSpineSpecificationIds()}
spineTerm={term}
/>
</div>
Expand All @@ -254,25 +255,35 @@ export default class PropertiesList extends Component {
});

const filteredMappingsList = () => {
const mappings = sortBy(
uniqBy(
compact(
flatMap(this.filteredProperties(), (term) => term.alignments.map((a) => a.mapping))
),
'id'
),
'title'
const mappings = uniqBy(
flatMap(this.filteredProperties(), (term) => term.alignments.map((a) => a.mapping)),
'id'
);

const groupedMappings = {};

for (const mapping of mappings) {
const lastMapping = groupedMappings[mapping.specification.name];

if (!lastMapping || lastMapping.mappedAt < mapping.mappedAt) {
groupedMappings[mapping.specification.name] = mapping;
}
}

const lastMappings = sortBy(Object.values(groupedMappings), 'specification.name');

return (
<>
<h5 className="mb-0 mt-3">
{i18n.t('ui.view_mapping.mapping', { count: mappings.length })}
</h5>
<ul className="list-unstyled mb-0">
{mappings.map((mapping) => (
{lastMappings.map((mapping) => (
<li key={mapping.id}>
<span className="fw-bold">{mapping.title}</span> updated at{' '}
{dateLongFormat(mapping.mappedAt)}.{mapping.description}
<span className="fw-bold">
{mapping.specification.name} {mapping.version ? `(${mapping.version})` : ''}
</span>{' '}
updated on {dateLongFormat(mapping.mappedAt)}.
</li>
))}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useState } from 'react';
import { compact, flatMap } from 'lodash';
import { compact, flatMap, intersection } from 'lodash';
import { implementAlignmentSort, implementAlignmentTermsSort } from './SortOptions';
import { propertyClassesForAlignmentTerm } from './stores/propertyMappingListStore';

Expand All @@ -11,18 +11,18 @@ import { propertyClassesForAlignmentTerm } from './stores/propertyMappingListSto
* @param {Object} spineTerm The term of the spine to look for alignments
* @param {Array} selectedPredicateIds The list of predicates selected by the user in the filter
* @param {String} selectedAlignmentOrderOption The option selected by the user to order the list of alignments
* @param {Array} selectedAlignmentOrganizationIds The list of organizations that made alignments, selected by the user
* @param {Array} selectedAlignmentSpecificationsIds The list of specifications that made alignments, selected by the user
* in the filter.
* @param {Array} selectedSpineOrganizationIds The list of organizations that has properties with alignments, selected
* @param {Array} selectedSpineSpecificationIds The list of specifications that has properties with alignments, selected
* by the user in the filter. This refers to the origin of the property. Initially, a spine specification will have
* all its properties with the same organization. When a synthetic property is created, it will keep the organization
* all its properties with the same specification. When a synthetic property is created, it will keep the specification
* of origin.
*/
const PropertyAlignments = (props) => {
const {
selectedPredicateIds,
selectedAlignmentOrganizationIds,
selectedSpineOrganizationIds,
selectedAlignmentSpecificationsIds,
selectedSpineSpecificationIds,
} = props;
const alignments = props.spineTerm.alignments;

Expand All @@ -32,18 +32,22 @@ const PropertyAlignments = (props) => {
(alignment) =>
/// It matches the selected predicates
selectedPredicateIds.includes(alignment.predicateId) &&
/// It matches the selected alignment organizations
alignment.mappedTerms.some((mTerm) =>
selectedAlignmentOrganizationIds.includes(mTerm.organization.id)
) &&
/// It matches the selected alignment organizations
selectedSpineOrganizationIds.includes(props.spineTerm.organization.id)
/// It matches the selected alignment specifications
selectedAlignmentSpecificationsIds.includes(alignment.mapping.specification.id) &&
/// It matches the selected alignment specifications
intersection(
selectedSpineSpecificationIds,
props.spineTerm.specifications.map((s) => s.id)
).length
);
filteredAl = implementAlignmentSort(filteredAl, props.selectedAlignmentOrderOption);
let filteredMappedTerms = compact(
flatMap(filteredAl, (alignment) =>
alignment.mappedTerms.map((mTerm) =>
selectedAlignmentOrganizationIds.includes(mTerm.organization.id)
intersection(
selectedAlignmentSpecificationsIds,
mTerm.specifications.map((s) => s.id)
).length
? {
...mTerm,
alignment,
Expand All @@ -57,8 +61,8 @@ const PropertyAlignments = (props) => {
}, [
alignments,
selectedPredicateIds,
selectedAlignmentOrganizationIds,
selectedSpineOrganizationIds,
selectedAlignmentSpecificationsIds,
selectedSpineSpecificationIds,
props.selectedAlignmentOrderOption,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const PropertyMappingList = (props) => {
const {
configurationProfile,
domains,
organizations,
specifications,
predicates,
selectedDomain,
hideSpineTermsWithNoAlignments,
propertiesInputValue,
selectedAlignmentOrderOption,
selectedAlignmentOrganizations,
selectedAlignmentSpecifications,
selectedPredicates,
selectedSpineOrderOption,
selectedSpineOrganizations,
selectedSpineSpecifications,
} = state;
const updateQueryString = updateWithRouter(props);

Expand Down Expand Up @@ -125,32 +125,32 @@ const PropertyMappingList = (props) => {
{selectedDomain && (
<>
<PropertyMappingsFilter
organizations={organizations}
onAlignmentOrganizationSelected={actions.setSelectedAlignmentOrganizations}
specifications={specifications}
onAlignmentSpecificationSelected={actions.setSelectedAlignmentSpecifications}
onPredicateSelected={actions.setSelectedPredicates}
onSpineOrganizationSelected={actions.setSelectedSpineOrganizations}
onSpineSpecificationSelected={actions.setSelectedSpineSpecifications}
predicates={predicates}
selectedAlignmentOrderOption={selectedAlignmentOrderOption}
selectedAlignmentOrganizations={selectedAlignmentOrganizations}
selectedAlignmentSpecifications={selectedAlignmentSpecifications}
selectedDomain={selectedDomain}
selectedPredicates={selectedPredicates}
selectedSpineOrderOption={selectedSpineOrderOption}
selectedSpineOrganizations={selectedSpineOrganizations}
selectedSpineSpecifications={selectedSpineSpecifications}
/>

<PropertiesList
hideSpineTermsWithNoAlignments={hideSpineTermsWithNoAlignments}
inputValue={propertiesInputValue}
configurationProfile={configurationProfile}
domains={domains}
organizations={organizations}
specifications={specifications}
predicates={predicates}
selectedAlignmentOrderOption={selectedAlignmentOrderOption}
selectedAlignmentOrganizations={selectedAlignmentOrganizations}
selectedAlignmentSpecifications={selectedAlignmentSpecifications}
selectedDomain={selectedDomain}
selectedPredicates={selectedPredicates}
selectedSpineOrderOption={selectedSpineOrderOption}
selectedSpineOrganizations={selectedSpineOrganizations}
selectedSpineSpecifications={selectedSpineSpecifications}
/>
</>
)}
Expand Down
Loading

0 comments on commit 7a96adb

Please sign in to comment.