@things-factory/auth-ui 9.1.0 → 9.1.6

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.
@@ -54,12 +54,52 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
54
54
  border-width: 1px 0;
55
55
  }
56
56
 
57
+ .category-group {
58
+ display: contents;
59
+ }
60
+
61
+ .category-title {
62
+ font-weight: bold;
63
+ font-size: 0.9em;
64
+ color: var(--md-sys-color-primary);
65
+ text-transform: uppercase;
66
+ opacity: 0.7;
67
+ align-self: stretch;
68
+ position: sticky;
69
+ top: 0;
70
+ display: flex;
71
+ align-items: center;
72
+ justify-content: flex-end;
73
+ text-align: right;
74
+ }
75
+
76
+ .category-privileges {
77
+ display: contents;
78
+ }
79
+
80
+ @media screen and (min-width: 640px) {
81
+ ul {
82
+ grid-template-columns: minmax(200px, auto) 1fr 1fr;
83
+ gap: 0;
84
+ }
85
+
86
+ .category-title {
87
+ grid-column: 1;
88
+ padding-right: var(--spacing-medium);
89
+ }
90
+
91
+ li {
92
+ grid-column: auto;
93
+ }
94
+ }
95
+
57
96
  input[type='checkbox'] {
58
97
  display: inline;
59
98
  }
60
99
 
61
100
  li {
62
101
  padding: var(--spacing-small);
102
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
63
103
  }
64
104
 
65
105
  #checkAll,
@@ -78,10 +118,29 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
78
118
  background-color: var(--md-sys-color-surface-variant);
79
119
  }
80
120
 
