proje-react-panel 1.1.2 → 1.1.3
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/components/list/CellField.d.ts +3 -2
- package/dist/components/list/cells/BooleanCell.d.ts +6 -0
- package/dist/components/list/cells/DateCell.d.ts +6 -0
- package/dist/components/list/cells/DefaultCell.d.ts +8 -0
- package/dist/components/list/cells/DownloadCell.d.ts +8 -0
- package/dist/components/list/cells/ImageCell.d.ts +8 -0
- package/dist/components/list/cells/UUIDCell.d.ts +6 -0
- package/dist/decorators/list/Cell.d.ts +4 -6
- package/dist/decorators/list/ExtendedCell.d.ts +10 -0
- package/dist/decorators/list/cells/DownloadCell.d.ts +9 -0
- package/dist/decorators/list/cells/ImageCell.d.ts +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/utils/decerators.d.ts +7 -0
- package/package.json +1 -1
- package/src/components/list/CellField.tsx +26 -42
- package/src/components/list/Datagrid.tsx +16 -9
- package/src/components/list/cells/BooleanCell.tsx +15 -0
- package/src/components/list/cells/DateCell.tsx +21 -0
- package/src/components/list/cells/DefaultCell.tsx +11 -0
- package/src/components/list/cells/DownloadCell.tsx +28 -0
- package/src/components/list/cells/ImageCell.tsx +22 -0
- package/src/components/list/cells/UUIDCell.tsx +11 -0
- package/src/decorators/list/Cell.ts +15 -33
- package/src/decorators/list/ExtendedCell.ts +32 -0
- package/src/decorators/list/cells/DownloadCell.ts +18 -0
- package/src/decorators/list/cells/ImageCell.ts +6 -5
- package/src/index.ts +1 -0
- package/src/styles/list.scss +1 -1
- package/src/utils/decerators.ts +24 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { CellConfiguration } from '../../../decorators/list/Cell';
|
3
|
+
import { DownloadCellConfiguration } from '../../../decorators/list/cells/DownloadCell';
|
4
|
+
|
5
|
+
interface DownloadCellProps {
|
6
|
+
value: string;
|
7
|
+
configuration: CellConfiguration;
|
8
|
+
}
|
9
|
+
|
10
|
+
export function DownloadCell({ value, configuration }: DownloadCellProps): React.ReactElement {
|
11
|
+
if (!value) return <>-</>;
|
12
|
+
|
13
|
+
const downloadConfiguration = configuration as DownloadCellConfiguration;
|
14
|
+
const baseUrl = downloadConfiguration.baseUrl || '';
|
15
|
+
const downloadUrl = baseUrl + value;
|
16
|
+
|
17
|
+
return (
|
18
|
+
<a
|
19
|
+
href={downloadUrl}
|
20
|
+
download
|
21
|
+
className="download-link"
|
22
|
+
target="_blank"
|
23
|
+
rel="noopener noreferrer"
|
24
|
+
>
|
25
|
+
Download
|
26
|
+
</a>
|
27
|
+
);
|
28
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { CellConfiguration } from '../../../decorators/list/Cell';
|
3
|
+
import { ImageCellConfiguration } from '../../../decorators/list/cells/ImageCell';
|
4
|
+
interface ImageCellProps {
|
5
|
+
value: string;
|
6
|
+
configuration: CellConfiguration;
|
7
|
+
}
|
8
|
+
|
9
|
+
export function ImageCell({ value, configuration }: ImageCellProps) {
|
10
|
+
const imageConfiguration = configuration as ImageCellConfiguration;
|
11
|
+
if (!value) return <>-</>;
|
12
|
+
|
13
|
+
return (
|
14
|
+
<img
|
15
|
+
width={100}
|
16
|
+
height={100}
|
17
|
+
src={imageConfiguration.baseUrl + value}
|
18
|
+
style={{ objectFit: 'contain' }}
|
19
|
+
alt=""
|
20
|
+
/>
|
21
|
+
);
|
22
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
interface UUIDCellProps {
|
4
|
+
value: string;
|
5
|
+
}
|
6
|
+
|
7
|
+
export function UUIDCell({ value }: UUIDCellProps) {
|
8
|
+
if (!value || typeof value !== 'string' || value.length < 6) return <>-</>;
|
9
|
+
|
10
|
+
return <>{`${value.slice(0, 3)}...${value.slice(-3)}`}</>;
|
11
|
+
}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import 'reflect-metadata';
|
2
2
|
import { AnyClass } from '../../types/AnyClass';
|
3
|
+
import { createDecorator, DecoratorMap } from '../../utils/decerators';
|
3
4
|
|
4
|
-
export const CELL_KEY = Symbol('cell');
|
5
|
+
export const CELL_KEY: Symbol = Symbol('cell');
|
5
6
|
|
6
7
|
interface Filter {
|
7
8
|
type: 'string' | 'number' | 'date' | 'static-select';
|
@@ -13,7 +14,7 @@ export interface StaticSelectFilter extends Filter {
|
|
13
14
|
}
|
14
15
|
|
15
16
|
export type CellTypes = 'string' | 'date' | 'number' | 'boolean' | 'uuid';
|
16
|
-
export type ExtendedCellTypes = CellTypes | 'image';
|
17
|
+
export type ExtendedCellTypes = CellTypes | 'image' | 'download';
|
17
18
|
|
18
19
|
export interface CellOptions {
|
19
20
|
name?: string;
|
@@ -22,38 +23,23 @@ export interface CellOptions {
|
|
22
23
|
placeHolder?: string;
|
23
24
|
filter?: Filter | StaticSelectFilter;
|
24
25
|
}
|
25
|
-
export interface ExtendedCellOptions extends Omit<CellOptions, 'type'> {
|
26
|
-
type?: ExtendedCellTypes;
|
27
|
-
}
|
28
26
|
|
29
27
|
export interface CellConfiguration extends Omit<CellOptions, 'type'> {
|
30
28
|
name: string;
|
31
29
|
type: ExtendedCellTypes;
|
32
30
|
}
|
33
31
|
|
34
|
-
export
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
Reflect.defineMetadata(keyString, options, target);
|
43
|
-
}
|
44
|
-
};
|
45
|
-
}
|
46
|
-
|
47
|
-
export function ExtendedCell(options?: ExtendedCellOptions): PropertyDecorator {
|
48
|
-
return (target, propertyKey) => {
|
49
|
-
const existingCells: string[] = Reflect.getMetadata(CELL_KEY, target) || [];
|
50
|
-
Reflect.defineMetadata(CELL_KEY, [...existingCells, propertyKey.toString()], target);
|
32
|
+
export const cellMap: DecoratorMap<CellOptions, CellConfiguration> = (
|
33
|
+
{ propertyKey },
|
34
|
+
options
|
35
|
+
) => ({
|
36
|
+
...options,
|
37
|
+
name: options.name || propertyKey.toString(),
|
38
|
+
type: options.type || 'string',
|
39
|
+
});
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
Reflect.defineMetadata(keyString, options, target);
|
55
|
-
}
|
56
|
-
};
|
41
|
+
export function Cell(options?: CellOptions): PropertyDecorator {
|
42
|
+
return createDecorator(CELL_KEY, options, cellMap);
|
57
43
|
}
|
58
44
|
|
59
45
|
export function getCellFields<T extends AnyClass>(entityClass: T): CellConfiguration[] {
|
@@ -61,12 +47,8 @@ export function getCellFields<T extends AnyClass>(entityClass: T): CellConfigura
|
|
61
47
|
const inputFields: string[] = Reflect.getMetadata(CELL_KEY, prototype) || [];
|
62
48
|
|
63
49
|
return inputFields.map(field => {
|
64
|
-
const fields:
|
50
|
+
const fields: CellConfiguration =
|
65
51
|
Reflect.getMetadata(`${CELL_KEY.toString()}:${field}:options`, prototype) || {};
|
66
|
-
return
|
67
|
-
...fields,
|
68
|
-
name: fields.name || field,
|
69
|
-
type: fields.type as ExtendedCellTypes,
|
70
|
-
};
|
52
|
+
return fields;
|
71
53
|
});
|
72
54
|
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import {
|
2
|
+
CELL_KEY,
|
3
|
+
CellConfiguration,
|
4
|
+
CellOptions,
|
5
|
+
CellTypes,
|
6
|
+
Cell,
|
7
|
+
ExtendedCellTypes,
|
8
|
+
cellMap,
|
9
|
+
} from './Cell';
|
10
|
+
import { createDecorator, DecoratorMap } from '../../utils/decerators';
|
11
|
+
|
12
|
+
export interface ExtendedCellOptions extends Omit<CellOptions, 'type'> {
|
13
|
+
type?: ExtendedCellTypes;
|
14
|
+
}
|
15
|
+
|
16
|
+
interface ExtendedCellConfiguration extends Omit<CellConfiguration, 'name'> {
|
17
|
+
name?: string;
|
18
|
+
}
|
19
|
+
|
20
|
+
export function ExtendedCell<T extends ExtendedCellOptions, K extends ExtendedCellConfiguration>(
|
21
|
+
options?: T,
|
22
|
+
map?: DecoratorMap<T, K>
|
23
|
+
): PropertyDecorator {
|
24
|
+
return createDecorator<T, K>(CELL_KEY, options, ({ target, propertyKey }, optionsInner) => {
|
25
|
+
const config = cellMap({ target, propertyKey }, optionsInner as CellOptions);
|
26
|
+
const newConfig: K | undefined = map ? map({ target, propertyKey }, optionsInner) : undefined;
|
27
|
+
return {
|
28
|
+
...config,
|
29
|
+
...newConfig,
|
30
|
+
} as K;
|
31
|
+
});
|
32
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { CellConfiguration, CellOptions } from '../Cell';
|
2
|
+
import { ExtendedCell } from '../ExtendedCell';
|
3
|
+
|
4
|
+
export interface DownloadCellOptions extends Omit<CellOptions, 'type'> {
|
5
|
+
baseUrl: string;
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface DownloadCellConfiguration extends CellConfiguration {
|
9
|
+
type: 'download';
|
10
|
+
baseUrl: string;
|
11
|
+
}
|
12
|
+
|
13
|
+
export function DownloadCell(options?: DownloadCellOptions): PropertyDecorator {
|
14
|
+
return ExtendedCell(options, (_, options) => ({
|
15
|
+
...options,
|
16
|
+
type: 'download',
|
17
|
+
}));
|
18
|
+
}
|
@@ -1,17 +1,18 @@
|
|
1
|
-
import '
|
2
|
-
import {
|
1
|
+
import { CellConfiguration, CellOptions } from '../Cell';
|
2
|
+
import { ExtendedCell, ExtendedCellOptions } from '../ExtendedCell';
|
3
3
|
|
4
|
-
export interface ImageCellOptions extends CellOptions {
|
4
|
+
export interface ImageCellOptions extends Omit<CellOptions, 'type'> {
|
5
5
|
baseUrl: string;
|
6
6
|
}
|
7
7
|
|
8
8
|
export interface ImageCellConfiguration extends CellConfiguration {
|
9
9
|
type: 'image';
|
10
|
+
baseUrl: string;
|
10
11
|
}
|
11
12
|
|
12
13
|
export function ImageCell(options?: ImageCellOptions): PropertyDecorator {
|
13
|
-
return ExtendedCell({
|
14
|
+
return ExtendedCell(options, (_, options) => ({
|
14
15
|
...options,
|
15
16
|
type: 'image',
|
16
|
-
});
|
17
|
+
}));
|
17
18
|
}
|
package/src/index.ts
CHANGED
@@ -19,6 +19,7 @@ export { FormPage } from './components/form/FormPage';
|
|
19
19
|
export { Form, type OnSubmitFN } from './decorators/form/Form';
|
20
20
|
export { Input } from './decorators/form/Input';
|
21
21
|
export { SelectInput } from './decorators/form/inputs/SelectInput';
|
22
|
+
export { DownloadCell } from './decorators/list/cells/DownloadCell';
|
22
23
|
//for nested form fields
|
23
24
|
export { getInputFields } from './decorators/form/Input';
|
24
25
|
|
package/src/styles/list.scss
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@import 'utils/scrollbar';
|
2
2
|
$header-height: 60px;
|
3
3
|
$footer-height: 60px;
|
4
|
-
$datagrid-height: calc(100vh -
|
4
|
+
$datagrid-height: calc(100vh - #{$header-height} - #{$footer-height});
|
5
5
|
.list {
|
6
6
|
width: 100%;
|
7
7
|
background-color: #2b2b2b;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export type DecoratorMap<T, K> = (
|
2
|
+
{ target, propertyKey }: { target: Object; propertyKey: string | symbol },
|
3
|
+
options: T
|
4
|
+
) => K;
|
5
|
+
export function createDecorator<T extends { name?: string }, K>(
|
6
|
+
key: Symbol,
|
7
|
+
options?: T,
|
8
|
+
map?: DecoratorMap<T, K>
|
9
|
+
): PropertyDecorator {
|
10
|
+
return (target, propertyKey) => {
|
11
|
+
const propKeyStr = propertyKey.toString();
|
12
|
+
const existingCells: string[] = Reflect.getMetadata(key, target) || [];
|
13
|
+
|
14
|
+
if (options) {
|
15
|
+
const keyString = `${key.toString()}:${propKeyStr}:options`;
|
16
|
+
const config = map ? map({ target, propertyKey }, options) : options;
|
17
|
+
|
18
|
+
Reflect.defineMetadata(key, [...existingCells, propKeyStr], target);
|
19
|
+
Reflect.defineMetadata(keyString, config, target);
|
20
|
+
} else {
|
21
|
+
Reflect.defineMetadata(key, [...existingCells, propKeyStr], target);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
}
|