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

Ro-Crate Dataset entity #364

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

sivangbagri
Copy link
Contributor

@sivangbagri sivangbagri commented Oct 9, 2024

Description

Added required fields for root dataset entity.

Checklist

  • My code follows the [contributing guidelines][contributing] 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.

Summary by Sourcery

Add a new ECCClientRoCrateAbout component to manage dataset metadata with fields for ID, type, name, description, date published, and licence. Enhance the EccUtilsDesignForm component to dispatch custom events on field changes. Introduce demo pages to showcase the new component.

New Features:

  • Introduce a new component ECCClientRoCrateAbout for managing dataset metadata, including fields for ID, type, name, description, date published, and licence.
  • Add a new demo page for the ecc-client-elixir-ro-crate package to showcase the ECCClientRoCrateAbout component.

Enhancements:

  • Enhance the EccUtilsDesignForm component to dispatch a custom event ecc-utils-change whenever form fields are updated, allowing for better integration and event handling.

Copy link

changeset-bot bot commented Oct 9, 2024

⚠️ No Changeset found

Latest commit: 52f6602

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 9, 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 Oct 9, 2024 5:23am

Copy link
Contributor

sourcery-ai bot commented Oct 9, 2024

Reviewer's Guide by Sourcery

This pull request implements a new component for handling RO-Crate Dataset entities in the ELIXIR Cloud & Compute project. The changes include adding required fields for the root dataset entity, implementing a form for dataset metadata, and enhancing the existing form component with new event handling capabilities.

Sequence diagram for form event handling

sequenceDiagram
    actor User
    participant ECCUtilsDesignForm
    participant ECCClientRoCrateAbout
    User ->> ECCUtilsDesignForm: Interact with form
    ECCUtilsDesignForm -->> ECCClientRoCrateAbout: Dispatch "ecc-utils-change" event
    ECCClientRoCrateAbout ->> ECCClientRoCrateAbout: _handleDataset(e)
    ECCClientRoCrateAbout -->> ECCClientRoCrateAbout: Update AboutFields based on event detail
    ECCClientRoCrateAbout -->> ECCUtilsDesignForm: Update form display
Loading

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
        + children: Field[]
    }
    ECCClientRoCrateAbout --> Field
Loading

File-Level Changes

Change Details Files
Added a new component for RO-Crate Dataset entity handling
  • Created a new ECCClientRoCrateAbout class extending LitElement
  • Implemented tabs for 'About', 'Related People, Orgs & Works', and 'Structure'
  • Added form fields for dataset metadata including @id, @type, name, description, datePublished, and licence
  • Implemented dynamic form field updates based on user input
  • Added demo files for the new component
packages/ecc-client-elixir-ro-crate/src/components/about/about.ts
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
Enhanced the existing form component with new event handling
  • Added 'ecc-utils-change' event dispatch for various form field types
  • Implemented event handling for the new custom event in the demo
packages/ecc-utils-design/src/components/form/form.ts
packages/ecc-utils-design/demo/form/index.html

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
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:

  • Consider refactoring the ECCClientRoCrateAbout class in the future to break it down into smaller, more manageable components. This would improve maintainability without affecting current functionality.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues 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.

@@ -129,6 +129,16 @@ export default class EccUtilsDesignForm extends LitElement {
@sl-change=${(e: Event) => {
_.set(this.form, path, (e.target as HTMLInputElement).checked);
this.requestUpdate();
this.dispatchEvent(
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 extracting the repeated event dispatch code into a separate function.

The repeated event dispatch code across different form elements introduces unnecessary complexity. To simplify the code and improve maintainability, extract this common behavior into a separate function. Here's an example of how you can refactor this:

// Add this utility function
private dispatchChangeEvent(key: string, value: any) {
  this.dispatchEvent(
    new CustomEvent("ecc-utils-change", {
      detail: { key, value },
      bubbles: true,
      composed: true,
    })
  );
}

// Then, replace the repeated code in each event handler with a call to this function
// For example, in the switch element:
@sl-change=${(e: Event) => {
  const checked = (e.target as HTMLInputElement).checked;
  _.set(this.form, path, checked);
  this.requestUpdate();
  this.dispatchChangeEvent(field.key, checked);
}}

// Similarly for other elements, e.g., file input:
@change=${async (e: Event) => {
  const { files } = e.target as HTMLInputElement;
  _.set(this.form, path, files);
  this.requestUpdate();
  this.dispatchChangeEvent(field.key, files);
}}

This refactoring reduces code duplication, improves maintainability, and makes it easier to modify the event dispatch behavior in the future if needed. It also retains all the new functionality while simplifying the code structure.

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 the _handleDataset method and moving field definitions to a separate file.

The _handleDataset method can be simplified to reduce complexity and improve maintainability. Here's a suggested refactoring:

  1. Separate the field update logic:
private updateLicenceFields(licenceType: string): Field[] {
  const baseFields = [
    { key: "licence", label: "Licence Type", type: "select", fieldOptions: { required: true },
      selectOptions: [{ label: "URL", value: "URL" }, { label: "CreativeWork", value: "CreativeWork" }]
    }
  ];

  const urlFields = [
    { key: "url", label: "URL", type: "url", fieldOptions: { required: true } }
  ];

  const creativeWorkFields = [
    { key: "@id", label: "@id", type: "text", fieldOptions: { required: true, tooltip: "Persistent, managed unique ID in URL format" } },
    { key: "@type", label: "@type", type: "text", fieldOptions: { default: "CreativeWork", required: true, tooltip: "The type of the entity." } },
    { key: "name", label: "Name", type: "text", fieldOptions: { required: true, tooltip: "The name of the item." } },
    { key: "desc", label: "Description", type: "text", fieldOptions: { required: true, tooltip: "A description of the item." } }
  ];

  return [...baseFields, ...(licenceType === "URL" ? urlFields : creativeWorkFields)];
}

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

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

  const updatedLicenceField = {
    ...this.AboutFields[licenceFieldIndex],
    children: this.updateLicenceFields(e.detail.value)
  };

  this.AboutFields = [
    ...this.AboutFields.slice(0, licenceFieldIndex),
    updatedLicenceField,
    ...this.AboutFields.slice(licenceFieldIndex + 1)
  ];
}
  1. Move field definitions to a separate file:

Create a new file fieldDefinitions.ts:

import { Field } from "@elixir-cloud/design/dist/components/form/form";

export const AboutFields: Field[] = [
  // ... (move the AboutFields array here)
];

export const RelatedPeopleFields: Field[] = [
  // ... (move the RelatedPeopleFields array here)
];

export const StructureFields: Field[] = [
  // ... (move the StructureFields array here)
];

Then import and use these definitions in your component:

import { AboutFields, RelatedPeopleFields, StructureFields } from './fieldDefinitions';

export default class ECCClientRoCrateAbout extends LitElement {
  @state()
  private AboutFields = AboutFields;

  static RelatedPeopleFields = RelatedPeopleFields;
  static StructureFields = StructureFields;

  // ... rest of the class
}

These changes will significantly reduce the complexity of the _handleDataset method, improve code organization, and make the component more maintainable and easier to extend in the future.

@SalihuDickson
Copy link
Contributor

hi @sivangbagri great work so far, but it seems you're continuing from the #355 PR. I think we need to split up the PR, have one implementing the dataset entity, one for the metadata entity and then the necessary contextual and data entities respectively. That way we can make the PRs more specific and easier to review.

You can go ahead and start with a new PR and just copy over the code implementing the dataset entity. I'll just cherry-pick the original PR to implement the fixes we made that were blockers for you.

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.

3 participants