81
- @media screen and (max-width: 480px) {
121
+ @media screen and (max-width: 639px) {
82
122
  ul {
83
123
  grid-template-columns: 1fr;
84
124
  }
125
+
126
+ .category-group {
127
+ display: block;
128
+ margin-top: var(--spacing-medium);
129
+ }
130
+
131
+ .category-group:first-child {
132
+ margin-top: 0;
133
+ }
134
+
135
+ .category-title {
136
+ position: static;
137
+ margin-bottom: var(--spacing-small);
138
+ }
139
+
140
+ .category-privileges {
141
+ display: grid;
142
+ grid-template-columns: 1fr;
143
+ }
85
144
  }
86
145
  `
87
146
  ]; }
@@ -89,6 +148,21 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
89
148
  const allPrivileges = this.allPrivileges || [];
90
149
  const privileges = this.privileges || [];
91
150
  const users = this.users || [];
151
+ // Group privileges by category
152
+ const groupedPrivileges = allPrivileges.reduce((acc, privilege) => {
153
+ const category = privilege.category || 'Other';
154
+ if (!acc[category]) {
155
+ acc[category] = [];
156
+ }
157
+ acc[category].push(privilege);
158
+ return acc;
159
+ }, {});
160
+ // Sort categories alphabetically
161
+ const sortedCategories = Object.keys(groupedPrivileges).sort();
162
+ // Sort privileges within each category by name (descending)
163
+ sortedCategories.forEach(category => {
164
+ groupedPrivileges[category].sort((a, b) => b.name.localeCompare(a.name));
165
+ });
92
166
  return html `
93
167
  <div titler>${String(i18next.t('label.user'))}</div>
94
168
 
@@ -102,16 +176,25 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
102
176
  </div>
103
177
 
104
178
  <ul privileges>
105
- ${allPrivileges.map(privilege => html `
106
- <li>
107
- <input
108
- type="checkbox"
109
- id="${privilege.id}"
110
- .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}
111
- .data-privilege=${privilege}
112
- />
113
- <label for="${privilege.id}">${privilege.description}</label>
114
- </li>
179
+ ${sortedCategories.map(category => html `
180
+ <div class="category-group">
181
+ <div class="category-title">${category}</div>
182
+ <div class="category-privileges">
183
+ ${groupedPrivileges[category].map(
184
+ /* privilege : {id, name, category, description} */
185
+ privilege => html `
186
+ <li>
187
+ <input
188
+ type="checkbox"
189
+ id="${privilege.id}"
190
+ .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}
191
+ .data-privilege=${privilege}
192
+ />
193
+ <label for="${privilege.id}">${privilege.description}</label>
194
+ </li>
195
+ `)}
196
+ </div>
197
+ </div>
115
198
  `)}
116
199
  </ul>
117
200
 
@@ -200,6 +283,7 @@ let RolePrivilegeEditor = class RolePrivilegeEditor extends localize(i18next)(Li
200
283
  items {
201
284
  id
202
285
  name
286
+ category
203
287
  description
204
288
  }
205
289
  total
@@ -1 +1 @@
1
- {"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA/D;;QA2E6B,kBAAa,GAAU,EAAE,CAAA;QAG3C,eAAU,GAA0C,EAAE,CAAA;QACtD,UAAK,GAA0E,EAAE,CAAA;IAkL5F,CAAC;aAhQQ,WAAM,GAAG;QACd,qBAAqB;QACrB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoEF;KACF,AAvEY,CAuEZ;IASD,MAAM;QACJ,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAA;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAA;QACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAA;QAE9B,OAAO,IAAI,CAAA;oBACK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EF,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAA;IACvC,CAAC;IAED,KAAK,CAAC,qBAAqB,CAAC,IAAI;QAC9B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;YAClC,KAAK,EAAE,GAAG,CAAA;;;;;;;;;;;;;;;OAeT;YACD,SAAS,EAAE,EAAE,IAAI,EAAE;YACnB,OAAO,EAAE,UAAU,EAAE;SACtB,CAAC,CAAA;QAEF,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAA;QAChD,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAA;IACxC,CAAC;IAED,SAAS,CAAC,OAAO;QACf,QAAQ,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IACrG,CAAC;;AAtL2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAU;AACV;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;0DAA0B;AACxB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;0DAAmB;AAErC;IAAR,KAAK,EAAE;;uDAAuD;AACtD;IAAR,KAAK,EAAE;;kDAAkF;AA/EtF,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CAiQxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n }\n\n div {\n margin: var(--spacing-medium);\n }\n\n div[users] {\n margin: 0;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n div[titler] {\n color: var(--md-sys-color-secondary);\n font: bold 1.2em var(--theme-font);\n text-transform: capitalize;\n }\n\n ul {\n flex: 1;\n color: var(--md-sys-color-secondary);\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin-block-start: 0;\n margin-block-end: 0;\n padding: var(--spacing-medium);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--spacing-small);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-small);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 480px) {\n ul {\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n @state() privileges: { id: string; description: string }[] = []\n @state() users: { /* id: string; username: string; */ name: string; email: string }[] = []\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n const users = this.users || []\n\n return html`\n <div titler>${String(i18next.t('label.user'))}</div>\n\n <div users>${users.map(user => html`<div>${user.name} (${user.email})</div>`)}</div>\n\n <div titler>${String(i18next.t('field.privileges'))}</div>\n\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${allPrivileges.map(\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n users {\n name\n email\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n this.privileges = response.data.role?.privileges\n this.users = response.data.role?.users\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}
1
+ {"version":3,"file":"role-privilege-editor.js","sourceRoot":"","sources":["../../client/components/role-privilege-editor.ts"],"names":[],"mappings":";AAAA,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,C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R,KAAK,EAAE;;kDAAkF;AA1ItF,mBAAmB;IADxB,aAAa,CAAC,uBAAuB,CAAC;GACjC,mBAAmB,CA4VxB","sourcesContent":["import gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { client, gqlContext } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { OxPrompt } from '@operato/popup/ox-prompt.js'\nimport { ButtonContainerStyles } from '@operato/styles'\n\n@customElement('role-privilege-editor')\nclass RolePrivilegeEditor extends localize(i18next)(LitElement) {\n static styles = [\n ButtonContainerStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n border: 1px solid var(--md-sys-color-primary);\n font: normal 15px var(--theme-font);\n }\n\n div {\n margin: var(--spacing-medium);\n }\n\n div[users] {\n margin: 0;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n div[titler] {\n color: var(--md-sys-color-secondary);\n font: bold 1.2em var(--theme-font);\n text-transform: capitalize;\n }\n\n ul {\n flex: 1;\n color: var(--md-sys-color-secondary);\n background-color: var(--md-sys-color-surface-variant);\n overflow: auto;\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin-block-start: 0;\n margin-block-end: 0;\n padding: var(--spacing-medium);\n list-style: none;\n border: 1px dashed rgba(0, 0, 0, 0.1);\n border-width: 1px 0;\n }\n\n .category-group {\n display: contents;\n }\n\n .category-title {\n font-weight: bold;\n font-size: 0.9em;\n color: var(--md-sys-color-primary);\n text-transform: uppercase;\n opacity: 0.7;\n align-self: stretch;\n position: sticky;\n top: 0;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n text-align: right;\n }\n\n .category-privileges {\n display: contents;\n }\n\n @media screen and (min-width: 640px) {\n ul {\n grid-template-columns: minmax(200px, auto) 1fr 1fr;\n gap: 0;\n }\n\n .category-title {\n grid-column: 1;\n padding-right: var(--spacing-medium);\n }\n\n li {\n grid-column: auto;\n }\n }\n\n input[type='checkbox'] {\n display: inline;\n }\n\n li {\n padding: var(--spacing-small);\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n }\n\n #checkAll,\n [for='checkAll'] {\n margin-bottom: var(--spacing-medium);\n padding-bottom: var(--spacing-small);\n font-weight: bold;\n }\n\n md-elevated-button {\n margin: 5px;\n background-color: var(--md-sys-color-surface-variant);\n }\n\n md-outlined-button {\n background-color: var(--md-sys-color-surface-variant);\n }\n\n @media screen and (max-width: 639px) {\n ul {\n grid-template-columns: 1fr;\n }\n\n .category-group {\n display: block;\n margin-top: var(--spacing-medium);\n }\n\n .category-group:first-child {\n margin-top: 0;\n }\n\n .category-title {\n position: static;\n margin-bottom: var(--spacing-small);\n }\n\n .category-privileges {\n display: grid;\n grid-template-columns: 1fr;\n }\n }\n `\n ]\n\n @property({ type: Object }) role: any\n @property({ type: Array }) allPrivileges: any[] = []\n @property({ type: Object }) updateRoleObj: any\n\n @state() privileges: { id: string; description: string }[] = []\n @state() users: { /* id: string; username: string; */ name: string; email: string }[] = []\n\n render() {\n const allPrivileges = this.allPrivileges || []\n const privileges = this.privileges || []\n const users = this.users || []\n\n // Group privileges by category\n const groupedPrivileges = allPrivileges.reduce(\n (acc, privilege) => {\n const category = privilege.category || 'Other'\n if (!acc[category]) {\n acc[category] = []\n }\n acc[category].push(privilege)\n return acc\n },\n {} as Record<string, any[]>\n )\n\n // Sort categories alphabetically\n const sortedCategories = Object.keys(groupedPrivileges).sort()\n\n // Sort privileges within each category by name (descending)\n sortedCategories.forEach(category => {\n groupedPrivileges[category].sort((a, b) => b.name.localeCompare(a.name))\n })\n\n return html`\n <div titler>${String(i18next.t('label.user'))}</div>\n\n <div users>${users.map(user => html`<div>${user.name} (${user.email})</div>`)}</div>\n\n <div titler>${String(i18next.t('field.privileges'))}</div>\n\n <div>\n <input id=\"checkAll\" type=\"checkbox\" @change=${e => this.oncheckAll(e)} />\n <label for=\"checkAll\">Check all</label>\n </div>\n\n <ul privileges>\n ${sortedCategories.map(\n category => html`\n <div class=\"category-group\">\n <div class=\"category-title\">${category}</div>\n <div class=\"category-privileges\">\n ${groupedPrivileges[category].map(\n /* privilege : {id, name, category, description} */\n privilege => html`\n <li>\n <input\n type=\"checkbox\"\n id=\"${privilege.id}\"\n .checked=${privileges.map(p => p.id).indexOf(privilege.id) > -1}\n .data-privilege=${privilege}\n />\n <label for=\"${privilege.id}\">${privilege.description}</label>\n </li>\n `\n )}\n </div>\n </div>\n `\n )}\n </ul>\n\n <div class=\"button-container\">\n <md-elevated-button @click=${e => this.onSave()}>${String(i18next.t('button.save'))}</md-elevated-button>\n <md-elevated-button @click=${e => this.onDeleteRole()} danger\n >${String(i18next.t('button.delete role'))}</md-elevated-button\n >\n </div>\n `\n }\n\n async firstUpdated() {\n this.allPrivileges = await this.fetchPrivileges()\n }\n\n async updated(changes) {\n if (changes.has('role')) {\n await this.fetchPrivilegesOnRole(this.role.name)\n }\n }\n\n checkAll(checked) {\n Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]')).forEach(\n checkbox => ((checkbox as HTMLInputElement).checked = checked)\n )\n }\n\n oncheckAll(e) {\n this.checkAll(e.target.checked)\n }\n\n async onSave() {\n const updateRoleObj = this.updateRoleObj\n const privileges = Array.from(this.renderRoot.querySelectorAll('ul[privileges] input[type=checkbox]:checked')).map(\n e => e['data-privilege']\n )\n\n const patch = { ...updateRoleObj, privileges: privileges }\n\n if (this.role) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: RolePatch!) {\n updateRole(id: $id, patch: $patch) {\n id\n name\n description\n privileges {\n id\n description\n }\n }\n }\n `,\n variables: { id: this.role.id, patch },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n this.showToast(i18next.t('text.data_updated_successfully'))\n }\n }\n }\n\n async onDeleteRole() {\n if (\n await OxPrompt.open({\n title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.are_you_sure_to_delete_x', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.delete') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) {\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!) {\n deleteRole(id: $id)\n }\n `,\n variables: { id: this.role.id },\n context: gqlContext()\n })\n\n if (!response.errors) {\n await this.dispatchEvent(new CustomEvent('fetch-roles'))\n\n await OxPrompt.open({\n type: 'success',\n title: i18next.t('text.completed'),\n text: i18next.t('text.x_deleted_successfully', { x: i18next.t('label.role') }),\n confirmButton: { text: i18next.t('button.confirm') }\n })\n }\n }\n }\n\n async fetchPrivileges() {\n const response = await client.query({\n query: gql`\n query privileges {\n privileges {\n items {\n id\n name\n category\n description\n }\n total\n }\n }\n `\n })\n\n return response.data.privileges.items\n }\n\n async fetchPrivilegesOnRole(name) {\n const response = await client.query({\n query: gql`\n query ($name: String!) {\n role(name: $name) {\n id\n name\n privileges {\n id\n description\n }\n users {\n name\n email\n }\n }\n }\n `,\n variables: { name },\n context: gqlContext()\n })\n\n this.privileges = response.data.role?.privileges\n this.users = response.data.role?.users\n }\n\n showToast(message) {\n document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))\n }\n}\n"]}