Skip to content

Commit c4f0d02

Browse files
committed
Refactor getDefaultProjectStorageType to enhance storage type determination logic and add isSwitchingStorageType function
1 parent c4cdf8d commit c4f0d02

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

packages/insomnia/src/models/project.ts

+49-7
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,71 @@ export function isDefaultOrganizationProject(project: Project) {
9494
}
9595

9696
export function getDefaultProjectStorageType(storageRules: StorageRules, project?: Project): 'local' | 'remote' | 'git' {
97-
if (storageRules.enableCloudSync && !storageRules.enableLocalVault && !storageRules.enableGitSync) {
98-
return 'remote';
99-
}
97+
// When the project exist. That means the user open the settings modal
98+
if (project) {
99+
if (isGitProject(project)) {
100+
if (storageRules.enableGitSync) {
101+
return 'git';
102+
}
103+
if (storageRules.enableLocalVault) {
104+
return 'local';
105+
}
106+
return 'remote';
107+
}
100108

101-
if (storageRules.enableCloudSync && storageRules.enableLocalVault) {
102-
if (project && isGitProject(project)) {
109+
if (isRemoteProject(project)) {
110+
if (storageRules.enableCloudSync) {
111+
return 'remote';
112+
}
113+
if (storageRules.enableLocalVault) {
114+
return 'local';
115+
}
103116
return 'git';
104117
}
105118

106-
if (project && isRemoteProject(project)) {
119+
if (storageRules.enableLocalVault) {
120+
return 'local';
121+
}
122+
123+
if (storageRules.enableCloudSync) {
107124
return 'remote';
108125
}
109126

127+
return 'git';
128+
}
129+
130+
// When the project doesn't exist. That means the user create a new project
131+
if (storageRules.enableLocalVault) {
110132
return 'local';
111133
}
112134

113-
if (project && isGitProject(project)) {
135+
if (storageRules.enableCloudSync) {
136+
return 'remote';
137+
}
138+
139+
if (storageRules.enableGitSync) {
114140
return 'git';
115141
}
116142

117143
return 'local';
118144
}
119145

146+
export function isSwitchingStorageType(project: Project, storageType: 'local' | 'remote' | 'git') {
147+
if (storageType === 'git' && !isGitProject(project)) {
148+
return true;
149+
}
150+
151+
if (storageType === 'local' && (isRemoteProject(project) || isGitProject(project))) {
152+
return true;
153+
}
154+
155+
if (storageType === 'remote' && !isRemoteProject(project)) {
156+
return true;
157+
}
158+
159+
return false;
160+
}
161+
120162
export function getProjectStorageTypeLabel(storageRules: StorageRules): string {
121163
const storageTypes = {
122164
'Cloud Sync': storageRules.enableCloudSync,

0 commit comments

Comments
 (0)