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

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

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                                                                                                                                                                                                                                                                                                                                                                                                                                         
/**
 * Uses a tab layout: "Permission settings" tab shows three cascaded tables side-by-side
 * (roleCategory → permission → permissionRole). A second "Documents" tab shows a document list.
 *
 * - roleCategory: read-only list of permission categories
 * - permission: filtered by selected roleCategory, hasRight inline toggle
 * - permissionRole: filtered by selected permission action, selected inline toggle
 * - The permissionRole card is only shown when roleCategory.hasSettings === true
 */
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/CascadedTablesVariant', component: Editor};
export default meta;

const variantValue = {
    roleCategory: [
        {actionCategoryId: 478, label: 'Manage Users', hasSettings: true},
        {actionCategoryId: 681, label: 'Manage History', hasSettings: false},
        {actionCategoryId: 259, label: 'Manage Content Items and Translations', hasSettings: false},
    ],
    permission: [
        {actionCategoryId: 259, actionId: 1006, actionName: 'Add Item', hasRight: true},
        {actionCategoryId: 259, actionId: 1025, actionName: 'Edit Item', hasRight: false},
        {
            actionCategoryId: 259,
            actionId: 1029,
            actionName: 'Enable / Disable Item',
            hasRight: false,
        },
        {actionCategoryId: 478, actionId: 1008, actionName: 'Add User', hasRight: true},
        {actionCategoryId: 478, actionId: 1011, actionName: 'Authorize Changes', hasRight: false},
        {
            actionCategoryId: 478,
            actionId: 1014,
            actionName: 'Clear Unsuccessful Login Attempts',
            hasRight: false,
        },
        {actionCategoryId: 478, actionId: 1020, actionName: 'Delete User', hasRight: false},
        {actionCategoryId: 478, actionId: 1028, actionName: 'Edit User', hasRight: false},
        {
            actionCategoryId: 681,
            actionId: 1109,
            actionName: 'Access Policy History Log',
            hasRight: true,
        },
        {
            actionCategoryId: 681,
            actionId: 1074,
            actionName: 'Agents and Merchants Network History Log',
            hasRight: false,
        },
        {actionCategoryId: 681, actionId: 1150, actionName: 'Export History', hasRight: false},
    ],
    permissionRole: [
        {actionId: 1008, value: 1167, selected: true, label: 'Banks Branch User'},
        {actionId: 1008, value: 1168, selected: true, label: 'CBI Admin'},
        {actionId: 1008, value: 1169, selected: true, label: 'CBI Auditor'},
        {actionId: 1008, value: 1170, selected: false, label: 'CBI Compliance Office User'},
        {actionId: 1109, value: 1171, selected: true, label: 'CBI Directorate Admin Checker'},
        {actionId: 1109, value: 1172, selected: false, label: 'CBI Directorate Admin Maker'},
    ],
    document: [
        {
            documentId: 1,
            documentType: 'Passport',
            issueDate: '2020-01-01',
            expiryDate: '2025-01-01',
            check: true,
        },
        {
            documentId: 2,
            documentType: 'Driving License',
            issueDate: '2020-01-02',
            expiryDate: '2025-01-02',
            check: false,
        },
        {
            documentId: 3,
            documentType: 'Marriage Certificate',
            issueDate: '2020-01-03',
            expiryDate: '2025-01-03',
            check: true,
        },
    ],
};

export const CascadedTablesVariant: StoryFn = () => (
    <Editor
        schema={{
            properties: {
                roleCategory: {
                    title: '',
                    type: 'array',
                    widget: {
                        type: 'table',
                        selectionMode: 'single',
                        actions: {allowAdd: false, allowDelete: false, allowEdit: false},
                        columns: ['label'],
                    },
                    items: {
                        properties: {
                            actionCategoryId: {title: 'ID', readOnly: true},
                            label: {title: 'Category', readOnly: true},
                            hasSettings: {title: 'Has Settings', type: 'boolean'},
                        },
                    },
                },
                permission: {
                    title: '',
                    type: 'array',
                    widget: {
                        type: 'table',
                        selectionMode: 'single',
                        actions: {allowAdd: false, allowDelete: false, allowEdit: false},
                        columns: ['hasRight', 'actionName'],
                        parent: '$.selected.roleCategory',
                        master: {actionCategoryId: 'actionCategoryId'},
                        autoSelect: true,
                    },
                    items: {
                        properties: {
                            actionCategoryId: {title: 'Category ID', readOnly: true},
                            actionId: {title: 'Action ID', readOnly: true},
                            actionName: {title: 'Granted Permissions', readOnly: true},
                            hasRight: {title: ' ', type: 'boolean'},
                        },
                    },
                },
                permissionRole: {
                    title: '',
                    type: 'array',
                    widget: {
                        type: 'table',
                        selectionMode: 'single',
                        actions: {allowAdd: false, allowDelete: false, allowEdit: false},
                        columns: ['selected', 'label'],
                        parent: '$.selected.permission',
                        master: {actionId: 'actionId'},
                        autoSelect: true,
                    },
                    items: {
                        properties: {
                            actionId: {title: 'Action ID', readOnly: true},
                            value: {title: 'Value', readOnly: true},
                            selected: {title: ' ', type: 'boolean'},
                            label: {title: 'Permissions for Role'},
                        },
                    },
                },
                document: {
                    title: '',
                    type: 'array',
                    widget: {
                        type: 'table',
                        actions: {allowEdit: false},
                        columns: ['documentType', 'issueDate', 'expiryDate', 'check'],
                    },
                    items: {
                        properties: {
                            documentId: {title: 'ID', readOnly: true},
                            documentType: {title: 'Document Type'},
                            issueDate: {title: 'Issue Date'},
                            expiryDate: {title: 'Expiry Date'},
                            check: {title: 'Check', type: 'boolean'},
                        },
                    },
                },
            },
        }}
        cards={{
            roleCategory: {
                label: undefined,
                className: 'col-12 md:col-4',
                widgets: ['roleCategory'],
            },
            permission: {
                label: undefined,
                className: 'col-12 md:col-4',
                widgets: ['permission'],
            },
            permissionRole: {
                label: undefined,
                className: 'col-12 md:col-4',
                widgets: ['permissionRole'],
            },
            document: {
                label: 'Document',
                className: 'col-12',
                widgets: ['document'],
            },
        }}
        value={variantValue}
        editable
        editMode
        layout="edit"
        layouts={{
            edit: {
                orientation: 'left',
                items: [
                    {
                        id: 'permissions',
                        label: 'Permission settings',
                        widgets: ['roleCategory', 'permission', 'permissionRole'],
                    },
                    {id: 'documents', label: 'Documents', widgets: ['document']},
                ],
            },
        }}
    />
);