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

feat: RO-Crate Contextual entity #373

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sivangbagri
Copy link
Contributor

@sivangbagri sivangbagri commented Oct 30, 2024

Description

This PR adds contextual entity (Person, Org) support to ro-crate.
Continuing #370

Checklist

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit, using the PR title as the commit message.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated the user-facing documentation to describe any new or changed behavior.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have not reduced the existing code coverage.

Comments

Summary by Sourcery

New Features:

  • Introduce contextual entity support for Person and Organization in the RO-Crate component.

Copy link
Contributor

sourcery-ai bot commented Oct 30, 2024

Reviewer's Guide by Sourcery

This PR implements contextual entity support (Person and Organization) in the RO-Crate client by introducing a new tabbed form component. The implementation uses Lit Element and includes three main sections: About, Related People/Organizations, and Structure. The form dynamically updates based on user selections and handles different types of licenses and entity relationships.

Class diagram for ECCClientRoCrateAbout component

classDiagram
    class ECCClientRoCrateAbout {
        - activeTab: number
        - AboutFields: Field[]
        + render(): void
        + _switchTab(index: number): void
        + _handleDataset(e: CustomEvent): void
    }
    class Field {
        + key: string
        + label: string
        + type: string
        + fieldOptions: object
        + arrayOptions: object
        + groupOptions: object
        + children: Field[]
    }
    ECCClientRoCrateAbout --> Field
    note for ECCClientRoCrateAbout "This class represents a LitElement component with tabbed forms for contextual entities."
Loading

File-Level Changes

Change Details Files
Implementation of a new tabbed form component for RO-Crate metadata management
  • Created a base LitElement class with three tab sections: About, Related People/Orgs & Works, and Structure
  • Implemented tab switching functionality
  • Added state management for form fields using Lit's @State decorator
packages/ecc-client-elixir-ro-crate/src/components/about/about.ts
Implementation of dynamic form fields for dataset metadata
  • Added required dataset fields including @id, @type, name, description, and datePublished
  • Implemented dynamic license field handling with URL and CreativeWork options
  • Added field validation and tooltips for user guidance
packages/ecc-client-elixir-ro-crate/src/components/about/about.ts
Addition of contextual entity support for people and organizations
  • Implemented author fields for Person entities with ID, type, and name properties
  • Added publisher and funder fields for Organization entities
  • Created array-based form fields for multiple entity entries
packages/ecc-client-elixir-ro-crate/src/components/about/about.ts
Setup of demo environment and component registration
  • Created demo pages for testing the RO-Crate form component
  • Registered the custom element for browser use
  • Added basic styling and layout for the demo pages
packages/ecc-client-elixir-ro-crate/demo/about/index.html
packages/ecc-client-elixir-ro-crate/demo/index.html
packages/ecc-client-elixir-ro-crate/src/components/about/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

changeset-bot bot commented Oct 30, 2024

⚠️ No Changeset found

Latest commit: ea3c933

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
elixir-cloud-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 18, 2024 11:23am

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @sivangbagri - I've reviewed your changes - here's some feedback:

Overall Comments:

  • There appears to be a bug where organization types default to 'Person' instead of 'Organization' in the publisher and funder sections
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const licenceFieldIndex = this.AboutFields.findIndex(
(field) => field.key === "licence"
);
const licenceChildren = this.AboutFields[licenceFieldIndex].children ?? [];
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider combining the multiple .filter() operations into a single pass for better performance and readability

Instead of chaining multiple .filter() calls, you could combine the conditions using logical operators in a single filter operation. This would improve both performance and code maintainability.

label: "@type",
type: "text",
fieldOptions: {
default: "Person",
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Incorrect default @type for organization entries

The default @type for organization entries in both publisher and funder sections is set to 'Person' when it should be 'Organization'. This could cause data consistency issues.

private _switchTab(index: number): void {
this.activeTab = index;
}
private _handleDataset(e: CustomEvent): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring license field handling to use a configuration map pattern

The license field handling in _handleDataset can be simplified by using a configuration map approach. This reduces nesting and makes the code more maintainable:

private readonly LICENSE_CONFIGS = {
  URL: {
    removeKeys: ['@id', '@type', 'name', 'desc'],
    addFields: [{
      key: 'url',
      label: 'URL',
      type: 'url',
      fieldOptions: { required: true }
    }]
  },
  CreativeWork: {
    removeKeys: ['url'],
    addFields: [{
      key: '@id',
      label: '@id',
      type: 'text',
      fieldOptions: {
        required: true,
        tooltip: 'Persistent, managed unique ID in URL format'
      }
    },
    // ... other CreativeWork fields
    ]
  }
};

private _handleDataset(e: CustomEvent): void {
  if (e.detail.key !== 'licence') return;

  const config = this.LICENSE_CONFIGS[e.detail.value];
  if (!config) return;

  const licenceFieldIndex = this.AboutFields.findIndex(field => field.key === 'licence');
  if (licenceFieldIndex === -1) return;

  const licenceChildren = this.AboutFields[licenceFieldIndex].children ?? [];
  const updatedChildren = licenceChildren
    .filter(child => !config.removeKeys.includes(child.key))
    .concat(config.addFields);

  this.AboutFields = [
    ...this.AboutFields.slice(0, licenceFieldIndex),
    { ...this.AboutFields[licenceFieldIndex], children: updatedChildren },
    ...this.AboutFields.slice(licenceFieldIndex + 1)
  ];
}

This approach:

  1. Moves field configurations to a declarative map
  2. Eliminates nested conditionals
  3. Reduces repeated array operations
  4. Makes adding new license types easier

},
children: [
{
key: "person",
Copy link
Contributor

Choose a reason for hiding this comment

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

according to the ro-crate specification Author can either be a person or organization. So you should not label this as person. I think it would be better to use the key 'author-entities' and the label 'Author Entities'.

Also please the keys for the other fields in this array accordingly.

},
},
{
key: "personType",
Copy link
Contributor

Choose a reason for hiding this comment

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

the type of type allows for either organization or person, you should change this to a select field with only those 2 options.

},
children: [
{
key: "org",
Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue I addressed above applies here as well. The publisher entity allows for organization or person. Please change the keys and labels accordingly. And change the type field to a select field that allows for either 'organization' or 'person' to be selected.

},
children: [
{
key: "org",
Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue I stated above applies here, please update the entity to reflect the specification. It is pretty much the same situation as the author and publisher entitties.

@SalihuDickson
Copy link
Contributor

@sivangbagri, could you please modularize your code a little, one suggestion would be to move the fields objects into a fields.ts page. I think one major issue we are starting to have in this monorepo is a lack of proper modularization.

Also you can go ahead an resolve conflicts with the main branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants