Skip to content

Commit

Permalink
Remove links from connected components on api payload
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqu committed Jan 30, 2020
1 parent b093008 commit 4f05929
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/commands/connect/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,24 @@ const initializePlugins = async (plugins: Plugin[]): Promise<ConnectPluginInstan
return pluginInstances;
};

const removeEmptyFields = (componentData: ComponentData): ComponentData => {
if (typeof componentData.description === "undefined" || componentData.description.trim() === "") {
delete componentData.description;
const convertToData = (plugin: string, componentData: ComponentData): Data => {
const copyComponentData = { ...componentData };

if (typeof copyComponentData.description === "undefined" || copyComponentData.description.trim() === "") {
delete copyComponentData.description;
}

if (typeof componentData.snippet === "undefined" || componentData.snippet.trim() === "") {
delete componentData.snippet;
delete componentData.lang;
if (typeof copyComponentData.snippet === "undefined" || copyComponentData.snippet.trim() === "") {
delete copyComponentData.snippet;
delete copyComponentData.lang;
}

return componentData;
delete copyComponentData.links;

return {
plugin,
...copyComponentData
};
};

const processLink = (link: Link): Link => {
Expand All @@ -103,10 +110,7 @@ const connectComponentConfig = async (
logger.debug(`${plugin.name} supports ${component.path}. Processing…`);
const componentData = await plugin.process(component);

data.push({
plugin: plugin.name,
...removeEmptyFields(componentData)
});
data.push(convertToData(plugin.name, componentData));

componentData.links?.forEach(link =>
urlPaths.push(processLink(link))
Expand Down

0 comments on commit 4f05929

Please sign in to comment.