fix: pr comments fix
This commit is contained in:
@@ -10,10 +10,8 @@ import {
|
||||
Input,
|
||||
HStack,
|
||||
IconButton,
|
||||
Alert,
|
||||
AlertIcon,
|
||||
} from "@chakra-ui/react";
|
||||
import { useEffect, useState, useContext } from "react";
|
||||
import { useState, useContext } from "react";
|
||||
import { tagsTable, workflowsTable } from "../db-tables/WorkspaceDB";
|
||||
import { IconPlus, IconTag } from "@tabler/icons-react";
|
||||
import { MultiValue, Select } from "chakra-react-select";
|
||||
@@ -27,7 +25,6 @@ export default function AddTagToWorkflowPopover({ workflow }: Props) {
|
||||
const { onRefreshFilesList } = useContext(RecentFilesContext);
|
||||
const [allTags, setAllTags] = useState<Tag[]>([]);
|
||||
const [newTagName, setNewTagName] = useState("");
|
||||
const [submitError, setSubmitError] = useState(false);
|
||||
const initialTags =
|
||||
workflow.tags?.map((t) => ({
|
||||
value: t,
|
||||
@@ -38,18 +35,14 @@ export default function AddTagToWorkflowPopover({ workflow }: Props) {
|
||||
useState<MultiValue<{ value: string; label: string }>>(initialTags);
|
||||
|
||||
const addTag = async () => {
|
||||
const tagNameList =
|
||||
(await tagsTable?.listAll().then((list) => list.map((f) => f.name))) ??
|
||||
[];
|
||||
if (tagNameList.includes(newTagName)) {
|
||||
console.log(1111);
|
||||
setSubmitError(true);
|
||||
} else {
|
||||
await tagsTable?.create(newTagName);
|
||||
await tagsTable?.listAll().then((tags) => setAllTags(tags ?? []));
|
||||
setNewTagName("");
|
||||
setSubmitError(false);
|
||||
}
|
||||
await tagsTable?.put({
|
||||
id: newTagName,
|
||||
name: newTagName,
|
||||
workflowIDs: [],
|
||||
updateTime: Date.now(),
|
||||
});
|
||||
await tagsTable?.listAll().then((tags) => setAllTags(tags ?? []));
|
||||
setNewTagName("");
|
||||
};
|
||||
|
||||
const onOpen = async () => {
|
||||
@@ -141,14 +134,6 @@ export default function AddTagToWorkflowPopover({ workflow }: Props) {
|
||||
New Tag
|
||||
</Button>
|
||||
</HStack>
|
||||
{submitError ? (
|
||||
<Alert status="error" size="small">
|
||||
<AlertIcon />
|
||||
The name is duplicated, please modify it and submit again.
|
||||
</Alert>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</PopoverBody>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
@@ -10,7 +10,7 @@ export class TableBase<T> {
|
||||
protected constructor(tableName: Table) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
protected async saveDiskDB() {
|
||||
async saveDiskDB() {
|
||||
const objs = (await indexdb[this.tableName].toArray()) as TableBaseModel[];
|
||||
const backup: Record<string, TableBaseModel> = {};
|
||||
objs.forEach((f) => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { UserSettings } from "../types/dbTypes";
|
||||
import { TableBase } from "./TableBase";
|
||||
import { getSystemDir } from "../Api";
|
||||
|
||||
export class UserSettingsTable extends TableBase<UserSettings> {
|
||||
public defaultSettings: UserSettings;
|
||||
public readonly DEFAULT_USER = "guest";
|
||||
@@ -43,6 +45,8 @@ export class UserSettingsTable extends TableBase<UserSettings> {
|
||||
|
||||
static async load(): Promise<UserSettingsTable> {
|
||||
const instance = new UserSettingsTable();
|
||||
const getDir = await getSystemDir();
|
||||
instance.defaultSettings.myWorkflowsDir = `${getDir.dir_path}/my_workflows`;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import { MediaTable } from "./MediaTable";
|
||||
import { UserSettingsTable } from "./UserSettingsTable";
|
||||
import { TagsTable } from "./tagsTable";
|
||||
import { indexdb } from "./indexdb";
|
||||
import { Folder, UserSettings, Workflow } from "../types/dbTypes";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { getSystemDir } from "../Api";
|
||||
import { Folder, Workflow } from "../types/dbTypes";
|
||||
|
||||
export type Table =
|
||||
| "workflows"
|
||||
@@ -103,7 +101,7 @@ export async function backfillIndexdb() {
|
||||
// ID is a new field, compatible with the historical data of existing users.
|
||||
if (tagList.length > 0 && !tagList[0].id) {
|
||||
tagList.forEach((tag) => {
|
||||
tag.id = uuidv4();
|
||||
tag.id = tag.name;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,40 +112,18 @@ export async function backfillIndexdb() {
|
||||
};
|
||||
const backfillUserSettings = async () => {
|
||||
try {
|
||||
/**
|
||||
* In the new version, the data structure of the local disk backup of userSettings has changed, adding id, which is the user id.
|
||||
* Currently the default is set to Default User.
|
||||
* Therefore, the backfill needs to be compatible with the historical data of the original users.
|
||||
*/
|
||||
if (!userSettingsTable) return;
|
||||
let backupData = await userSettingsTable?.getRecords();
|
||||
if (Object.keys(backupData).length === 0) {
|
||||
// no local backup data
|
||||
backupData = {
|
||||
[userSettingsTable.DEFAULT_USER]: userSettingsTable.defaultSettings,
|
||||
};
|
||||
}
|
||||
|
||||
let backfillList;
|
||||
// If userId does not exist, it means that it is historical data and userId needs to be added.
|
||||
if (!backupData[userSettingsTable.DEFAULT_USER]) {
|
||||
backfillList = [
|
||||
{
|
||||
id: userSettingsTable.DEFAULT_USER,
|
||||
...backupData,
|
||||
},
|
||||
] as UserSettings[];
|
||||
} else {
|
||||
backfillList = Object.values(backupData);
|
||||
}
|
||||
if (!backfillList[0].myWorkflowsDir) {
|
||||
const getDir = await getSystemDir();
|
||||
const myWorkflowsDir = `${getDir.dir_path}/my_workflows`;
|
||||
backfillList[0].myWorkflowsDir = myWorkflowsDir;
|
||||
userSettingsTable!.defaultSettings.myWorkflowsDir = myWorkflowsDir;
|
||||
}
|
||||
await indexdb.userSettings.bulkAdd(backfillList);
|
||||
await userSettingsTable?.saveDiskDB();
|
||||
const tableInstance = userSettingsTable!;
|
||||
const backupData = await tableInstance.getRecords().then((data) => {
|
||||
if (!data[tableInstance.DEFAULT_USER]) {
|
||||
// legacy
|
||||
return data;
|
||||
}
|
||||
return data[tableInstance.DEFAULT_USER];
|
||||
});
|
||||
await indexdb.userSettings.put({
|
||||
...tableInstance.defaultSettings,
|
||||
...backupData,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class ManagerDB extends Dexie {
|
||||
|
||||
constructor() {
|
||||
super(WORKSPACE_INDEXDB_NAME);
|
||||
this.version(2)
|
||||
this.version(1)
|
||||
.stores({
|
||||
workflows: "&id, name, parentFolderID", // Primary key and indexed props
|
||||
changelogs: "&id, workflowID",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Tag } from "../types/dbTypes";
|
||||
import { Table } from "./WorkspaceDB";
|
||||
import { TableBase } from "./TableBase";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
export class TagsTable extends TableBase<Tag> {
|
||||
static readonly TABLE_NAME: Table = "tags";
|
||||
@@ -14,14 +13,4 @@ export class TagsTable extends TableBase<Tag> {
|
||||
const instance = new TagsTable();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public async create(name: string) {
|
||||
const newTag = {
|
||||
id: uuidv4(),
|
||||
name,
|
||||
workflowIDs: [],
|
||||
updateTime: Date.now(),
|
||||
};
|
||||
await this.add(newTag);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user