All files / blong-browser/src/components/Editor/stories Pivot.stories.tsx

0% Statements 0/238
0% Branches 0/1
0% Functions 0/1
0% Lines 0/238

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
/**
 * Pivot stories — table pivot views with static and dynamic row sets.
 *
 * Static pivot: pre-defined `examples` rows joined to actual data.
 * Dynamic pivot: rows sourced from a named dropdown, joined to actual data.
 */
import type {Meta} from '@storybook/react-vite';
import type {StoryFn} from '../Editor.stories.js';
import {Editor} from '../Editor.js';

const meta: Meta<typeof Editor> = {title: 'Editor/Pivot', component: Editor};
export default meta;

export const Pivot: StoryFn = () => (
    <Editor
        schema={{
            properties: {
                schedule: {
                    title: '' as const,
                    type: 'array' as const,
                    items: {
                        type: 'object' as const,
                        properties: {
                            weekdayName: {title: 'Weekday Name', readOnly: true},
                            startTime: {title: 'Start Time'},
                            endTime: {title: 'End Time'},
                        },
                    },
                    widget: {
                        type: 'table' as const,
                        pivot: {
                            join: {weekdayName: 'weekdayName'},
                            examples: [
                                {weekdayName: 'Monday'},
                                {weekdayName: 'Tuesday'},
                                {weekdayName: 'Wednesday'},
                                {weekdayName: 'Thursday'},
                                {weekdayName: 'Friday'},
                                {weekdayName: 'Saturday'},
                                {weekdayName: 'Sunday'},
                            ],
                        },
                        actions: {allowAdd: false, allowDelete: false},
                    },
                } as never,
                permission: {
                    title: '' as const,
                    type: 'array' as const,
                    items: {
                        type: 'object' as const,
                        properties: {
                            entityId: {title: 'Entity ID'},
                            entityName: {title: 'Entity Name', readOnly: true},
                            view: {title: 'View', type: 'boolean' as const},
                            create: {title: 'Create', type: 'boolean' as const},
                            edit: {title: 'Edit', type: 'boolean' as const},
                            delete: {title: 'Delete', type: 'boolean' as const},
                        },
                    },
                    widget: {
                        type: 'table' as const,
                        pivot: {
                            dropdown: 'entity',
                            join: {value: 'entityId', label: 'entityName'},
                        },
                        actions: {allowAdd: false, allowDelete: false},
                    },
                } as never,
            },
        }}
        cards={{
            schedule: {
                label: 'Schedule (static pivot)',
                widgets: [
                    {
                        id: 'schedule',
                        name: 'schedule',
                        widgets: ['weekdayName', 'startTime', 'endTime'],
                    },
                ],
            },
            permission: {
                label: 'Permission (dynamic pivot)',
                widgets: [
                    {
                        id: 'permission',
                        name: 'permission',
                        widgets: ['entityName', 'view', 'create', 'edit', 'delete'],
                    },
                ],
            },
        }}
        dropdowns={{
            entity: [
                {value: 1, label: 'Organization'},
                {value: 2, label: 'Role'},
                {value: 3, label: 'User'},
                {value: 4, label: 'Product'},
                {value: 5, label: 'Account'},
            ],
        }}
        value={{
            schedule: [
                {weekdayName: 'Tuesday', startTime: '16:00', endTime: '17:00'},
                {weekdayName: 'Friday', startTime: '09:00', endTime: '10:00'},
            ],
            permission: [
                {entityId: 1, entityName: 'Organization', create: true, edit: true},
                {entityId: 2, entityName: 'Role', view: true},
                {
                    entityId: 3,
                    entityName: 'User',
                    view: true,
                    create: true,
                    edit: true,
                    delete: true,
                },
            ],
        }}
        editable
        editMode
        layout="edit"
        layouts={{edit: [['schedule', 'permission']]}}
    />
);

export const PivotBG: StoryFn = () => (
    <Editor
        schema={{
            properties: {
                schedule: {
                    title: '' as const,
                    type: 'array' as const,
                    items: {
                        type: 'object' as const,
                        properties: {
                            weekdayName: {title: 'Weekday Name', readOnly: true},
                            startTime: {title: 'Start Time'},
                            endTime: {title: 'End Time'},
                        },
                    },
                    widget: {
                        type: 'table' as const,
                        pivot: {
                            join: {weekdayName: 'weekdayName'},
                            examples: [
                                {weekdayName: 'Monday'},
                                {weekdayName: 'Tuesday'},
                                {weekdayName: 'Wednesday'},
                                {weekdayName: 'Thursday'},
                                {weekdayName: 'Friday'},
                                {weekdayName: 'Saturday'},
                                {weekdayName: 'Sunday'},
                            ],
                        },
                        actions: {allowAdd: false, allowDelete: false},
                    },
                } as never,
                permission: {
                    title: '' as const,
                    type: 'array' as const,
                    items: {
                        type: 'object' as const,
                        properties: {
                            entityId: {title: 'Entity ID'},
                            entityName: {title: 'Entity Name', readOnly: true},
                            view: {title: 'View', type: 'boolean' as const},
                            create: {title: 'Create', type: 'boolean' as const},
                            edit: {title: 'Edit', type: 'boolean' as const},
                            delete: {title: 'Delete', type: 'boolean' as const},
                        },
                    },
                    widget: {
                        type: 'table' as const,
                        pivot: {
                            dropdown: 'entity',
                            join: {value: 'entityId', label: 'entityName'},
                        },
                        actions: {allowAdd: false, allowDelete: false},
                    },
                } as never,
            },
        }}
        cards={{
            schedule: {
                label: 'График (статичен pivot)',
                widgets: [
                    {
                        id: 'schedule',
                        name: 'schedule',
                        widgets: ['weekdayName', 'startTime', 'endTime'],
                    },
                ],
            },
            permission: {
                label: 'Права (динамичен pivot)',
                widgets: [
                    {
                        id: 'permission',
                        name: 'permission',
                        widgets: ['entityName', 'view', 'create', 'edit', 'delete'],
                    },
                ],
            },
        }}
        dropdowns={{
            entity: [
                {value: 1, label: 'Организация'},
                {value: 2, label: 'Роля'},
                {value: 3, label: 'Потребител'},
                {value: 4, label: 'Продукт'},
                {value: 5, label: 'Сметка'},
            ],
        }}
        value={{
            schedule: [
                {weekdayName: 'Tuesday', startTime: '16:00', endTime: '17:00'},
                {weekdayName: 'Friday', startTime: '09:00', endTime: '10:00'},
            ],
            permission: [
                {entityId: 1, entityName: 'Организация', create: true, edit: true},
                {entityId: 2, entityName: 'Роля', view: true},
                {
                    entityId: 3,
                    entityName: 'Потребител',
                    view: true,
                    create: true,
                    edit: true,
                    delete: true,
                },
            ],
        }}
        editable
        editMode
        layout="edit"
        layouts={{edit: [['schedule', 'permission']]}}
    />
);