From 58d6b072f627216ea530f635c71466db33592ac0 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 13:39:52 +0300 Subject: [PATCH 01/58] Client:Store:AvatarEditorStore: delete --- .../client/src/store/AvatarEditorStore.js | 48 ------------------- packages/client/src/store/PeopleStore.js | 5 +- 2 files changed, 2 insertions(+), 51 deletions(-) delete mode 100644 packages/client/src/store/AvatarEditorStore.js diff --git a/packages/client/src/store/AvatarEditorStore.js b/packages/client/src/store/AvatarEditorStore.js deleted file mode 100644 index 0df7892bea..0000000000 --- a/packages/client/src/store/AvatarEditorStore.js +++ /dev/null @@ -1,48 +0,0 @@ -import { action, makeObservable, observable } from "mobx"; - -class AvatarEditorStore { - visible = false; - avatarMax = null; - createdAvatar = { - tmpFile: "", - image: null, - defaultWidth: 0, - defaultHeight: 0, - x: 0, - y: 0, - width: 0, - height: 0, - }; - croppedAvatar = null; - - constructor() { - makeObservable(this, { - visible: observable, - avatarMax: observable, - createdAvatar: observable, - croppedAvatar: observable, - toggleAvatarEditor: action, - setAvatarMax: action, - setCreatedAvatar: action, - setCroppedAvatar: action, - }); - } - - toggleAvatarEditor = (isVisible) => { - return (this.visible = isVisible); - }; - - setAvatarMax = (avatarMax) => { - return (this.avatarMax = avatarMax); - }; - - setCreatedAvatar = (avatar) => { - return (this.createdAvatar = avatar); - }; - - setCroppedAvatar = (croppedAvatar) => { - return (this.croppedAvatar = croppedAvatar); - }; -} - -export default AvatarEditorStore; diff --git a/packages/client/src/store/PeopleStore.js b/packages/client/src/store/PeopleStore.js index f791e855ee..2149f920f8 100644 --- a/packages/client/src/store/PeopleStore.js +++ b/packages/client/src/store/PeopleStore.js @@ -13,7 +13,7 @@ import EditingFormStore from "./EditingFormStore"; import FilterStore from "./FilterStore"; import SelectionStore from "./SelectionPeopleStore"; import HeaderMenuStore from "./HeaderMenuStore"; -import AvatarEditorStore from "./AvatarEditorStore"; + import InviteLinksStore from "./InviteLinksStore"; import DialogStore from "./DialogStore"; @@ -36,7 +36,7 @@ class PeopleStore { filterStore = null; selectionStore = null; headerMenuStore = null; - avatarEditorStore = null; + inviteLinksStore = null; dialogStore = null; setupStore = null; @@ -74,7 +74,6 @@ class PeopleStore { this.filterStore = new FilterStore(); this.selectionStore = new SelectionStore(this); this.headerMenuStore = new HeaderMenuStore(this); - this.avatarEditorStore = new AvatarEditorStore(this); this.inviteLinksStore = new InviteLinksStore(this); this.dialogStore = new DialogStore(); this.userStore = userStore; From 9d5c66e872dffd500902c3b1a3c11d9c7d1399c8 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 17:13:38 +0300 Subject: [PATCH 02/58] Client: add eslint and update tsconfig --- packages/client/.eslintrc.cjs | 10 ++++++++++ packages/client/package.json | 14 ++++++++++++++ packages/client/tsconfig.eslint.json | 17 +++++++++++++++++ packages/client/tsconfig.json | 19 +++++-------------- packages/shared/package.json | 1 - yarn.lock | 14 ++++++++++++++ 6 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 packages/client/.eslintrc.cjs create mode 100644 packages/client/tsconfig.eslint.json diff --git a/packages/client/.eslintrc.cjs b/packages/client/.eslintrc.cjs new file mode 100644 index 0000000000..2d54a41b0e --- /dev/null +++ b/packages/client/.eslintrc.cjs @@ -0,0 +1,10 @@ +module.exports = { + extends: "../shared/.eslintrc.cjs", + parserOptions: { + project: "tsconfig.eslint.json", + tsconfigRootDir: __dirname, + sourceType: "module", + }, + + ignorePatterns: ["./tsconfig.json", "coverage/**", "storybook-static/**"], +}; diff --git a/packages/client/package.json b/packages/client/package.json index cba193fbbd..7d14c388fc 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -59,6 +59,7 @@ }, "devDependencies": { "@babel/core": "^7.21.3", + "@babel/eslint-parser": "^7.21.8", "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-export-default-from": "^7.18.10", "@babel/plugin-transform-runtime": "^7.21.0", @@ -66,10 +67,23 @@ "@babel/preset-react": "^7.18.6", "@babel/preset-typescript": "^7.21.0", "@svgr/webpack": "^5.5.0", + "@types/eslint": "^8.44.7", + "@typescript-eslint/eslint-plugin": "^6.12.0", + "@typescript-eslint/parser": "^6.12.0", "babel-loader": "^8.3.0", "clean-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "^9.1.0", "css-loader": "^6.7.3", + "eslint": "^8.54.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-airbnb-typescript": "^17.1.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-jsx-a11y": "^6.8.0", + "eslint-plugin-prettier": "^5.0.1", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-storybook": "^0.6.15", "external-remotes-plugin": "^1.0.0", "file-loader": "^6.2.0", "html-loader": "^4.2.0", diff --git a/packages/client/tsconfig.eslint.json b/packages/client/tsconfig.eslint.json new file mode 100644 index 0000000000..037ebb9ba7 --- /dev/null +++ b/packages/client/tsconfig.eslint.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "include": [ + // 👇️ add all the directories and files + // that you want to lint here + "src", + // add all files in which you see + // the "parserOptions.project" error + ".eslintrc.cjs", + "__mocks__", + "jest.config.ts", + ".storybook", + "babel.config.ts", + "index.d.ts", + "tsconfig.eslint.json" + ] +} diff --git a/packages/client/tsconfig.json b/packages/client/tsconfig.json index b3a4c00f28..264823ce78 100644 --- a/packages/client/tsconfig.json +++ b/packages/client/tsconfig.json @@ -1,21 +1,12 @@ { + "extends": "../shared/tsconfig.json", "compilerOptions": { - "outDir": "./dist/", - "target": "es2016", - "jsx": "react-jsx", - "module": "ESNext", + "rootDir": "./", "baseUrl": "./", - "moduleResolution": "node", - - "strict": true, - "resolveJsonModule": true, - "esModuleInterop": true, - "skipLibCheck": true, - "allowJs": true, "paths": { "PUBLIC_DIR": ["../../public"], "COMMON_DIR": ["../common"], - "SRC_DIR": ["./src"] - } - } + "SRC_DIR": ["./src"], + }, + }, } diff --git a/packages/shared/package.json b/packages/shared/package.json index 4cfefb654a..f7bc3fa7d5 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -169,4 +169,3 @@ "react-dom": "^18.2.0" } } - diff --git a/yarn.lock b/yarn.lock index d873415e42..749943a73b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2958,6 +2958,7 @@ __metadata: resolution: "@docspace/client@workspace:packages/client" dependencies: "@babel/core": "npm:^7.21.3" + "@babel/eslint-parser": "npm:^7.21.8" "@babel/plugin-proposal-class-properties": "npm:^7.18.6" "@babel/plugin-proposal-export-default-from": "npm:^7.18.10" "@babel/plugin-transform-runtime": "npm:^7.21.0" @@ -2965,12 +2966,25 @@ __metadata: "@babel/preset-react": "npm:^7.18.6" "@babel/preset-typescript": "npm:^7.21.0" "@svgr/webpack": "npm:^5.5.0" + "@types/eslint": "npm:^8.44.7" + "@typescript-eslint/eslint-plugin": "npm:^6.12.0" + "@typescript-eslint/parser": "npm:^6.12.0" babel-loader: "npm:^8.3.0" clean-webpack-plugin: "npm:^4.0.0" copy-to-clipboard: "npm:^3.3.3" copy-webpack-plugin: "npm:^9.1.0" css-loader: "npm:^6.7.3" element-resize-detector: "npm:^1.2.4" + eslint: "npm:^8.54.0" + eslint-config-airbnb: "npm:^19.0.4" + eslint-config-airbnb-typescript: "npm:^17.1.0" + eslint-config-prettier: "npm:^9.0.0" + eslint-plugin-import: "npm:^2.29.0" + eslint-plugin-jsx-a11y: "npm:^6.8.0" + eslint-plugin-prettier: "npm:^5.0.1" + eslint-plugin-react: "npm:^7.33.2" + eslint-plugin-react-hooks: "npm:^4.6.0" + eslint-plugin-storybook: "npm:^0.6.15" external-remotes-plugin: "npm:^1.0.0" file-loader: "npm:^6.2.0" file-saver: "npm:^2.0.5" From b6f52e7a26f4e3338ce8ac26af981916db0ff5cc Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 17:15:39 +0300 Subject: [PATCH 03/58] Client: disable eslint for .js files --- packages/client/.eslintrc.cjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/client/.eslintrc.cjs b/packages/client/.eslintrc.cjs index 2d54a41b0e..39bf91784d 100644 --- a/packages/client/.eslintrc.cjs +++ b/packages/client/.eslintrc.cjs @@ -6,5 +6,10 @@ module.exports = { sourceType: "module", }, - ignorePatterns: ["./tsconfig.json", "coverage/**", "storybook-static/**"], + ignorePatterns: [ + "./tsconfig.json", + "coverage/**", + "storybook-static/**", + "*.js", + ], }; From a7b2564601ba6c298f7a0f6d3032698182cc4de9 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 19:35:01 +0300 Subject: [PATCH 04/58] Client: add prettier --- packages/client/.prettierrc.json | 3 +++ packages/client/package.json | 1 + yarn.lock | 1 + 3 files changed, 5 insertions(+) create mode 100644 packages/client/.prettierrc.json diff --git a/packages/client/.prettierrc.json b/packages/client/.prettierrc.json new file mode 100644 index 0000000000..558d71d1a8 --- /dev/null +++ b/packages/client/.prettierrc.json @@ -0,0 +1,3 @@ +{ + "extends": "../shared/.prettierrc.json" +} diff --git a/packages/client/package.json b/packages/client/package.json index 7d14c388fc..cbd52445fe 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -90,6 +90,7 @@ "html-webpack-plugin": "5.5.0", "json-loader": "^0.5.7", "playwright": "^1.32.0", + "prettier": "^3.1.0", "sass": "^1.59.3", "sass-loader": "^12.6.0", "serve": "14.2.0", diff --git a/yarn.lock b/yarn.lock index 749943a73b..78c0f381dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2994,6 +2994,7 @@ __metadata: html-webpack-plugin: "npm:5.5.0" json-loader: "npm:^0.5.7" playwright: "npm:^1.32.0" + prettier: "npm:^3.1.0" queue-promise: "npm:2.2.1" react-avatar-editor: "npm:^13.0.0" react-colorful: "npm:^5.6.1" From 3f4c795f0cc33ff7c3fafaaec39b509e262a45d8 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 19:35:21 +0300 Subject: [PATCH 05/58] Shared:Types: add new utils with typing stores --- packages/shared/types/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/shared/types/index.ts b/packages/shared/types/index.ts index 5ae187a848..8b0bf9f990 100644 --- a/packages/shared/types/index.ts +++ b/packages/shared/types/index.ts @@ -15,6 +15,15 @@ export type TViewAs = "tile" | "table" | "row" | "settings" | "profile"; export type TTranslation = (key: string) => string; +export type NonFunctionPropertyNames = { + [K in keyof T]: T[K] extends ExcludeTypes ? never : K; +}[keyof T]; + +export type NonFunctionProperties = Pick< + T, + NonFunctionPropertyNames +>; + export type TPathParts = { id: number; title: string; From 88b02355cc006a98d299520b3a781c00fff07a40 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 19:35:50 +0300 Subject: [PATCH 06/58] Client:Helpers:Utils: fix type setDocumentTitle --- packages/client/src/helpers/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/helpers/utils.js b/packages/client/src/helpers/utils.js index 1a10b8497e..ce178d39ca 100644 --- a/packages/client/src/helpers/utils.js +++ b/packages/client/src/helpers/utils.js @@ -7,7 +7,7 @@ import { FolderType, ShareAccessRights } from "@docspace/shared/enums"; import { translations } from "./autoGeneratedTranslations"; // import router from "SRC_DIR/router"; -export const setDocumentTitle = (subTitle = null) => { +export const setDocumentTitle = (subTitle = "") => { const { isAuthenticated, product: currentModule } = authStore; const { organizationName } = settingsStore; From e7205ba2788a62818e727b307b858f435e02a66c Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 19:36:15 +0300 Subject: [PATCH 07/58] Shared:Utils:Socket: update types --- packages/shared/utils/socket.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/utils/socket.ts b/packages/shared/utils/socket.ts index e335d9aa6f..d839325542 100644 --- a/packages/shared/utils/socket.ts +++ b/packages/shared/utils/socket.ts @@ -15,7 +15,7 @@ const subscribers = new Set(); export type TEmit = { command: string; - data: { roomParts: string | [] }; + data: { roomParts: string | []; individual?: boolean }; room?: null | boolean; }; From 071884ba003331c657ec37183fb8c33f10a05e23 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Fri, 26 Jan 2024 19:36:29 +0300 Subject: [PATCH 08/58] Client:Store:SelectedFolderStore: rewrite to typescript --- .../client/src/store/SelectedFolderStore.js | 219 ------------- .../client/src/store/SelectedFolderStore.ts | 304 ++++++++++++++++++ 2 files changed, 304 insertions(+), 219 deletions(-) delete mode 100644 packages/client/src/store/SelectedFolderStore.js create mode 100644 packages/client/src/store/SelectedFolderStore.ts diff --git a/packages/client/src/store/SelectedFolderStore.js b/packages/client/src/store/SelectedFolderStore.js deleted file mode 100644 index 496baad267..0000000000 --- a/packages/client/src/store/SelectedFolderStore.js +++ /dev/null @@ -1,219 +0,0 @@ -import { ShareAccessRights } from "@docspace/shared/enums"; -import { makeAutoObservable } from "mobx"; -import { setDocumentTitle } from "SRC_DIR/helpers/utils"; - -class SelectedFolderStore { - folders = null; - parentId = null; - filesCount = null; - foldersCount = null; - isShareable = null; - new = null; - id = null; - title = null; - access = null; - shared = null; - created = null; - createdBy = null; - updated = null; - updatedBy = null; - rootFolderType = null; - pathParts = null; - navigationPath = null; - providerItem = null; - providerKey = null; - providerId = null; - roomType = null; - pinned = null; - isRoom = null; - isArchive = null; - logo = null; - tags = null; - rootFolderId = null; - settingsStore = null; - security = null; - type = null; - inRoom = false; - isFolder = true; - - constructor(settingsStore) { - makeAutoObservable(this); - this.settingsStore = settingsStore; - } - - getSelectedFolder = () => { - return { - folders: this.folders, - parentId: this.parentId, - filesCount: this.filesCount, - foldersCount: this.foldersCount, - isShareable: this.isShareable, - new: this.new, - id: this.id, - title: this.title, - access: this.access, - shared: this.shared, - created: this.created, - createdBy: this.createdBy, - updated: this.updated, - updatedBy: this.updatedBy, - rootFolderType: this.rootFolderType, - pathParts: this.pathParts, - navigationPath: this.navigationPath, - providerItem: this.providerItem, - providerKey: this.providerKey, - providerId: this.providerId, - roomType: this.roomType, - pinned: this.pinned, - isRoom: this.isRoom, - logo: this.logo, - tags: this.tags, - rootFolderId: this.rootFolderId, - security: this.security, - inRoom: this.inRoom, - isFolder: this.isFolder, - }; - }; - - get isRootFolder() { - return this.pathParts && this.pathParts.length <= 1; - } - - get canCopyPublicLink() { - return ( - this.access === ShareAccessRights.RoomManager || - this.access === ShareAccessRights.None - ); - } - - toDefault = () => { - this.folders = null; - this.parentId = null; - this.filesCount = null; - this.foldersCount = null; - this.isShareable = null; - this.new = null; - this.id = null; - this.title = null; - this.access = null; - this.shared = null; - this.created = null; - this.createdBy = null; - this.updated = null; - this.updatedBy = null; - this.rootFolderType = null; - this.pathParts = null; - this.navigationPath = null; - this.providerItem = null; - this.providerKey = null; - this.providerId = null; - this.roomType = null; - this.pinned = null; - this.isRoom = null; - this.logo = null; - this.tags = null; - this.rootFolderId = null; - this.security = null; - this.type = null; - this.inRoom = false; - }; - - setParentId = (parentId) => { - this.parentId = parentId; - }; - - setRoomType = (roomType) => { - this.roomType = roomType; - }; - - setCreatedBy = (createdBy) => { - this.createdBy = createdBy; - }; - - setNavigationPath = (navigationPath) => { - this.navigationPath = navigationPath; - }; - - setShared = (shared) => { - this.shared = shared; - }; - - updateEditedSelectedRoom = (title = this.title, tags = this.tags) => { - this.title = title; - this.tags = tags; - }; - - setInRoom = (inRoom) => { - this.inRoom = inRoom; - }; - - addDefaultLogoPaths = () => { - const cachebreaker = new Date().getTime(); - this.logo = { - small: `/storage/room_logos/root/${this.id}_small.png?` + cachebreaker, - medium: `/storage/room_logos/root/${this.id}_medium.png?` + cachebreaker, - large: `/storage/room_logos/root/${this.id}_large.png?` + cachebreaker, - original: - `/storage/room_logos/root/${this.id}_original.png?` + cachebreaker, - }; - }; - - removeLogoPaths = () => { - this.logo = { - small: "", - medium: "", - large: "", - original: "", - }; - }; - - updateLogoPathsCacheBreaker = () => { - if (!this.logo.original) return; - - const cachebreaker = new Date().getTime(); - this.logo = { - small: this.logo.small.split("?")[0] + "?" + cachebreaker, - medium: this.logo.medium.split("?")[0] + "?" + cachebreaker, - large: this.logo.large.split("?")[0] + "?" + cachebreaker, - original: this.logo.original.split("?")[0] + "?" + cachebreaker, - }; - }; - - setSelectedFolder = (selectedFolder) => { - const { socketHelper } = this.settingsStore; - - if (this.id !== null) { - socketHelper.emit({ - command: "unsubscribe", - data: { roomParts: `DIR-${this.id}`, individual: true }, - }); - } - - if (selectedFolder) { - socketHelper.emit({ - command: "subscribe", - data: { roomParts: `DIR-${selectedFolder.id}`, individual: true }, - }); - } - - if (!selectedFolder) { - this.toDefault(); - } else { - const selectedFolderItems = Object.keys(selectedFolder); - - if (!selectedFolderItems.includes("roomType")) this.roomType = null; - - setDocumentTitle(selectedFolder.title); - - if (!selectedFolder.hasOwnProperty("type")) this.type = null; - - for (let key of selectedFolderItems) { - if (key in this) { - this[key] = selectedFolder[key]; - } - } - } - }; -} - -export default SelectedFolderStore; diff --git a/packages/client/src/store/SelectedFolderStore.ts b/packages/client/src/store/SelectedFolderStore.ts new file mode 100644 index 0000000000..d80ade6263 --- /dev/null +++ b/packages/client/src/store/SelectedFolderStore.ts @@ -0,0 +1,304 @@ +import { makeAutoObservable } from "mobx"; + +import { SettingsStore } from "@docspace/shared/store/SettingsStore"; +import { + FolderType, + RoomsType, + ShareAccessRights, +} from "@docspace/shared/enums"; +import { + NonFunctionProperties, + NonFunctionPropertyNames, + TCreatedBy, + TPathParts, +} from "@docspace/shared/types"; +import { TFolder, TFolderSecurity } from "@docspace/shared/api/files/types"; +import { TLogo, TRoomSecurity } from "@docspace/shared/api/rooms/types"; + +import { setDocumentTitle } from "../helpers/utils"; + +export type TNavigationPath = { + id: number; + title: string; + isRoom: boolean; + roomType: RoomsType; + isRootRoom: boolean; + shared: boolean; + canCopyPublicLink: boolean; +}; + +type ExcludeTypes = SettingsStore | Function; + +export type TSelectedFolder = NonFunctionProperties< + SelectedFolderStore, + ExcludeTypes +>; + +export type TSetSelectedFolder = { + [key in NonFunctionPropertyNames< + SelectedFolderStore, + ExcludeTypes + >]?: TSelectedFolder[key]; +}; + +class SelectedFolderStore { + folders: TFolder[] | null = null; + + parentId = 0; + + filesCount = 0; + + foldersCount = 0; + + isShareable = false; + + new = 0; + + id: number | string | null = null; + + title: string = ""; + + access: ShareAccessRights | null = null; + + shared = false; + + created: Date | null = null; + + createdBy: TCreatedBy | null = null; + + updated: Date | null = null; + + updatedBy: TCreatedBy | null = null; + + rootFolderType: FolderType | null = null; + + pathParts: TPathParts[] = []; + + navigationPath: TNavigationPath[] = []; + + providerItem = null; + + providerKey = null; + + providerId = null; + + roomType: RoomsType | null = null; + + pinned = false; + + isRoom = false; + + isArchive = false; + + logo: TLogo | null = null; + + tags: string[] = []; + + rootFolderId: number = 0; + + settingsStore: SettingsStore = {} as SettingsStore; + + security: TFolderSecurity | TRoomSecurity | null = null; + + type = null; + + inRoom = false; + + isFolder = true; + + mute = false; + + private = false; + + canShare = false; + + constructor(settingsStore: SettingsStore) { + makeAutoObservable(this); + this.settingsStore = settingsStore; + } + + getSelectedFolder: () => TSelectedFolder = () => { + return { + folders: this.folders, + parentId: this.parentId, + filesCount: this.filesCount, + foldersCount: this.foldersCount, + isShareable: this.isShareable, + new: this.new, + id: this.id, + title: this.title, + access: this.access, + shared: this.shared, + created: this.created, + createdBy: this.createdBy, + updated: this.updated, + updatedBy: this.updatedBy, + rootFolderType: this.rootFolderType, + pathParts: this.pathParts, + navigationPath: this.navigationPath, + providerItem: this.providerItem, + providerKey: this.providerKey, + providerId: this.providerId, + roomType: this.roomType, + pinned: this.pinned, + isRoom: this.isRoom, + logo: this.logo, + tags: this.tags, + rootFolderId: this.rootFolderId, + security: this.security, + inRoom: this.inRoom, + isFolder: this.isFolder, + mute: this.mute, + private: this.private, + canShare: this.canShare, + isArchive: this.isArchive, + canCopyPublicLink: this.canCopyPublicLink, + type: this.type, + isRootFolder: this.isRootFolder, + }; + }; + + get isRootFolder() { + return this.pathParts && this.pathParts.length <= 1; + } + + get canCopyPublicLink() { + return ( + this.access === ShareAccessRights.RoomManager || + this.access === ShareAccessRights.None + ); + } + + toDefault = () => { + this.folders = null; + this.parentId = 0; + this.filesCount = 0; + this.foldersCount = 0; + this.isShareable = false; + this.new = 0; + this.id = 0; + this.title = ""; + this.access = null; + this.shared = false; + this.created = null; + this.createdBy = null; + this.updated = null; + this.updatedBy = null; + this.rootFolderType = null; + this.pathParts = []; + this.navigationPath = []; + this.providerItem = null; + this.providerKey = null; + this.providerId = null; + this.roomType = null; + this.pinned = false; + this.isRoom = false; + this.logo = null; + this.tags = []; + this.rootFolderId = 0; + this.security = null; + this.type = null; + this.inRoom = false; + }; + + setParentId = (parentId: number) => { + this.parentId = parentId; + }; + + setRoomType = (roomType: RoomsType) => { + this.roomType = roomType; + }; + + setCreatedBy = (createdBy: TCreatedBy) => { + this.createdBy = createdBy; + }; + + setNavigationPath = (navigationPath: TNavigationPath[]) => { + this.navigationPath = navigationPath; + }; + + setShared = (shared: boolean) => { + this.shared = shared; + }; + + updateEditedSelectedRoom = (title = this.title, tags = this.tags) => { + this.title = title; + this.tags = tags; + }; + + setInRoom = (inRoom: boolean) => { + this.inRoom = inRoom; + }; + + addDefaultLogoPaths = () => { + const cachebreaker = new Date().getTime(); + this.logo = { + small: `/storage/room_logos/root/${this.id}_small.png?${cachebreaker}`, + medium: `/storage/room_logos/root/${this.id}_medium.png?${cachebreaker}`, + large: `/storage/room_logos/root/${this.id}_large.png?${cachebreaker}`, + original: `/storage/room_logos/root/${this.id}_original.png?${cachebreaker}`, + }; + }; + + removeLogoPaths = () => { + this.logo = { + small: "", + medium: "", + large: "", + original: "", + }; + }; + + updateLogoPathsCacheBreaker = () => { + if (!this.logo?.original) return; + + const cachebreaker = new Date().getTime(); + this.logo = { + small: `${this.logo.small.split("?")[0]}?${cachebreaker}`, + medium: `${this.logo.medium.split("?")[0]}?${cachebreaker}`, + large: `${this.logo.large.split("?")[0]}?${cachebreaker}`, + original: `${this.logo.original.split("?")[0]}?${cachebreaker}`, + }; + }; + + setSelectedFolder: (selectedFolder: TSetSelectedFolder | null) => void = ( + selectedFolder, + ) => { + const socketHelper = this.settingsStore?.socketHelper; + + if (this.id !== null && socketHelper) { + socketHelper.emit({ + command: "unsubscribe", + data: { roomParts: `DIR-${this.id}`, individual: true }, + }); + } + + if (selectedFolder && socketHelper) { + socketHelper.emit({ + command: "subscribe", + data: { roomParts: `DIR-${selectedFolder.id}`, individual: true }, + }); + } + + if (!selectedFolder) { + this.toDefault(); + } else { + const selectedFolderItems = Object.keys(selectedFolder); + + if (!selectedFolderItems.includes("roomType")) this.roomType = null; + + setDocumentTitle(selectedFolder.title); + + if (!("type" in selectedFolder)) this.type = null; + + Object.entries(selectedFolder).forEach(([key, item]) => { + if (key in this) { + // @ts-expect-error its always be good + this[key] = item; + } + }); + } + }; +} + +export default SelectedFolderStore; From 64013053581ea0a420dcedca591908c21ee2bc01 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Mon, 29 Jan 2024 13:07:02 +0300 Subject: [PATCH 09/58] Client:Store:PluginsStore: rewrite to typescript --- packages/client/index.d.ts | 2 +- .../components/dialogs/PluginDialog/index.js | 6 +- .../dialogs/SettingsPluginDialog/index.js | 2 +- .../sub-components/Info.js | 4 +- .../src/helpers/plugins/WrappedComponent.js | 18 +- .../src/helpers/plugins/components/Plugin.js | 4 +- .../helpers/plugins/components/PluginInfo.js | 2 +- .../plugins/components/PluginSettings.js | 2 +- .../client/src/helpers/plugins/constants.js | 87 ---- packages/client/src/helpers/plugins/enums.ts | 97 ++++ packages/client/src/helpers/plugins/types.ts | 275 +++++++++++ packages/client/src/helpers/plugins/utils.js | 8 +- .../Home/InfoPanel/Body/views/Plugin/index.js | 2 +- .../src/pages/Home/InfoPanel/Header/index.js | 8 +- .../src/pages/Home/MediaViewer/index.js | 6 +- .../Plugins/sub-components/plugin.js | 2 +- packages/client/src/store/FilesStore.js | 140 +++--- .../store/{PluginStore.js => PluginStore.ts} | 430 ++++++++++-------- .../client/src/store/SelectedFolderStore.ts | 2 +- packages/client/tsconfig.json | 5 +- 20 files changed, 718 insertions(+), 384 deletions(-) delete mode 100644 packages/client/src/helpers/plugins/constants.js create mode 100644 packages/client/src/helpers/plugins/enums.ts create mode 100644 packages/client/src/helpers/plugins/types.ts rename packages/client/src/store/{PluginStore.js => PluginStore.ts} (67%) diff --git a/packages/client/index.d.ts b/packages/client/index.d.ts index c3ab6153bb..27cac0ad3f 100644 --- a/packages/client/index.d.ts +++ b/packages/client/index.d.ts @@ -1,5 +1,5 @@ interface Window { - zESettings?: any; + zESettings?: unknown; zE?: { apply: Function; }; diff --git a/packages/client/src/components/dialogs/PluginDialog/index.js b/packages/client/src/components/dialogs/PluginDialog/index.js index d10a893730..99acd9cece 100644 --- a/packages/client/src/components/dialogs/PluginDialog/index.js +++ b/packages/client/src/components/dialogs/PluginDialog/index.js @@ -7,7 +7,7 @@ import { Portal } from "@docspace/shared/components/portal"; import { Base } from "@docspace/shared/themes"; import WrappedComponent from "SRC_DIR/helpers/plugins/WrappedComponent"; -import { PluginComponents } from "SRC_DIR/helpers/plugins/constants"; +import { PluginComponents } from "SRC_DIR/helpers/plugins/enums"; import { messageActions } from "SRC_DIR/helpers/plugins/utils"; const StyledFullScreen = styled.div` @@ -83,7 +83,7 @@ const PluginDialog = ({ updateMainButtonItems, updateProfileMenuItems, updateEventListenerItems, - updateFileItems + updateFileItems, ); }; @@ -111,7 +111,7 @@ const PluginDialog = ({ updateMainButtonItems, updateProfileMenuItems, updateEventListenerItems, - updateFileItems + updateFileItems, ); }; diff --git a/packages/client/src/components/dialogs/SettingsPluginDialog/index.js b/packages/client/src/components/dialogs/SettingsPluginDialog/index.js index 4673e85249..ce6a319db8 100644 --- a/packages/client/src/components/dialogs/SettingsPluginDialog/index.js +++ b/packages/client/src/components/dialogs/SettingsPluginDialog/index.js @@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next"; import { Button } from "@docspace/shared/components/button"; import { ModalDialog } from "@docspace/shared/components/modal-dialog"; -import { PluginComponents } from "SRC_DIR/helpers/plugins/constants"; +import { PluginComponents } from "SRC_DIR/helpers/plugins/enums"; import WrappedComponent from "SRC_DIR/helpers/plugins/WrappedComponent"; import Header from "./sub-components/Header"; diff --git a/packages/client/src/components/dialogs/SettingsPluginDialog/sub-components/Info.js b/packages/client/src/components/dialogs/SettingsPluginDialog/sub-components/Info.js index bffd3e9e08..e19686ffbf 100644 --- a/packages/client/src/components/dialogs/SettingsPluginDialog/sub-components/Info.js +++ b/packages/client/src/components/dialogs/SettingsPluginDialog/sub-components/Info.js @@ -7,7 +7,7 @@ import { Text } from "@docspace/shared/components/text"; import { Link } from "@docspace/shared/components/link"; import { getCorrectDate, getCookie } from "@docspace/shared/utils"; -import { PluginStatus } from "SRC_DIR/helpers/plugins/constants"; +import { PluginStatus } from "SRC_DIR/helpers/plugins/enums"; import { Base } from "@docspace/shared/themes"; const StyledContainer = styled.div` @@ -121,7 +121,7 @@ const Info = ({ t, plugin, withDelete, withSeparator }) => { lineHeight={"20px"} noSelect > - {plugin.createBy} + {plugin.createBy.displayName} )} diff --git a/packages/client/src/helpers/plugins/WrappedComponent.js b/packages/client/src/helpers/plugins/WrappedComponent.js index 611ac464c4..202947fd6f 100644 --- a/packages/client/src/helpers/plugins/WrappedComponent.js +++ b/packages/client/src/helpers/plugins/WrappedComponent.js @@ -13,7 +13,7 @@ import { Button } from "@docspace/shared/components/button"; import { ToggleButton } from "@docspace/shared/components/toggle-button"; import { ComboBox } from "@docspace/shared/components/combobox"; -import { PluginComponents } from "./constants"; +import { PluginComponents } from "./enums"; import { messageActions } from "./utils"; @@ -74,7 +74,7 @@ const ComponentPure = ({ component={item} pluginName={pluginName} /> - ) + ), ); return {childrenComponents}; @@ -110,7 +110,7 @@ const ComponentPure = ({ updateMainButtonItems, updateProfileMenuItems, updateEventListenerItems, - updateFileItems + updateFileItems, ); }; @@ -139,7 +139,7 @@ const ComponentPure = ({ updateMainButtonItems, updateProfileMenuItems, updateEventListenerItems, - updateFileItems + updateFileItems, ); }; @@ -168,11 +168,11 @@ const ComponentPure = ({ updateMainButtonItems, updateProfileMenuItems, updateEventListenerItems, - updateFileItems + updateFileItems, ); }; - return