Skip to content

Conversation

@sourabratabose
Copy link

@sourabratabose sourabratabose commented Apr 24, 2025

…back to org level configuration as fetched

Description

I have updated the fetchValue() function body to fetch both the organization level and repo level configurations which are then merged and returned on call. Repo level configurations as found will be considered as final over organization level configurations.

Related Issue

#422

Motivation and Context

As of right now, the org fallback only works if you have no site config. We should inherit on a row basis so that if a site has a single property (aem.assets.link.type) the rest still falls back to org so you don't have to duplicate your repoId, etc.

To solve this as mention in issue #422.

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [ x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x ] I have signed the Adobe Open Source CLA.
  • [x ] My code follows the code style of this project.
  • [x ] My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Comment on lines 40 to 60
const data = null;

// Start with organization-level config
if (orgConf) {
data = {};
orgConf.forEach((item) => {
data[item.key] = item.value;
});
}

// Override with repository-level config
if (repoConf) {
if (data === null) data = {};
repoConf.forEach((item) => {
data[item.key] = item.value;
});
}

if (!data) return null;

const confKey = data.find((conf) => conf.key === key);
Copy link
Contributor

Choose a reason for hiding this comment

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

data was an array previously, and is now an object which means that the data.find will fail on line 60. Now that it's an object, you can just do a lookup

Suggested change
const data = null;
// Start with organization-level config
if (orgConf) {
data = {};
orgConf.forEach((item) => {
data[item.key] = item.value;
});
}
// Override with repository-level config
if (repoConf) {
if (data === null) data = {};
repoConf.forEach((item) => {
data[item.key] = item.value;
});
}
if (!data) return null;
const confKey = data.find((conf) => conf.key === key);
const data = {};
// Start with organization-level config
orgConf?.forEach((item) => {
data[item.key] = item.value;
});
// Override with repository-level config
repoConf?.forEach((item) => {
data[item.key] = item.value;
});
return data[key];

Copy link
Author

Choose a reason for hiding this comment

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

I will be updating the PR to treat data as an array to retain the expected data type of data variable. Pushing objects to an array and updating values inside them if the keys match afterwards, is my approach.

@sourabratabose
Copy link
Author

sourabratabose commented Apr 26, 2025

Hi @chrischrischris , I didn't really understand as to why the path variable is required to be passed anyways.

Since configuration merge is fetched from an exhaustive list of paths. I decided to check whether paths are matching with the expected org and repo level paths, fetch the configurations and merge as required.

All other fetchValue() calls which dont match that path patterns will still fall through and return the value fetched as expected in the original function body.

@auniverseaway
Copy link
Member

Closing. A) there's now conflicts, B) I think there was some missing context of the needs for this PR and I think we can accomplish the need in a simpler way.

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