@scality/core-ui 0.136.0 → 0.137.0
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/organisms/attachments/AttachmentConfirmationModal.d.ts +4 -3
- package/dist/organisms/attachments/AttachmentConfirmationModal.d.ts.map +1 -1
- package/dist/organisms/attachments/AttachmentConfirmationModal.js +1 -0
- package/dist/organisms/attachments/AttachmentTable.d.ts +10 -10
- package/dist/organisms/attachments/AttachmentTable.d.ts.map +1 -1
- package/dist/organisms/attachments/AttachmentTypes.d.ts +4 -3
- package/dist/organisms/attachments/AttachmentTypes.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/lib/organisms/attachments/AttachmentConfirmationModal.tsx +11 -5
- package/src/lib/organisms/attachments/AttachmentTable.tsx +53 -29
- package/src/lib/organisms/attachments/AttachmentTypes.ts +10 -3
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { UseMutationOptions } from 'react-query';
|
|
3
3
|
import { AttachmentOperation, AttachmentAction } from './AttachmentTypes';
|
|
4
|
-
export declare function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>({ attachmentOperations, getAttachmentMutationOptions, resourceType, resourceName, redirectUrl, EntityIcon, cancelButtonDisabled, onCancel, onExit, }: {
|
|
5
|
-
attachmentOperations: AttachmentOperation<ENTITY_TYPE>[];
|
|
4
|
+
export declare function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE, ENTITY extends Record<string, unknown> = Record<string, unknown>>({ attachmentOperations, getAttachmentMutationOptions, resourceType, resourceName, redirectUrl, EntityIcon, cancelButtonDisabled, onCancel, onExit, }: {
|
|
5
|
+
attachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
6
6
|
getAttachmentMutationOptions: () => UseMutationOptions<unknown, unknown, {
|
|
7
7
|
action: AttachmentAction;
|
|
8
8
|
type: ENTITY_TYPE;
|
|
9
9
|
entityName: string;
|
|
10
10
|
id: string;
|
|
11
|
+
completeEntity?: ENTITY;
|
|
11
12
|
}>;
|
|
12
13
|
resourceName: string;
|
|
13
14
|
resourceType: RESOURCE_TYPE;
|
|
@@ -17,6 +18,6 @@ export declare function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>(
|
|
|
17
18
|
}>;
|
|
18
19
|
cancelButtonDisabled?: boolean;
|
|
19
20
|
onCancel?: () => void;
|
|
20
|
-
onExit?: (successfullOperations: AttachmentOperation<ENTITY_TYPE>[], failedOperations: AttachmentOperation<ENTITY_TYPE>[]) => void;
|
|
21
|
+
onExit?: (successfullOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[], failedOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[]) => void;
|
|
21
22
|
}): JSX.Element;
|
|
22
23
|
//# sourceMappingURL=AttachmentConfirmationModal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentConfirmationModal.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentConfirmationModal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAY,MAAM,OAAO,CAAC;AAGhD,OAAO,EAAe,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1E,wBAAgB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"AttachmentConfirmationModal.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentConfirmationModal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAY,MAAM,OAAO,CAAC;AAGhD,OAAO,EAAe,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1E,wBAAgB,2BAA2B,CACzC,WAAW,EACX,aAAa,EACb,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,EACA,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,QAAQ,EACR,MAAM,GACP,EAAE;IACD,oBAAoB,EAAE,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;IACjE,4BAA4B,EAAE,MAAM,kBAAkB,CACpD,OAAO,EACP,OAAO,EACP;QACE,MAAM,EAAE,gBAAgB,CAAC;QACzB,IAAI,EAAE,WAAW,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CACF,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,aAAa,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAAA;KAAE,CAAC,CAAC;IACjE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,CACP,qBAAqB,EAAE,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EACjE,gBAAgB,EAAE,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KACzD,IAAI,CAAC;CACX,eA0QA"}
|
|
@@ -30,6 +30,7 @@ export function AttachmentConfirmationModal({ attachmentOperations, getAttachmen
|
|
|
30
30
|
type: attachmentOperation.entity.type,
|
|
31
31
|
entityName: attachmentOperation.entity.name,
|
|
32
32
|
id: attachmentOperation.entity.id,
|
|
33
|
+
completeEntity: attachmentOperation.entity.completeEntity,
|
|
33
34
|
};
|
|
34
35
|
});
|
|
35
36
|
const attach = () => {
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { AttachableEntity, AttachmentOperation } from './AttachmentTypes';
|
|
3
3
|
import { UseQueryOptions } from 'react-query';
|
|
4
|
-
export type AttachmentTableProps<ENTITY_TYPE> = {
|
|
5
|
-
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE>[];
|
|
4
|
+
export type AttachmentTableProps<ENTITY_TYPE, ENTITY extends Record<string, unknown> = Record<string, unknown>> = {
|
|
5
|
+
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
6
6
|
initiallyAttachedEntitiesStatus: 'idle' | 'loading' | 'success' | 'error';
|
|
7
|
-
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE>[];
|
|
7
|
+
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
8
8
|
entityName: {
|
|
9
9
|
plural: string;
|
|
10
10
|
singular: string;
|
|
11
11
|
};
|
|
12
|
-
getNameQuery?: (entity: AttachableEntity<ENTITY_TYPE>) => UseQueryOptions<unknown, unknown, string>;
|
|
12
|
+
getNameQuery?: (entity: AttachableEntity<ENTITY_TYPE, ENTITY>) => UseQueryOptions<unknown, unknown, string>;
|
|
13
13
|
searchEntityPlaceholder: string;
|
|
14
|
-
onAttachmentsOperationsChanged: (attachmentOperations: AttachmentOperation<ENTITY_TYPE>[]) => void;
|
|
14
|
+
onAttachmentsOperationsChanged: (attachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[]) => void;
|
|
15
15
|
filteredEntities: {
|
|
16
16
|
status: 'idle';
|
|
17
17
|
} | {
|
|
18
18
|
status: 'loading' | 'error';
|
|
19
19
|
data?: {
|
|
20
20
|
number: number;
|
|
21
|
-
entities: AttachableEntity<ENTITY_TYPE>[];
|
|
21
|
+
entities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
22
22
|
};
|
|
23
23
|
} | {
|
|
24
24
|
status: 'success';
|
|
25
25
|
data: {
|
|
26
26
|
number: number;
|
|
27
|
-
entities: AttachableEntity<ENTITY_TYPE>[];
|
|
27
|
+
entities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
onEntitySearchChange: (search?: string) => void;
|
|
31
31
|
};
|
|
32
|
-
export declare const AttachmentProvider: <ENTITY_TYPE extends unknown>({ children, }: PropsWithChildren<{}>) => JSX.Element;
|
|
32
|
+
export declare const AttachmentProvider: <ENTITY_TYPE extends unknown, ENTITY extends Record<string, unknown> = Record<string, unknown>>({ children, }: PropsWithChildren<{}>) => JSX.Element;
|
|
33
33
|
export declare const useAttachmentOperations: () => {
|
|
34
|
-
resetAttachmentTable: (initiallyAttachedEntities: AttachableEntity<any>[], initialAttachmentOperations: AttachmentOperation<any>[]) => void;
|
|
34
|
+
resetAttachmentTable: (initiallyAttachedEntities: AttachableEntity<any, any>[], initialAttachmentOperations: AttachmentOperation<any, any>[]) => void;
|
|
35
35
|
};
|
|
36
|
-
export declare const AttachmentTable: <ENTITY_TYPE>({ initiallyAttachedEntities, initiallyAttachedEntitiesStatus, initialAttachmentOperations, onAttachmentsOperationsChanged, entityName, searchEntityPlaceholder, getNameQuery, filteredEntities, onEntitySearchChange, }: AttachmentTableProps<ENTITY_TYPE>) => JSX.Element;
|
|
36
|
+
export declare const AttachmentTable: <ENTITY_TYPE, ENTITY extends Record<string, unknown> = Record<string, unknown>>({ initiallyAttachedEntities, initiallyAttachedEntitiesStatus, initialAttachmentOperations, onAttachmentsOperationsChanged, entityName, searchEntityPlaceholder, getNameQuery, filteredEntities, onEntitySearchChange, }: AttachmentTableProps<ENTITY_TYPE, ENTITY>) => JSX.Element;
|
|
37
37
|
//# sourceMappingURL=AttachmentTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentTable.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentTable.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EASlB,MAAM,OAAO,CAAC;AAef,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAQxD,MAAM,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"AttachmentTable.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentTable.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EASlB,MAAM,OAAO,CAAC;AAef,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AAQxD,MAAM,MAAM,oBAAoB,CAC9B,WAAW,EACX,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9D;IACF,yBAAyB,EAAE,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;IACnE,+BAA+B,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IAC1E,2BAA2B,EAAE,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;IACxE,UAAU,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,YAAY,CAAC,EAAE,CACb,MAAM,EAAE,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,KAC1C,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/C,uBAAuB,EAAE,MAAM,CAAC;IAChC,8BAA8B,EAAE,CAC9B,oBAAoB,EAAE,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAC7D,IAAI,CAAC;IACV,gBAAgB,EACZ;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAClB;QACE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;QAC5B,IAAI,CAAC,EAAE;YACL,MAAM,EAAE,MAAM,CAAC;YACf,QAAQ,EAAE,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;SACnD,CAAC;KACH,GACD;QACE,MAAM,EAAE,SAAS,CAAC;QAClB,IAAI,EAAE;YACJ,MAAM,EAAE,MAAM,CAAC;YACf,QAAQ,EAAE,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,CAAC;SACnD,CAAC;KACH,CAAC;IACN,oBAAoB,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACjD,CAAC;AAmFF,eAAO,MAAM,kBAAkB,iHAK5B,kBAAkB,EAAE,CAAC,gBAmBvB,CAAC;AAEF,eAAO,MAAM,uBAAuB;sDA/BL,iBAAiB,GAAG,EAAE,GAAG,CAAC,EAAE,+BAC1B,oBAAoB,GAAG,EAAE,GAAG,CAAC,EAAE,KACzD,IAAI;CAqCV,CAAC;AAEF,eAAO,MAAM,eAAe,oWA+iB3B,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
export type AttachableEntity<ENTITY_TYPE> = {
|
|
1
|
+
export type AttachableEntity<ENTITY_TYPE, ENTITY extends Record<string, unknown> = Record<string, unknown>> = {
|
|
2
2
|
name: string;
|
|
3
3
|
id: string;
|
|
4
4
|
type: ENTITY_TYPE;
|
|
5
5
|
disableDetach?: boolean;
|
|
6
|
+
completeEntity?: ENTITY;
|
|
6
7
|
};
|
|
7
8
|
export declare enum AttachmentAction {
|
|
8
9
|
ADD = 0,
|
|
9
10
|
REMOVE = 1
|
|
10
11
|
}
|
|
11
|
-
export type AttachmentOperation<ENTITY_TYPE> = {
|
|
12
|
+
export type AttachmentOperation<ENTITY_TYPE, ENTITY extends Record<string, unknown> = Record<string, unknown>> = {
|
|
12
13
|
action: AttachmentAction;
|
|
13
|
-
entity: AttachableEntity<ENTITY_TYPE>;
|
|
14
|
+
entity: AttachableEntity<ENTITY_TYPE, ENTITY>;
|
|
14
15
|
};
|
|
15
16
|
//# sourceMappingURL=AttachmentTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"AttachmentTypes.d.ts","sourceRoot":"","sources":["../../../src/lib/organisms/attachments/AttachmentTypes.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,CAC1B,WAAW,EACX,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9D;IACF,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,oBAAY,gBAAgB;IAC1B,GAAG,IAAA;IACH,MAAM,IAAA;CACP;AAED,MAAM,MAAM,mBAAmB,CAC7B,WAAW,EACX,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9D;IACF,MAAM,EAAE,gBAAgB,CAAC;IACzB,MAAM,EAAE,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;CAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,11 @@ import { Icon, LargerText, Modal, SecondaryText, Stack, Wrap } from '../..';
|
|
|
10
10
|
type AttachmentStatus = 'Waiting for confirmation' | 'Error' | 'Success';
|
|
11
11
|
|
|
12
12
|
//The entity is the "thing" you want to attach to the resource, sorry about the naming :(
|
|
13
|
-
export function AttachmentConfirmationModal<
|
|
13
|
+
export function AttachmentConfirmationModal<
|
|
14
|
+
ENTITY_TYPE,
|
|
15
|
+
RESOURCE_TYPE,
|
|
16
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
17
|
+
>({
|
|
14
18
|
attachmentOperations,
|
|
15
19
|
getAttachmentMutationOptions,
|
|
16
20
|
resourceType,
|
|
@@ -21,7 +25,7 @@ export function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>({
|
|
|
21
25
|
onCancel,
|
|
22
26
|
onExit,
|
|
23
27
|
}: {
|
|
24
|
-
attachmentOperations: AttachmentOperation<ENTITY_TYPE>[];
|
|
28
|
+
attachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
25
29
|
getAttachmentMutationOptions: () => UseMutationOptions<
|
|
26
30
|
unknown,
|
|
27
31
|
unknown,
|
|
@@ -30,6 +34,7 @@ export function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>({
|
|
|
30
34
|
type: ENTITY_TYPE;
|
|
31
35
|
entityName: string;
|
|
32
36
|
id: string;
|
|
37
|
+
completeEntity?: ENTITY;
|
|
33
38
|
}
|
|
34
39
|
>;
|
|
35
40
|
resourceName: string;
|
|
@@ -39,8 +44,8 @@ export function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>({
|
|
|
39
44
|
cancelButtonDisabled?: boolean;
|
|
40
45
|
onCancel?: () => void;
|
|
41
46
|
onExit?: (
|
|
42
|
-
successfullOperations: AttachmentOperation<ENTITY_TYPE>[],
|
|
43
|
-
failedOperations: AttachmentOperation<ENTITY_TYPE>[],
|
|
47
|
+
successfullOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
48
|
+
failedOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
44
49
|
) => void;
|
|
45
50
|
}) {
|
|
46
51
|
const history = useHistory();
|
|
@@ -70,12 +75,13 @@ export function AttachmentConfirmationModal<ENTITY_TYPE, RESOURCE_TYPE>({
|
|
|
70
75
|
entityName: string;
|
|
71
76
|
id: string;
|
|
72
77
|
}[] = attachmentOperations.map(
|
|
73
|
-
(attachmentOperation: AttachmentOperation<ENTITY_TYPE>) => {
|
|
78
|
+
(attachmentOperation: AttachmentOperation<ENTITY_TYPE, ENTITY>) => {
|
|
74
79
|
return {
|
|
75
80
|
action: attachmentOperation.action,
|
|
76
81
|
type: attachmentOperation.entity.type,
|
|
77
82
|
entityName: attachmentOperation.entity.name,
|
|
78
83
|
id: attachmentOperation.entity.id,
|
|
84
|
+
completeEntity: attachmentOperation.entity.completeEntity,
|
|
79
85
|
};
|
|
80
86
|
},
|
|
81
87
|
);
|
|
@@ -38,27 +38,36 @@ type AttachableEntityWithPendingStatus<ENTITY_TYPE> = {
|
|
|
38
38
|
isPending?: boolean;
|
|
39
39
|
} & AttachableEntity<ENTITY_TYPE>;
|
|
40
40
|
|
|
41
|
-
export type AttachmentTableProps<
|
|
42
|
-
|
|
41
|
+
export type AttachmentTableProps<
|
|
42
|
+
ENTITY_TYPE,
|
|
43
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
44
|
+
> = {
|
|
45
|
+
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
43
46
|
initiallyAttachedEntitiesStatus: 'idle' | 'loading' | 'success' | 'error';
|
|
44
|
-
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE>[];
|
|
47
|
+
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
45
48
|
entityName: { plural: string; singular: string };
|
|
46
49
|
getNameQuery?: (
|
|
47
|
-
entity: AttachableEntity<ENTITY_TYPE>,
|
|
50
|
+
entity: AttachableEntity<ENTITY_TYPE, ENTITY>,
|
|
48
51
|
) => UseQueryOptions<unknown, unknown, string>;
|
|
49
52
|
searchEntityPlaceholder: string;
|
|
50
53
|
onAttachmentsOperationsChanged: (
|
|
51
|
-
attachmentOperations: AttachmentOperation<ENTITY_TYPE>[],
|
|
54
|
+
attachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
52
55
|
) => void;
|
|
53
56
|
filteredEntities:
|
|
54
57
|
| { status: 'idle' }
|
|
55
58
|
| {
|
|
56
59
|
status: 'loading' | 'error';
|
|
57
|
-
data?: {
|
|
60
|
+
data?: {
|
|
61
|
+
number: number;
|
|
62
|
+
entities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
63
|
+
};
|
|
58
64
|
}
|
|
59
65
|
| {
|
|
60
66
|
status: 'success';
|
|
61
|
-
data: {
|
|
67
|
+
data: {
|
|
68
|
+
number: number;
|
|
69
|
+
entities: AttachableEntity<ENTITY_TYPE, ENTITY>[];
|
|
70
|
+
};
|
|
62
71
|
};
|
|
63
72
|
onEntitySearchChange: (search?: string) => void;
|
|
64
73
|
};
|
|
@@ -131,31 +140,34 @@ const PrivateAttachmentContext = createContext<{
|
|
|
131
140
|
setResetAttachementTable: Dispatch<
|
|
132
141
|
SetStateAction<
|
|
133
142
|
(
|
|
134
|
-
initiallyAttachedEntities: AttachableEntity<any>[], //Deliberately using any here because we can't use generics
|
|
135
|
-
initialAttachmentOperations: AttachmentOperation<any>[],
|
|
143
|
+
initiallyAttachedEntities: AttachableEntity<any, any>[], //Deliberately using any here because we can't use generics
|
|
144
|
+
initialAttachmentOperations: AttachmentOperation<any, any>[],
|
|
136
145
|
) => void
|
|
137
146
|
>
|
|
138
147
|
>;
|
|
139
148
|
} | null>(null);
|
|
140
149
|
const AttachmentContext = createContext<{
|
|
141
150
|
resetAttachmentTable: (
|
|
142
|
-
initiallyAttachedEntities: AttachableEntity<any>[], //Deliberately using any here because we can't use generics
|
|
143
|
-
initialAttachmentOperations: AttachmentOperation<any>[],
|
|
151
|
+
initiallyAttachedEntities: AttachableEntity<any, any>[], //Deliberately using any here because we can't use generics
|
|
152
|
+
initialAttachmentOperations: AttachmentOperation<any, any>[],
|
|
144
153
|
) => void;
|
|
145
154
|
} | null>(null);
|
|
146
155
|
|
|
147
|
-
export const AttachmentProvider = <
|
|
156
|
+
export const AttachmentProvider = <
|
|
157
|
+
ENTITY_TYPE extends unknown,
|
|
158
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
159
|
+
>({
|
|
148
160
|
children,
|
|
149
161
|
}: PropsWithChildren<{}>) => {
|
|
150
162
|
const [resetAttachmentTable, setResetAttachementTable] = useState<
|
|
151
163
|
(
|
|
152
|
-
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE>[],
|
|
153
|
-
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE>[],
|
|
164
|
+
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE, ENTITY>[],
|
|
165
|
+
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
154
166
|
) => void
|
|
155
167
|
>(
|
|
156
168
|
(
|
|
157
|
-
_: AttachableEntity<ENTITY_TYPE>[],
|
|
158
|
-
__: AttachmentOperation<ENTITY_TYPE>[],
|
|
169
|
+
_: AttachableEntity<ENTITY_TYPE, ENTITY>[],
|
|
170
|
+
__: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
159
171
|
) => {},
|
|
160
172
|
);
|
|
161
173
|
return (
|
|
@@ -177,7 +189,10 @@ export const useAttachmentOperations = () => {
|
|
|
177
189
|
return ctx;
|
|
178
190
|
};
|
|
179
191
|
|
|
180
|
-
export const AttachmentTable = <
|
|
192
|
+
export const AttachmentTable = <
|
|
193
|
+
ENTITY_TYPE,
|
|
194
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
195
|
+
>({
|
|
181
196
|
initiallyAttachedEntities,
|
|
182
197
|
initiallyAttachedEntitiesStatus,
|
|
183
198
|
initialAttachmentOperations,
|
|
@@ -187,7 +202,7 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
187
202
|
getNameQuery,
|
|
188
203
|
filteredEntities,
|
|
189
204
|
onEntitySearchChange,
|
|
190
|
-
}: AttachmentTableProps<ENTITY_TYPE>) => {
|
|
205
|
+
}: AttachmentTableProps<ENTITY_TYPE, ENTITY>) => {
|
|
191
206
|
const privateAttachmentContext = useContext(PrivateAttachmentContext);
|
|
192
207
|
const exposedAttachmentContext = useContext(AttachmentContext);
|
|
193
208
|
|
|
@@ -198,8 +213,11 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
198
213
|
//Desired attached entities and onAttachmentsOperationsChanged handling
|
|
199
214
|
const convertInitiallyAttachedEntitiesToDesiredAttachedEntities = useCallback(
|
|
200
215
|
(
|
|
201
|
-
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE>[],
|
|
202
|
-
operations: AttachmentOperation<
|
|
216
|
+
initiallyAttachedEntities: AttachableEntity<ENTITY_TYPE, ENTITY>[],
|
|
217
|
+
operations: AttachmentOperation<
|
|
218
|
+
ENTITY_TYPE,
|
|
219
|
+
ENTITY
|
|
220
|
+
>[] = initialAttachmentOperations,
|
|
203
221
|
) => {
|
|
204
222
|
return initiallyAttachedEntities
|
|
205
223
|
.filter(
|
|
@@ -216,7 +234,9 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
216
234
|
);
|
|
217
235
|
const convertInitiallyAttachementOperationsToDesiredAttachedEntities =
|
|
218
236
|
useCallback(
|
|
219
|
-
(
|
|
237
|
+
(
|
|
238
|
+
initialAttachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
239
|
+
) => {
|
|
220
240
|
return initialAttachmentOperations
|
|
221
241
|
.filter((op) => op.action !== AttachmentAction.REMOVE)
|
|
222
242
|
.map((op) => ({
|
|
@@ -232,21 +252,21 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
232
252
|
(
|
|
233
253
|
state: {
|
|
234
254
|
desiredAttachedEntities: AttachableEntityWithPendingStatus<ENTITY_TYPE>[];
|
|
235
|
-
attachmentsOperations: AttachmentOperation<ENTITY_TYPE>[];
|
|
255
|
+
attachmentsOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
236
256
|
},
|
|
237
257
|
action:
|
|
238
258
|
| {
|
|
239
259
|
action: AttachmentAction.ADD;
|
|
240
|
-
entity: AttachableEntity<ENTITY_TYPE>;
|
|
260
|
+
entity: AttachableEntity<ENTITY_TYPE, ENTITY>;
|
|
241
261
|
}
|
|
242
262
|
| {
|
|
243
263
|
action: AttachmentAction.REMOVE;
|
|
244
|
-
entity: AttachableEntity<ENTITY_TYPE>;
|
|
264
|
+
entity: AttachableEntity<ENTITY_TYPE, ENTITY>;
|
|
245
265
|
}
|
|
246
266
|
| {
|
|
247
267
|
action: 'RESET_DESIRED_ATTACHED_ENTITIES';
|
|
248
268
|
entities: AttachableEntityWithPendingStatus<ENTITY_TYPE>[];
|
|
249
|
-
operations: AttachmentOperation<ENTITY_TYPE>[];
|
|
269
|
+
operations: AttachmentOperation<ENTITY_TYPE, ENTITY>[];
|
|
250
270
|
},
|
|
251
271
|
) => {
|
|
252
272
|
switch (action.action) {
|
|
@@ -401,8 +421,8 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
401
421
|
useEffect(() => {
|
|
402
422
|
privateAttachmentContext.setResetAttachementTable(() => {
|
|
403
423
|
return (
|
|
404
|
-
newlyAttachedEntities: AttachableEntity<ENTITY_TYPE>[],
|
|
405
|
-
newAttachmentOperations: AttachmentOperation<ENTITY_TYPE>[],
|
|
424
|
+
newlyAttachedEntities: AttachableEntity<ENTITY_TYPE, ENTITY>[],
|
|
425
|
+
newAttachmentOperations: AttachmentOperation<ENTITY_TYPE, ENTITY>[],
|
|
406
426
|
) => {
|
|
407
427
|
dispatch({
|
|
408
428
|
action: 'RESET_DESIRED_ATTACHED_ENTITIES',
|
|
@@ -429,7 +449,11 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
429
449
|
const searchInputRef = useRef<HTMLInputElement | null>(null);
|
|
430
450
|
|
|
431
451
|
const onSelectedItemChange = useCallback(
|
|
432
|
-
(
|
|
452
|
+
(
|
|
453
|
+
onChangeParams: UseComboboxStateChange<
|
|
454
|
+
AttachableEntity<ENTITY_TYPE, ENTITY>
|
|
455
|
+
>,
|
|
456
|
+
) => {
|
|
433
457
|
if (onChangeParams.selectedItem) {
|
|
434
458
|
dispatch({
|
|
435
459
|
action: AttachmentAction.ADD,
|
|
@@ -478,7 +502,7 @@ export const AttachmentTable = <ENTITY_TYPE,>({
|
|
|
478
502
|
row: { original: entity },
|
|
479
503
|
}: {
|
|
480
504
|
value: string;
|
|
481
|
-
row: { original: AttachableEntity<ENTITY_TYPE> };
|
|
505
|
+
row: { original: AttachableEntity<ENTITY_TYPE, ENTITY> };
|
|
482
506
|
}) => {
|
|
483
507
|
const { data: asyncName, status } = useQuery({
|
|
484
508
|
...(getNameQuery
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export type AttachableEntity<
|
|
1
|
+
export type AttachableEntity<
|
|
2
|
+
ENTITY_TYPE,
|
|
3
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
4
|
+
> = {
|
|
2
5
|
name: string;
|
|
3
6
|
id: string;
|
|
4
7
|
type: ENTITY_TYPE;
|
|
5
8
|
disableDetach?: boolean;
|
|
9
|
+
completeEntity?: ENTITY;
|
|
6
10
|
};
|
|
7
11
|
|
|
8
12
|
export enum AttachmentAction {
|
|
@@ -10,7 +14,10 @@ export enum AttachmentAction {
|
|
|
10
14
|
REMOVE,
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export type AttachmentOperation<
|
|
17
|
+
export type AttachmentOperation<
|
|
18
|
+
ENTITY_TYPE,
|
|
19
|
+
ENTITY extends Record<string, unknown> = Record<string, unknown>,
|
|
20
|
+
> = {
|
|
14
21
|
action: AttachmentAction;
|
|
15
|
-
entity: AttachableEntity<ENTITY_TYPE>;
|
|
22
|
+
entity: AttachableEntity<ENTITY_TYPE, ENTITY>;
|
|
16
23
|
};
|