feat: add new tag from text in text input, no enter needed.

This commit is contained in:
linonetwo 2023-07-14 23:34:29 +08:00 committed by lin onetwo
parent 72db085f2e
commit 65db454057
5 changed files with 15 additions and 6 deletions

View file

@ -461,7 +461,7 @@
"AddNewWorkflowDescription": "Create a new automated workflow and save it to the selected workspace wiki to backup.",
"BelongsToWorkspace": "Belongs to workspace",
"AddNewWorkflowDoneMessage": "Add successfully",
"AddTagsDescription": "press Enter to input a tag"
"AddTagsDescription": "in-wiki tags, press Enter to add more"
},
"Description": "Description",
"Tags": "Tags",

View file

@ -464,6 +464,6 @@
"AddNewWorkflowDescription": "创建新的自动化工作流并保存到所选的工作区Wiki里备份。",
"AddNewWorkflowDoneMessage": "添加成功",
"BelongsToWorkspace": "所属工作区",
"AddTagsDescription": "回车后变成标签的样子才算成功添加"
"AddTagsDescription": "Wiki内的标签回车可以添加更多"
}
}

View file

@ -114,6 +114,13 @@ export const AddItemDialog: React.FC<AddItemDialogProps> = ({
{...parameters}
label={`${t('Tags')} (${t('Workflow.AddTagsDescription')})`}
margin='dense'
onBlur={() => {
// add new tag from text in text input, no enter needed.
if (parameters.inputProps.value) {
const newValue = parameters.inputProps.value as string;
setTags(previousTags => [...previousTags.filter(tag => tag !== newValue), newValue]);
}
}}
/>
)}
renderTags={(value, getTagProps) =>
@ -124,6 +131,7 @@ export const AddItemDialog: React.FC<AddItemDialogProps> = ({
key={option}
/>
))}
clearOnBlur
/>
<Autocomplete
options={workspacesList ?? []}

View file

@ -40,8 +40,8 @@ export const WorkflowManage: React.FC = () => {
}, []);
const filteredWorkflows = workflows
.filter(workflow => workflow.title.includes(search))
.filter(workflow => selectedTags.some(tag => workflow.tags.includes(tag)));
.filter(workflow => search.length > 0 ? workflow.title.includes(search) : workflow)
.filter(workflow => selectedTags.length > 0 ? selectedTags.some(tag => workflow.tags.includes(tag)) : workflow);
return (
<Box>

View file

@ -119,7 +119,7 @@ export function useWorkflows(workspacesList: IWorkspaceWithMetadata[] | undefine
'{}',
{
type: 'application/json',
tags: newItem.tags,
tags: [...newItem.tags, workflowTiddlerTagName],
description: newItem.description ?? '',
'page-cover': newItem.image ?? '',
} satisfies Omit<IWorkflowTiddler, 'text' | 'title'>,
@ -129,7 +129,8 @@ export function useWorkflows(workspacesList: IWorkspaceWithMetadata[] | undefine
setWorkflows((workflows) => [...workflows.filter(item => item.title !== newItem.title), newItem]);
// update tag list in the search region tags filter
setTagsByWorkspace((previousTagsByWorkspace) => {
const newTags = newItem.tags.filter((tag) => !previousTagsByWorkspace[newItem.workspaceID]?.includes(tag));
// add newly appeared tags to local state
const newTags = newItem.tags.filter((tag) => !previousTagsByWorkspace[newItem.workspaceID]?.includes(tag) && tag !== workflowTiddlerTagName);
if (newTags.length === 0) return previousTagsByWorkspace;
const previousTags = previousTagsByWorkspace[newItem.workspaceID] ?? [];
return {