@progressive-development/pd-spa-helper 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/service-provider/firebase/firestorage-client.d.ts +1 -0
- package/dist/src/service-provider/firebase/firestorage-client.js +22 -1
- package/dist/src/service-provider/firebase/firestorage-client.js.map +1 -1
- package/dist/src/service-provider/mock/storage-client.d.ts +2 -1
- package/dist/src/service-provider/mock/storage-client.js +7 -2
- package/dist/src/service-provider/mock/storage-client.js.map +1 -1
- package/dist/src/service-provider/service-provider-impl.d.ts +1 -0
- package/dist/src/service-provider/service-provider-impl.js +11 -2
- package/dist/src/service-provider/service-provider-impl.js.map +1 -1
- package/dist/src/service-provider/service-provider-model.d.ts +2 -0
- package/dist/src/service-provider/service-provider-model.js.map +1 -1
- package/dist/src/store/spa-app-selector.js +1 -1
- package/dist/src/store/spa-app-selector.js.map +1 -1
- package/dist/src/stories/pd-loading-state.stories.d.ts +1 -0
- package/dist/src/stories/pd-loading-state.stories.js +27 -0
- package/dist/src/stories/pd-loading-state.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/service-provider/firebase/firestorage-client.ts +26 -1
- package/src/service-provider/mock/storage-client.ts +8 -2
- package/src/service-provider/service-provider-impl.ts +16 -3
- package/src/service-provider/service-provider-model.ts +2 -0
- package/src/store/spa-app-selector.ts +1 -1
- package/src/stories/pd-loading-state.stories.ts +28 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FirebaseApp } from 'firebase/app';
|
|
2
|
-
import { FirebaseStorage, FullMetadata, StorageReference, UploadResult, getMetadata, getStorage, listAll, ref, uploadString } from "firebase/storage";
|
|
2
|
+
import { FirebaseStorage, FullMetadata, StorageReference, UploadResult, getDownloadURL, getMetadata, getStorage, listAll, ref, uploadString } from "firebase/storage";
|
|
3
3
|
|
|
4
4
|
import { FileStorageConfig, StorageDocument, UploadFile } from '../service-provider-model.js';
|
|
5
5
|
import { getUser } from '../service-provider-impl.js';
|
|
@@ -131,6 +131,7 @@ export const getFirestorageFileList = (
|
|
|
131
131
|
itemRefs.push({
|
|
132
132
|
fileName: itemRef.name,
|
|
133
133
|
filePath: itemRef.fullPath,
|
|
134
|
+
storageName, refKey
|
|
134
135
|
});
|
|
135
136
|
|
|
136
137
|
// MetaData for each item with own promise
|
|
@@ -163,6 +164,30 @@ export const getFirestorageFileList = (
|
|
|
163
164
|
|
|
164
165
|
};
|
|
165
166
|
|
|
167
|
+
export const downloadFileFirestorage = (file: StorageDocument) => {
|
|
168
|
+
|
|
169
|
+
if (!storageMap || storageMap.size === 0) {
|
|
170
|
+
throw new Error("No storage is configured");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// get storage
|
|
174
|
+
const storageConf = storageMap.get(file.storageName);
|
|
175
|
+
if (!storageConf ) {
|
|
176
|
+
throw new Error(`Invalid storage name: ${file.storageName}`);
|
|
177
|
+
}
|
|
178
|
+
if (!storageConf.references || storageConf.references.length === 0) {
|
|
179
|
+
throw new Error(`No references configured for storage: ${file.storageName}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// get refrence
|
|
183
|
+
const storageRef = storageConf.references.filter(refIt => refIt.key === file.refKey)[0];
|
|
184
|
+
if (!storageRef) {
|
|
185
|
+
throw new Error(`No reference available for storage: ${file.storageName} and ref: ${file.refKey}`);
|
|
186
|
+
}
|
|
187
|
+
const usedRef = ref(storageRef.storageRef, file.filePath);
|
|
188
|
+
return getDownloadURL(usedRef);
|
|
189
|
+
}
|
|
190
|
+
|
|
166
191
|
|
|
167
192
|
/* Firestorage Error List: https://firebase.google.com/docs/storage/web/handle-errors */
|
|
168
193
|
/*
|
|
@@ -124,17 +124,23 @@ export const uploadStorageFileMock = (file: UploadFile):Promise<any> => {
|
|
|
124
124
|
return storageConf.storage.uploadFile(fileRef, file);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
+
export const downloadFileMock = (file: StorageDocument) => {
|
|
128
|
+
alert("Not implemented for mock");
|
|
129
|
+
return Promise.resolve("");
|
|
130
|
+
}
|
|
131
|
+
|
|
127
132
|
export const getMockFileList = (
|
|
128
133
|
storageName: string,
|
|
129
|
-
|
|
134
|
+
refKey: string,
|
|
130
135
|
subFolder?: string,
|
|
131
136
|
includeMetadata?: boolean
|
|
132
137
|
):Promise<StorageDocument[]> => {
|
|
133
|
-
console.log("Searching for Documents in ", storageName,
|
|
138
|
+
console.log("Searching for Documents in ", storageName, refKey, subFolder, includeMetadata);
|
|
134
139
|
return Promise.resolve([{
|
|
135
140
|
fileName: "workReport.png",
|
|
136
141
|
filePath: "workReports/1234234f2fswf/workReport.png",
|
|
137
142
|
documentType: "ToDo",
|
|
143
|
+
storageName, refKey
|
|
138
144
|
}]);
|
|
139
145
|
};
|
|
140
146
|
|
|
@@ -2,13 +2,16 @@ import { FirebaseApp, FirebaseOptions, initializeApp } from "firebase/app";
|
|
|
2
2
|
|
|
3
3
|
import { authStateChanged, getAuthUser, initAuth, isAuthenticated, login, logout } from "./firebase/auth.js";
|
|
4
4
|
import { authStateChangedMock, getAuthUserMock, isAuthenticatedMock, loginMock, logoutMock } from "./mock/auth.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
AppConfiguration, FileStorageConfig, FunctionDefinition, FunctionResult,
|
|
7
|
+
FunctionsConfig, ServiceProviderConfiguration, StorageDocument, UploadFile
|
|
8
|
+
} from "./service-provider-model.js";
|
|
6
9
|
import { callFunction, initFunctions } from "./firebase/functions-client.js";
|
|
7
10
|
import { initFirestore } from "./firebase/firestore-client.js";
|
|
8
11
|
import { callFunctionMock, initMockResponse } from "./mock/function-client.js";
|
|
9
12
|
import { ServiceCallController } from "../service-call-controller2.js";
|
|
10
|
-
import { getFirestorageFileList, initFirestorage, uploadFirestorageFile } from "./firebase/firestorage-client.js";
|
|
11
|
-
import { getMockFileList, initStorageMock, uploadStorageFileMock } from "./mock/storage-client.js";
|
|
13
|
+
import { downloadFileFirestorage, getFirestorageFileList, initFirestorage, uploadFirestorageFile } from "./firebase/firestorage-client.js";
|
|
14
|
+
import { downloadFileMock, getMockFileList, initStorageMock, uploadStorageFileMock } from "./mock/storage-client.js";
|
|
12
15
|
|
|
13
16
|
let provider: ServiceProviderConfiguration | undefined;
|
|
14
17
|
let controller: ServiceCallController;
|
|
@@ -181,4 +184,14 @@ export const getStorageFileList = (
|
|
|
181
184
|
return getMockFileList(storageName, keyRef, subFolder, includeMetadata);
|
|
182
185
|
}
|
|
183
186
|
return throwUndefinedProviderError();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export const downloadFile = (file: StorageDocument): Promise<unknown> => {
|
|
190
|
+
if (provider === "firebase") {
|
|
191
|
+
return downloadFileFirestorage(file);
|
|
192
|
+
}
|
|
193
|
+
if (provider === "mock") {
|
|
194
|
+
return downloadFileMock(file)
|
|
195
|
+
}
|
|
196
|
+
return throwUndefinedProviderError();
|
|
184
197
|
}
|
|
@@ -7,7 +7,7 @@ const getSpaAppFeatureState = createFeatureStateSelector<SpaAppState>('spaApp');
|
|
|
7
7
|
export const getLoadingSelector = createSelector(
|
|
8
8
|
getSpaAppFeatureState,
|
|
9
9
|
state => {
|
|
10
|
-
// filter add only the oldest for each typ
|
|
10
|
+
// filter add only the oldest for each typ (avoid overlapping loading boxes with different size)
|
|
11
11
|
const orderByCreation = [...state.loadingState].sort(
|
|
12
12
|
(a, b) => (a.creation?.getMilliseconds() || 0) - (b.creation?.getMilliseconds() || 0)
|
|
13
13
|
);
|
|
@@ -138,3 +138,31 @@ export const ModalStateWithSubTasks: Story = {
|
|
|
138
138
|
},
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
+
export const BackgroundWithSubTasks: Story = {
|
|
142
|
+
args: {
|
|
143
|
+
loadingState: {
|
|
144
|
+
isLoading: true,
|
|
145
|
+
modal: false,
|
|
146
|
+
smallBackground: true,
|
|
147
|
+
loadingTxt: "Sammelaufgabe wird erledigt",
|
|
148
|
+
subTask: [
|
|
149
|
+
{
|
|
150
|
+
actionKey: "",
|
|
151
|
+
completed: true,
|
|
152
|
+
loadingTxt: "SubTask 1"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
actionKey: "",
|
|
156
|
+
completed: false,
|
|
157
|
+
loadingTxt: "SubTask 2"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
actionKey: "",
|
|
161
|
+
completed: false,
|
|
162
|
+
loadingTxt: "SubTask 3"
|
|
163
|
+
},
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|