File size: 1,260 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { BlockDeprecation, registerBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import edit from './editor';
import icon from './icon';
import save from './save';
import type { BlockAttributesV1, BlockAttributes } from './types';

const v1deprecation: BlockDeprecation< BlockAttributesV1 > = {
	attributes: {
		estimate: { type: 'string' },
		team: { type: 'string', default: '' },
	},
	migrate( attributes: Record< string, unknown > ) {
		return {
			allTasks: 0,
			completedTasks: 0,
			pendingTasks: 0,
			...attributes,
		};
	},
	save() {
		return null;
	},
};

export function registerBlock() {
	registerBlockType< BlockAttributes >( 'a8c/project-status', {
		title: __( 'Project status' ),
		description: __( 'Display a task overview of the status of a project.' ),
		icon,
		category: 'a8c',
		supports: {
			className: false,
			anchor: true,
		},
		deprecated: [ v1deprecation ],
		attributes: {
			allTasks: {
				type: 'number',
				default: 0,
			},
			completedTasks: {
				type: 'number',
				default: 0,
			},
			estimate: {
				type: 'string',
			},
			pendingTasks: {
				type: 'number',
				default: 0,
			},
			team: {
				type: 'string',
				default: '',
			},
		},
		edit,
		save,
	} );
}

registerBlock();