Skip to content

Commit

Permalink
test: nested component checks
Browse files Browse the repository at this point in the history
- identifies if a page is that of a nested component
- reassigns packageName to the nestedComponentName in order to navigate
to a nestedComponent link guidelines
  • Loading branch information
marissahuysentruyt committed Sep 18, 2024
1 parent 7a98286 commit 82e4159
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
35 changes: 34 additions & 1 deletion .storybook/blocks/ComponentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ const convertLinkTypeText = (linkType) => {
return linkType;
};

// checks if the page URL includes any nested component
const isNestedComponent = (data) => {
const url = window.location.href;
const nestedComponent = data.nestedComponentName;

if (url.includes(nestedComponent)) {
return true;
}
return false;
};

export const ResourceLinkContent = ({data, linkType=["package", "repository", "guidelines"]}) => {
const packageJson = data;

Expand All @@ -244,17 +255,30 @@ export const ResourceLinkContent = ({data, linkType=["package", "repository", "g
// componentBetaName: for components with guidelines that are still on spectrum-contributions/beta site
let packageAltName = "";
let packageAltLink = "";


// for instances where a single package.json generates multiple components (i.e. form, meter)
let nestedComponentName = (isNestedComponent(packageJson)) ? packageJson?.nestedComponentName : undefined;

const isNestedComponentPage = isNestedComponent(packageJson);

if(linkType === "package") {
// NPM package name and link
packageName = packageJson?.name ?? undefined;
packageLink = (packageName && typeof packageName !== "undefined") ? `https://npmjs.com/${packageName}` : false;

if(isNestedComponentPage && (typeof nestedComponentName !== "undefined")) {
packageName = packageJson?.nestedComponentName ?? undefined;
}
}

else if (linkType === "repository") {
// repo name and link
packageName = packageJson?.name ? packageJson?.name.split('/').pop() : undefined;
packageLink = (packageName && typeof packageName !== "undefined") ? `https://github.com/adobe/spectrum-css/tree/main/components/${packageName}` : false;

if(isNestedComponentPage && (typeof nestedComponentName !== "undefined")) {
packageName = packageJson?.nestedComponentName ? packageJson?.nestedComponentName.split('/').pop() : undefined;
}
}

else if (linkType === "guidelines") {
Expand All @@ -269,6 +293,15 @@ export const ResourceLinkContent = ({data, linkType=["package", "repository", "g
packageAltLink = (packageAltName && typeof packageAltName !== "undefined") ? `https://spectrum-contributions.corp.adobe.com/page/${packageAltName}` : false;
packageLink = packageAltLink;
}

if(isNestedComponentPage && (typeof nestedComponentName !== "undefined")) {
packageName = packageJson?.nestedComponentName ?? undefined;
packageLink = (packageName && typeof packageName !== "undefined") ? `https://spectrum.adobe.com/page/${packageName}` : false;
}
if (isNestedComponentPage && nestedComponentName === "form") {
packageName = packageJson?.nestedGuidelinesName;
packageLink = (packageName && typeof packageName !== "undefined") ? `https://spectrum.adobe.com/page/${packageName}` : false;
}
}

else {
Expand Down
4 changes: 3 additions & 1 deletion components/fieldlabel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@
"publishConfig": {
"access": "public"
},
"componentGuidelinesName": "field-label"
"componentGuidelinesName": "field-label",
"nestedComponentName": "form",
"nestedGuidelinesName": "form-errors"
}
3 changes: 2 additions & 1 deletion components/progressbar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
"publishConfig": {
"access": "public"
},
"componentGuidelinesName": "progress-bar"
"componentGuidelinesName": "progress-bar",
"nestedComponentName": "meter"
}

0 comments on commit 82e4159

Please sign in to comment.