@xen-orchestra/web-core 0.3.0 → 0.5.0

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.
Files changed (124) hide show
  1. package/lib/assets/css/_colors.pcss +56 -24
  2. package/lib/assets/css/_context.pcss +9 -9
  3. package/lib/assets/css/base.pcss +6 -6
  4. package/lib/components/backup-item/VtsBackupItem.vue +47 -0
  5. package/lib/components/backup-state/{BackupState.vue → VtsBackupState.vue} +4 -4
  6. package/lib/components/{button/ButtonGroup.vue → button-group/VtsButtonGroup.vue} +7 -6
  7. package/lib/components/cell-object/{CellObject.vue → VtsCellObject.vue} +14 -14
  8. package/lib/components/cell-text/{CellText.vue → VtsCellText.vue} +11 -11
  9. package/lib/components/console/{RemoteConsole.vue → VtsRemoteConsole.vue} +12 -18
  10. package/lib/components/donut-chart-with-legend/{DonutChartWithLegend.vue → VtsDonutChartWithLegend.vue} +6 -6
  11. package/lib/components/dropdown/DropdownItem.vue +8 -14
  12. package/lib/components/dropdown/DropdownTitle.vue +3 -3
  13. package/lib/components/icon/VtsIcon.vue +38 -42
  14. package/lib/components/layout/{LayoutSidebar.vue → VtsLayoutSidebar.vue} +31 -30
  15. package/lib/components/legend-group/VtsLegendGroup.vue +44 -0
  16. package/lib/components/{legend/LegendList.vue → legend-list/VtsLegendList.vue} +2 -2
  17. package/lib/components/menu/MenuTrigger.vue +2 -2
  18. package/lib/components/stacked-bar-with-legend/{StackedBarWithLegend.vue → VtsStackedBarWithLegend.vue} +14 -14
  19. package/lib/components/state-hero/VtsComingSoonHero.vue +13 -0
  20. package/lib/components/state-hero/VtsLoadingHero.vue +15 -0
  21. package/lib/components/state-hero/VtsNoDataHero.vue +11 -0
  22. package/lib/components/state-hero/VtsObjectNotFoundHero.vue +13 -0
  23. package/lib/components/state-hero/{StateHero.vue → VtsStateHero.vue} +42 -35
  24. package/lib/components/tab/TabItem.vue +6 -6
  25. package/lib/components/table/ColumnTitle.vue +7 -7
  26. package/lib/components/table/{UiTable.vue → VtsTable.vue} +7 -3
  27. package/lib/components/task/{QuickTaskButton.vue → VtsQuickTaskButton.vue} +8 -7
  28. package/lib/components/task/{QuickTaskList.vue → VtsQuickTaskList.vue} +10 -11
  29. package/lib/components/task/{QuickTaskTabBar.vue → VtsQuickTaskTabBar.vue} +9 -13
  30. package/lib/components/{tooltip/TooltipList.vue → tooltip-list/VtsTooltipList.vue} +2 -3
  31. package/lib/components/tree/{TreeItem.vue → VtsTreeItem.vue} +3 -4
  32. package/lib/components/tree/VtsTreeItemError.vue +18 -0
  33. package/lib/components/tree/{TreeLine.vue → VtsTreeLine.vue} +9 -11
  34. package/lib/components/tree/{TreeList.vue → VtsTreeList.vue} +5 -2
  35. package/lib/components/tree/VtsTreeLoadingItem.vue +61 -0
  36. package/lib/components/ui/account-menu-button/UiAccountMenuButton.vue +64 -0
  37. package/lib/components/ui/actions-title/UiActionsTitle.vue +18 -0
  38. package/lib/components/ui/button/UiButton.vue +532 -0
  39. package/lib/components/ui/button-icon/UiButtonIcon.vue +248 -0
  40. package/lib/components/{UiCard.vue → ui/card/UiCard.vue} +8 -6
  41. package/lib/components/ui/card-numbers/UiCardNumbers.vue +103 -0
  42. package/lib/components/ui/card-subtitle/UiCardSubtitle.vue +24 -0
  43. package/lib/components/ui/card-title/UiCardTitle.vue +56 -0
  44. package/lib/components/ui/checkbox/UiCheckbox.vue +410 -0
  45. package/lib/components/ui/checkbox-group/UiCheckboxGroup.vue +57 -0
  46. package/lib/components/ui/chip/ChipIcon.vue +21 -0
  47. package/lib/components/ui/chip/ChipRemoveIcon.vue +13 -0
  48. package/lib/components/ui/chip/UiChip.vue +135 -0
  49. package/lib/components/{icon/ComplexIcon.vue → ui/complex-icon/UiComplexIcon.vue} +21 -27
  50. package/lib/components/ui/counter/UiCounter.vue +134 -0
  51. package/lib/components/{donut-chart/DonutChart.vue → ui/donut-chart/UiDonutChart.vue} +28 -30
  52. package/lib/components/{head-bar/HeadBar.vue → ui/head-bar/UiHeadBar.vue} +31 -31
  53. package/lib/components/{info/VtsInfo.vue → ui/info/UiInfo.vue} +13 -11
  54. package/lib/components/{input → ui/input}/UiInput.vue +9 -7
  55. package/lib/components/ui/input/UiTextarea.vue +120 -0
  56. package/lib/components/ui/label/UiLabel.vue +76 -0
  57. package/lib/components/ui/legend/UiLegend.vue +98 -0
  58. package/lib/components/{LegendTitle.vue → ui/legend-title/UiLegendTitle.vue} +4 -4
  59. package/lib/components/{UiSpinner.vue → ui/loader/UiLoader.vue} +3 -3
  60. package/lib/components/{icon/ObjectIcon.vue → ui/object-icon/UiObjectIcon.vue} +44 -36
  61. package/lib/components/ui/object-link/UiObjectLink.vue +83 -0
  62. package/lib/components/ui/panel/UiPanel.vue +57 -0
  63. package/lib/components/{query-search-bar/QuerySearchBar.vue → ui/query-search-bar/UiQuerySearchBar.vue} +16 -16
  64. package/lib/components/{task/QuickTaskItem.vue → ui/quick-task-item/UiQuickTaskItem.vue} +46 -34
  65. package/lib/components/{task/QuickTaskPanel.vue → ui/quick-task-panel/UiQuickTaskPanel.vue} +8 -7
  66. package/lib/components/ui/radio-button/UiRadioButton.vue +196 -0
  67. package/lib/components/ui/radio-button-group/UiRadioButtonGroup.vue +56 -0
  68. package/lib/components/{stacked-bar → ui/stacked-bar}/StackedBarSegment.vue +23 -26
  69. package/lib/components/{stacked-bar/StackedBar.vue → ui/stacked-bar/UiStackedBar.vue} +6 -6
  70. package/lib/components/ui/table-actions/UiTableActions.vue +46 -0
  71. package/lib/components/ui/tag/UiTag.vue +118 -0
  72. package/lib/components/ui/title/UiTitle.vue +39 -0
  73. package/lib/components/ui/toaster/UiToaster.vue +100 -0
  74. package/lib/components/ui/toggle/UiToggle.vue +117 -0
  75. package/lib/components/{tooltip/TooltipItem.vue → ui/tooltip/UiTooltip.vue} +15 -15
  76. package/lib/components/ui/top-bottom-table/UiTopBottomTable.vue +64 -0
  77. package/lib/components/{tree/TreeItemLabel.vue → ui/tree-item-label/UiTreeItemLabel.vue} +60 -59
  78. package/lib/components/ui/user-link/UiUserLink.vue +76 -0
  79. package/lib/components/ui/user-logo/UiUserLogo.vue +50 -0
  80. package/lib/composables/route-query.composable.md +136 -0
  81. package/lib/composables/table.composable.md +159 -0
  82. package/lib/composables/tree/define-tree.ts +1 -1
  83. package/lib/composables/tree/tree-node-base.ts +6 -6
  84. package/lib/composables/tree.composable.md +536 -0
  85. package/lib/layouts/CoreLayout.vue +8 -6
  86. package/lib/locales/de.json +3 -2
  87. package/lib/locales/en.json +7 -3
  88. package/lib/locales/fa.json +3 -2
  89. package/lib/locales/fr.json +7 -3
  90. package/lib/types/color.type.ts +0 -2
  91. package/lib/types/subscribable-store.type.ts +2 -2
  92. package/lib/utils/create-subscribable-store-context.util.ts +1 -1
  93. package/lib/utils/if-else.utils.md +23 -0
  94. package/lib/utils/if-else.utils.ts +2 -2
  95. package/lib/utils/to-variants.util.md +62 -0
  96. package/package.json +7 -7
  97. package/lib/components/CardNumbers.vue +0 -101
  98. package/lib/components/PowerStateIcon.vue +0 -46
  99. package/lib/components/UiTag.vue +0 -101
  100. package/lib/components/backup-item/BackupItem.vue +0 -40
  101. package/lib/components/button/ButtonIcon.vue +0 -220
  102. package/lib/components/button/UiButton.vue +0 -470
  103. package/lib/components/card/CardSubtitle.vue +0 -24
  104. package/lib/components/card/CardTitle.vue +0 -57
  105. package/lib/components/chip/ChipIcon.vue +0 -30
  106. package/lib/components/chip/ChipRemoveIcon.vue +0 -13
  107. package/lib/components/chip/UiChip.vue +0 -137
  108. package/lib/components/counter/VtsCounter.vue +0 -147
  109. package/lib/components/legend/LegendGroup.vue +0 -44
  110. package/lib/components/legend/LegendItem.vue +0 -86
  111. package/lib/components/object-link/ObjectLink.vue +0 -87
  112. package/lib/components/state-hero/ComingSoonHero.vue +0 -13
  113. package/lib/components/state-hero/LoadingHero.vue +0 -15
  114. package/lib/components/state-hero/NoDataHero.vue +0 -11
  115. package/lib/components/state-hero/ObjectNotFoundHero.vue +0 -13
  116. package/lib/components/tree/TreeItemError.vue +0 -13
  117. package/lib/components/tree/TreeLoadingItem.vue +0 -60
  118. package/lib/components/user/UserLink.vue +0 -72
  119. package/lib/components/user/UserLogo.vue +0 -57
  120. package/lib/types/backup.type.ts +0 -11
  121. package/lib/types/size.type.ts +0 -1
  122. package/lib/types/task.type.ts +0 -13
  123. /package/lib/components/backdrop/{Backdrop.vue → VtsBackdrop.vue} +0 -0
  124. /package/lib/components/divider/{Divider.vue → VtsDivider.vue} +0 -0
@@ -0,0 +1,159 @@
1
+ # `useTable` composable
2
+
3
+ ## Usage
4
+
5
+ ```ts
6
+ const { columns, visibleColumns, rows, columnsById } = useTable('<table-id>', records, {
7
+ rowId: record => record.id,
8
+ columns: define => [
9
+ define('<column-id>', { label: 'Column 1' }),
10
+ define('<column-id>', { label: 'Column 2' }),
11
+ define('<column-id>', { label: 'Column 3' }),
12
+ ],
13
+ })
14
+ ```
15
+
16
+ ## `useTable` options
17
+
18
+ | Name | Type | Required | Description |
19
+ | --------- | ---------------------------------------------- | :------: | ------------------------------------------------- |
20
+ | `rowId` | `(record: TRecord) => string` | ✓ | A function that define the id of a row. |
21
+ | `columns` | `(define: DefineColumn) => ColumnDefinition[]` | ✓ | A function that defines the columns of the table. |
22
+
23
+ ## Defining a column
24
+
25
+ ```ts
26
+ define('<TColumnId>', options) // TValue will be TRecord[TColumnId]
27
+ define('<TColumnId>', `<TProperty>`, options) // TValue will be TRecord[TProperty]
28
+ define('<TColumnId>', (record: TRecord) => '<TValue>', options) // TValue will be the result of the function
29
+ ```
30
+
31
+ ### Column options
32
+
33
+ | Name | Type | Required | Default | Description |
34
+ | ------------ | ---------------------------------- | :------: | ------- | -------------------------------------- |
35
+ | `label` | `string` | ✓ | | The column label. |
36
+ | `isHideable` | `boolean` | | `true` | Indicates if the column can be hidden. |
37
+ | `compareFn` | `(a: TValue, b: TValue) => number` | | | A function used to compare the values. |
38
+
39
+ ## `columns`
40
+
41
+ An array containing all columns defined in the table.
42
+
43
+ ### Properties of a column
44
+
45
+ | Name | Type | Description |
46
+ | ------------ | ----------------------------- | ------------------------------------------------ |
47
+ | `id` | `string` | The column id. |
48
+ | `label` | `string` | The column label. |
49
+ | `isVisible` | `boolean` | Indicates if the column is visible. |
50
+ | `getter` | `(record: TRecord) => TValue` | A function that returns the value of the column. |
51
+ | `isSortable` | `boolean` | Indicates if the column is sortable. |
52
+ | `isHideable` | `boolean` | Indicates if the column is hideable. |
53
+
54
+ #### If `isSortable` is `true`
55
+
56
+ | Name | Type | Description |
57
+ | --------------------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------- |
58
+ | `compareFn` | `(a: TValue, b: TValue) => number` | The compare function defined in the column options. |
59
+ | `isSorted` | `boolean` | Indicates if the column is sorted. |
60
+ | `isSortedAsc` | `boolean` | Indicates if the column is sorted in ascending order. |
61
+ | `isSortedDesc` | `boolean` | Indicates if the column is sorted in descending order. |
62
+ | `sort` | `(direction, toggleOffIfSameDirection?) => void` | A function that sorts the rows based on the column values. |
63
+ | &nbsp;⤷&nbsp;`direction` | `'asc' \| 'desc' \| false` | The sort direction. If `false`, the column is unsorted. |
64
+ | &nbsp;⤷&nbsp;`toggleOffIfSameDirection` | `boolean` | Indicates if the column should be unsorted if it is already sorted in the same direction. |
65
+ | `sortAsc` | `(toggleOffIfSameDirection?) => void` | A function that sorts the rows based on the column values in ascending order. |
66
+ | &nbsp;⤷&nbsp;`toggleOffIfSameDirection` | `boolean` | Indicates if the column should be unsorted if it is already sorted in ascending order. |
67
+ | `sortDesc` | `(toggleOffIfSameDirection?) => void` | A function that sorts the rows based on the column values in descending order. |
68
+ | &nbsp;⤷&nbsp;`toggleOffIfSameDirection` | `boolean` | Indicates if the column should be unsorted if it is already sorted in descending order. |
69
+
70
+ #### If `isHideable` is `true`
71
+
72
+ | Name | Type | Description |
73
+ | -------------------- | --------------------------- | ------------------------------------------------------------------------------- |
74
+ | `hide` | `() => void` | A function that hides the column. |
75
+ | `show` | `() => void` | A function that shows the column. |
76
+ | `toggle` | `(value?: boolean) => void` | A function that toggles the visibility of the column. |
77
+ | &nbsp;⤷&nbsp;`value` | `boolean \| undefined` | If undefined, the visibility will be toggled. Else it will be set to the value. |
78
+
79
+ ## `visibleColumns`
80
+
81
+ Same as `columns` but only contains the visible columns.
82
+
83
+ ## `rows`
84
+
85
+ An array containing all rows of the table.
86
+
87
+ ### Properties of a row
88
+
89
+ | Name | Type | Description |
90
+ | ---------------- | ---------- | ------------------------------- |
91
+ | `id` | `string` | The row id. |
92
+ | `value` | `TRecord` | The record of the row. |
93
+ | `visibleColumns` | `Column[]` | The visible columns of the row. |
94
+
95
+ #### `visibleColumns`
96
+
97
+ An array containing the visible columns of the row.
98
+
99
+ ##### Properties of a row column
100
+
101
+ | Name | Type | Description |
102
+ | ------- | -------- | ------------------------ |
103
+ | `id` | `string` | The column id. |
104
+ | `value` | `TValue` | The value of the column. |
105
+
106
+ ## `columnsById`
107
+
108
+ An object containing all columns defined in the table indexed by their id.
109
+
110
+ ## Example
111
+
112
+ ```vue
113
+ <template>
114
+ <div>
115
+ <button v-for="column of columns" :key="column.id" @click.prevent="column.toggle()">
116
+ {{ column.isVisible ? 'Hide' : 'Show' }} {{ column.label }}
117
+ </button>
118
+ </div>
119
+ <table>
120
+ <thead>
121
+ <tr>
122
+ <th v-for="column of visibleColumns" :key="column.id">
123
+ {{ column.label }}
124
+ <button v-if="column.isHideable" @click.prevent="column.hide()">Hide</button>
125
+ <template v-if="column.isSortable">
126
+ <button @click.prevent="column.sortAsc(true)">Sort ASC</button>
127
+ <button @click.prevent="column.sortDesc(true)">Sort DESC</button>
128
+ </template>
129
+ </th>
130
+ </tr>
131
+ </thead>
132
+ <tbody>
133
+ <tr v-for="row of rows" :key="row.id">
134
+ <td v-for="column of row.visibleColumns" :key="column.id">
135
+ {{ column.value }}
136
+ </td>
137
+ </tr>
138
+ </tbody>
139
+ </table>
140
+ </template>
141
+
142
+ <script lang="ts" setup>
143
+ const { columns, visibleColumns, rows } = useTable(
144
+ 'users',
145
+ [
146
+ { id: 1, name: 'John', age: 25 },
147
+ { id: 2, name: 'Jane', age: 30 },
148
+ { id: 3, name: 'Alice', age: 20 },
149
+ ],
150
+ {
151
+ rowId: record => record.id,
152
+ columns: define => [
153
+ define('name', { label: 'Name', isHideable: false }),
154
+ define('age', { label: 'Age', compareFn: (user1, user2) => user1.age - user2.age }),
155
+ ],
156
+ }
157
+ )
158
+ </script>
159
+ ```
@@ -50,7 +50,7 @@ export function defineTree<
50
50
  optionsOrGetChildTree?: TreeNodeOptions<TData, TDiscriminator> | ChildTreeDefinitionGetter<TData, TChildDefinition>,
51
51
  getChildTreeOrNone?: ChildTreeDefinitionGetter<TData, TChildDefinition>
52
52
  ) {
53
- const options = (typeof optionsOrGetChildTree === 'function' ? {} : optionsOrGetChildTree ?? {}) as TreeNodeOptions<
53
+ const options = (typeof optionsOrGetChildTree === 'function' ? {} : (optionsOrGetChildTree ?? {})) as TreeNodeOptions<
54
54
  TData,
55
55
  TDiscriminator
56
56
  >
@@ -1,5 +1,5 @@
1
1
  import type { Branch } from '@core/composables/tree/branch'
2
- import type { Identifiable, Labeled, TreeContext, TreeNodeOptions } from '@core/composables/tree/types'
2
+ import type { Identifiable, Labeled, TreeContext, TreeNodeId, TreeNodeOptions } from '@core/composables/tree/types'
3
3
 
4
4
  export abstract class TreeNodeBase<TData extends object = any, TDiscriminator = any> {
5
5
  abstract readonly isBranch: boolean
@@ -27,16 +27,16 @@ export abstract class TreeNodeBase<TData extends object = any, TDiscriminator =
27
27
  this.options = options ?? ({} as TreeNodeOptions<TData, TDiscriminator>)
28
28
  }
29
29
 
30
- get id() {
30
+ get id(): TreeNodeId {
31
31
  if (this.options.getId === undefined) {
32
32
  return (this.data as Identifiable).id
33
33
  }
34
34
 
35
35
  if (typeof this.options.getId === 'function') {
36
- return this.options.getId(this.data)
36
+ return this.options.getId(this.data as Identifiable)
37
37
  }
38
38
 
39
- return this.data[this.options.getId]
39
+ return this.data[this.options.getId as keyof TData] as TreeNodeId
40
40
  }
41
41
 
42
42
  get label() {
@@ -45,10 +45,10 @@ export abstract class TreeNodeBase<TData extends object = any, TDiscriminator =
45
45
  }
46
46
 
47
47
  if (typeof this.options.getLabel === 'function') {
48
- return this.options.getLabel(this.data)
48
+ return this.options.getLabel(this.data as Labeled)
49
49
  }
50
50
 
51
- return this.data[this.options.getLabel]
51
+ return this.data[this.options.getLabel as keyof TData]
52
52
  }
53
53
 
54
54
  get discriminator() {