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

Add an option to open source FE writer generate to enable writing annotations. #2849

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

Conversation

kjose90
Copy link
Member

@kjose90 kjose90 commented Jan 30, 2025

#2773

  • Added option addAnnotations to FioriElementsApp interface.
  • Added logic to write annotations if addAnnotations is enabled and template type is LROP/ Worklist and service is OData version 4 or if template type is FEOP.
  • Unit tests

Copy link

changeset-bot bot commented Jan 30, 2025

🦋 Changeset detected

Latest commit: c3e53c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sap-ux/fiori-elements-writer Minor
@sap-ux/generator-simple-fe Patch

Not sure what this means? Click here to learn what changesets are.

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

@kjose90 kjose90 marked this pull request as ready for review January 30, 2025 11:06
@kjose90 kjose90 requested a review from a team as a code owner January 30, 2025 11:06
Copy link
Member

@devinea devinea left a comment

Choose a reason for hiding this comment

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

Overall looks good. couple of small suggestions

function canGenerateAnnotationsForTemplate(version: OdataVersion, type: TemplateType): boolean {
const isODataV4 = version === OdataVersion.v4;
const supportedTemplates: TemplateType[] = [TemplateType.ListReportObjectPage, TemplateType.Worklist];
return (isODataV4 && supportedTemplates.includes(type)) || type === TemplateType.FormEntryObjectPage;
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 267 to 295
const { settings } = feApp.template;
const { capService } = feApp.service;
const { name: packageName } = feApp.package ?? {};
let serviceName = 'mainService';
let projectPath = basePath;
// add line items is false for FormEntryObjectPage type project
const addLineItems =
feApp.template.type === TemplateType.ListReportObjectPage || feApp.template.type === TemplateType.Worklist;
const entitySetName = (settings as T & { entityConfig?: EntityConfig })?.entityConfig?.mainEntityName ?? '';

if (capService) {
serviceName = capService.serviceName;
projectPath = capService.projectPath;
}

const options: GenerateAnnotationsOptions = {
entitySetName,
annotationFilePath: getAnnotationFilePath(packageName, capService),
addFacets: true,
addLineItems,
addValueHelps: !!capService
};
const serviceParameters: AnnotationServiceParameters = {
serviceName,
appName: packageName,
project: projectPath
};

await generateAnnotations(fs, serviceParameters, options);
Copy link
Member

Choose a reason for hiding this comment

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

could we move this into a separate function?

devinea
devinea previously approved these changes Jan 31, 2025
Copy link
Member

@devinea devinea left a comment

Choose a reason for hiding this comment

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

Code changes are clean and covered by tests.
Thanks for the updates.
Changeset ✅

@@ -0,0 +1,102 @@
import { sep } from 'path';
Copy link
Contributor

@IainSAP IainSAP Jan 31, 2025

Choose a reason for hiding this comment

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

Not sure if the data folder is the correct place as this is for static settings but I guess it's ok for now, not sure what data means actually in this context :)

* @param {boolean} [addAnnotations] - An optional flag indicating whether annotations should be enabled.
* @returns {boolean} - Returns `true` if annotations can be generated, otherwise `false`.
*/
export function canGenerateAnnotationsForTemplate(
Copy link
Contributor

@IainSAP IainSAP Jan 31, 2025

Choose a reason for hiding this comment

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

Would it be better to use the template settings for this information, as thats its purpose, to have all template related information in one place.

e.g.

export const TemplateTypeAttributes: TemplateAttributes = {
    [TemplateType.Worklist]: {
        supportedODataVersions: [OdataVersion.v2, OdataVersion.v4],
        minimumUi5Version: {
            [OdataVersion.v2]: minSupportedUI5Version,
            [OdataVersion.v4]: '1.99.0'
        },
        annotationGenerationSupport: {
            [OdataVersion.v4]: true
    },

Then you dont need this function: https://github.com/SAP/open-ux-tools/pull/2849/files#diff-ac5073f87858b510da65484577f6afc172f304cfec03c196415cb096ce0ebf14R45
or this def:
https://github.com/SAP/open-ux-tools/pull/2849/files#diff-ac5073f87858b510da65484577f6afc172f304cfec03c196415cb096ce0ebf14R16

@@ -223,6 +236,33 @@ async function generate<T extends {}>(basePath: string, data: FioriElementsApp<T
await applyCAPUpdates(fs, feApp.service.capService, settings);
}

// Handle annotation writing
if (
Copy link
Contributor

@IainSAP IainSAP Jan 31, 2025

Choose a reason for hiding this comment

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

Can we move this whole block to the writeAnnotions file :

if (feApp.appOptions.addAnnotations) {
writeAnnotations(...)
}

The index file is getting too busy and the function is too long now! Would be nicer to hide all annotation writing code to that file now?

@@ -2,6 +2,9 @@
"info": {
"mockOnlyWarning": "This application was generated with a local metadata file and does not reference a live server. Please add the required server configuration or start this application with mock data using the target: npm run start-mock"
},
"warn": {
"invalidTypeForAnnotationGeneration": "Invalid template type '{{ templateType }}' for annotation generation. Supported types are: {{ supportedTypes }}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add additional information...

"The provided option addAnnotations is not supported for the specified template and odata version. Generation will continue but additional annotations will not added."

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