-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support exporting and importing tags of workflows via frontend and cli. On export, all tag data is included in the json. - id - name - updatedAt - createdAt When importing a workflow json to n8n we: - first check if a tag with the same id and createdAt date exists in the database, then we can assume the tag is identical. Changes on the name of the tag are now preserved. - check if a tag with the same name exists on the database. - create a new tag with the given name.
- Loading branch information
Showing
7 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Supports both database entries and frontend api responses | ||
export interface ITag { | ||
id: string | number; | ||
name: string; | ||
createdAt?: string | Date; | ||
updatedAt?: string | Date; | ||
} | ||
|
||
// Set tag ids to use existing tags, creates a new tag if no matching tag could be found | ||
export async function setTagsForImport( | ||
workflow: { tags: ITag[] }, | ||
tagsEntities: ITag[], | ||
createTag: (name: string) => Promise<ITag>, | ||
): Promise<void> { | ||
const findOrCreateTag = async (importTag: ITag) => { | ||
// Assume tag is identical if createdAt date is the same to preserve a changed tag name | ||
const identicalMatch = tagsEntities.find( | ||
(existingTag) => | ||
existingTag.id.toString() === importTag.id.toString() && | ||
existingTag.createdAt && | ||
importTag.createdAt && | ||
new Date(existingTag.createdAt) === new Date(importTag.createdAt), | ||
); | ||
if (identicalMatch) { | ||
return identicalMatch; | ||
} | ||
|
||
// Find tag with identical name | ||
const nameMatch = tagsEntities.find((existingTag) => existingTag.name === importTag.name); | ||
if (nameMatch) { | ||
return nameMatch; | ||
} | ||
|
||
// Create new Tag | ||
const createdTag = await createTag(importTag.name); | ||
// add new tag to available tags | ||
tagsEntities.push(createdTag); | ||
return createdTag; | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
const workflowTags = workflow.tags; | ||
if (!workflowTags || !Array.isArray(workflowTags) || workflowTags.length === 0) { | ||
return; | ||
} | ||
for (let i = 0; i < workflowTags.length; i++) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const tag = await findOrCreateTag(workflowTags[i]); | ||
workflowTags[i] = { | ||
id: tag.id, | ||
name: tag.name, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters