Skip to content

Commit

Permalink
UI-7229 - Option to remove widgets of a given type in the CLI (#21)
Browse files Browse the repository at this point in the history
* UI-7229 - Allow to optionally remove some widgets

* CLI option

* Add README

* Enrich warning message

* PR feedback

* Simplification attempt

* Update src/migrateUIFolder.test.ts

Co-authored-by: Benjamin Amelot <[email protected]>

* PR feedback

* feedback in other place

* Update src/migrateUIFolder.test.ts

Co-authored-by: Benjamin Amelot <[email protected]>

* other way of writing the assertion

* Fix

Co-authored-by: Benjamin Amelot <[email protected]>
Co-authored-by: Benjamin Amelot <[email protected]>
  • Loading branch information
3 people authored May 24, 2022
1 parent ec14799 commit d8d51c4
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 42 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ npx migrate -i "content of ui.json" -o migrated-content.json -s servers.json

This command generates a file named `migrated-content.json` in the same folder. It contains the migrated content, ready to be used in ActiveUI 5.

Optionally, you can pass an extra `--remove-widgets` option to remove all ActiveUI 4 widgets with the given keys during the migration.
For example, suppose you have 200 ActiveUI 4 bookmarks in which you use Page Filters and/or Page Context Values.
These plugins are not supported anymore in ActiveUI 5 as it was deemed a better user experience to remove them altogether.
If you want to follow this UX and remove these widgets programmatically, you can run the migration CLI with the extra option:

```
npx migrate -i "content of ui.json" -o migrated-content.json -s servers.json --remove-widgets "filters" "context-values"
```

### Test the migrated content

Use the Content Manager again, this time to import this migrated content.
Expand Down
144 changes: 144 additions & 0 deletions src/__snapshots__/migrateUIFolder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ Object {
"timestamp": 1607879735685,
},
},
"eef": Object {
"entry": Object {
"canRead": true,
"canWrite": true,
"content": "{\\"pages\\":{\\"p-0\\":{\\"layout\\":{\\"children\\":[{\\"size\\":0.2,\\"leafKey\\":\\"4\\"},{\\"size\\":0.8,\\"children\\":[{\\"size\\":0.3,\\"leafKey\\":\\"3\\"},{\\"size\\":0.27999999999999997,\\"leafKey\\":\\"1\\"},{\\"size\\":0.42,\\"leafKey\\":\\"2\\"}],\\"direction\\":\\"column\\"}],\\"direction\\":\\"row\\"},\\"name\\":\\"Start page\\",\\"contextValues\\":{\\"EquityDerivativesCube\\":{\\"mdx.lightCrossjoin\\":true},\\"EquityDerivativesCubeDist\\":{\\"mdx.aggressiveFormulaEvaluation\\":true}},\\"content\\":{\\"1\\":{\\"query\\":{\\"mdx\\":\\"SELECT NON EMPTY Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember])) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM [EquityDerivativesCube] CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS\\",\\"updateMode\\":\\"once\\"},\\"filters\\":[\\"TopCount(Filter([Geography].[City].Levels(1).Members, NOT IsEmpty([Measures].[contributors.COUNT])), 3, [Measures].[contributors.COUNT])\\",\\"{[Currency].[Currency].[ALL].[AllMember].[GBP], [Currency].[Currency].[ALL].[AllMember].[JPY], [Currency].[Currency].[ALL].[AllMember].[USD]}\\"],\\"queryContext\\":[{\\"key\\":\\"queriesTimeLimit\\",\\"value\\":60},{\\"key\\":\\"mdx.casesensitive\\",\\"value\\":true},{\\"key\\":\\"mdx.defaultmembers.[Geography].[City]\\",\\"value\\":\\"[AllMember].[Berlin]\\"}],\\"mapping\\":{\\"rows\\":[\\"[Currency].[Currency].[Currency]\\"],\\"columns\\":[\\"ALL_MEASURES\\"],\\"measures\\":[\\"[Measures].[contributors.COUNT]\\"]},\\"name\\":\\"Tree table\\",\\"serverKey\\":\\"my-server\\",\\"widgetKey\\":\\"tree-table\\",\\"columnWidths\\":{\\"[Currency].[Currency].[Currency]\\":250}},\\"2\\":{\\"plotly\\":{\\"data\\":{\\"overridesByTraceKey\\":{\\"[Measures].[pnlVega.SUM]\\":{\\"name\\":\\"Taux de marge\\",\\"yaxis\\":\\"y2\\"}}},\\"layout\\":{\\"xaxis\\":{\\"showticklabels\\":false,\\"showgrid\\":false,\\"showline\\":false},\\"yaxis\\":{\\"showticklabels\\":true,\\"showline\\":false},\\"yaxis2\\":{\\"showticklabels\\":true,\\"showline\\":true,\\"side\\":\\"right\\",\\"range\\":[-1000,1000],\\"overlaying\\":\\"y\\"},\\"margin\\":{\\"t\\":20,\\"l\\":20,\\"r\\":20,\\"b\\":20}}},\\"switchedTo\\":\\"plotly-line-chart\\",\\"mapping\\":{\\"xAxis\\":[\\"[Currency].[Currency].[Currency]\\"],\\"values\\":[\\"[Measures].[pnlDelta.SUM]\\",\\"[Measures].[pnlVega.SUM]\\"],\\"secondaryValues\\":[],\\"splitBy\\":[\\"ALL_MEASURES\\"],\\"horizontalSubplots\\":[],\\"verticalSubplots\\":[]},\\"query\\":{\\"mdx\\":\\"SELECT NON EMPTY [Currency].[Currency].[Currency].Members ON ROWS, NON EMPTY {[Measures].[pnlDelta.SUM], [Measures].[pnlVega.SUM]} ON COLUMNS FROM [EquityDerivativesCube]\\",\\"updateMode\\":\\"once\\"},\\"filters\\":[],\\"queryContext\\":[],\\"serverKey\\":\\"my-server\\",\\"name\\":\\"Chart\\",\\"widgetKey\\":\\"plotly-line-chart\\"},\\"3\\":{\\"mode\\":\\"checkbox\\",\\"name\\":\\"Quick filter\\",\\"levelCoordinates\\":{\\"dimensionName\\":\\"Currency\\",\\"hierarchyName\\":\\"Currency\\",\\"levelName\\":\\"Currency\\"},\\"cubeName\\":\\"EquityDerivativesCube\\",\\"serverKey\\":\\"my-server\\",\\"widgetKey\\":\\"quick-filter\\"},\\"4\\":{\\"name\\":\\"Page filters\\",\\"widgetKey\\":\\"filters\\"}},\\"filters\\":[],\\"queryContext\\":[{\\"key\\":\\"mdx.lightCrossjoin\\",\\"value\\":true},{\\"key\\":\\"mdx.aggressiveFormulaEvaluation\\",\\"value\\":true}]}},\\"pagesOrder\\":[\\"p-0\\"],\\"filters\\":[],\\"queryContext\\":[{\\"key\\":\\"queriesTimeLimit\\",\\"value\\":60},{\\"key\\":\\"mdx.casesensitive\\",\\"value\\":false},{\\"key\\":\\"mdx.defaultmembers.[Geography].[City]\\",\\"value\\":\\"[AllMember].[Paris]\\"}]}",
"isDirectory": false,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
"f06": Object {
"entry": Object {
"canRead": true,
Expand Down Expand Up @@ -907,6 +923,39 @@ Object {
"timestamp": 1607879735685,
},
},
"eef": Object {
"children": Object {
"eef_metadata": Object {
"entry": Object {
"canRead": true,
"canWrite": true,
"content": "{\\"name\\":\\"1 page, 4 widgets\\"}",
"isDirectory": true,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
},
"entry": Object {
"canRead": true,
"canWrite": true,
"isDirectory": true,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
"fba": Object {
"children": Object {
"fba_metadata": Object {
Expand Down Expand Up @@ -1111,6 +1160,18 @@ Object {
],
},
},
"organization_permissions": Object {
"entry": Object {
"content": "{}",
"isDirectory": false,
"owners": Array [
"ROLE_CS_ROOT",
],
"readers": Array [
"ROLE_CS_ROOT",
],
},
},
"organization_settings": Object {
"entry": Object {
"content": "{\\"theme\\":\\"light-activeviam\\"}",
Expand All @@ -1122,6 +1183,17 @@ Object {
],
},
},
"user_roles": Object {
"entry": Object {
"isDirectory": true,
"owners": Array [
"ROLE_CS_ROOT",
],
"readers": Array [
"ROLE_USER",
],
},
},
"users": Object {
"children": Object {
"admin": Object {
Expand Down Expand Up @@ -1233,6 +1305,22 @@ Object {
"timestamp": 1607879735685,
},
},
"0xb": Object {
"entry": Object {
"canRead": true,
"canWrite": true,
"content": "{}",
"isDirectory": false,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
"1fe": Object {
"entry": Object {
"canRead": true,
Expand Down Expand Up @@ -1487,6 +1575,39 @@ Object {
"timestamp": 1607879735685,
},
},
"0xb": Object {
"children": Object {
"0xb_metadata": Object {
"entry": Object {
"canRead": true,
"canWrite": true,
"content": "{\\"name\\":\\"Page filters\\",\\"widgetKey\\":\\"filters\\"}",
"isDirectory": true,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
},
"entry": Object {
"canRead": true,
"canWrite": true,
"isDirectory": true,
"lastEditor": "admin",
"owners": Array [
"admin",
],
"readers": Array [
"admin",
],
"timestamp": 1607879735685,
},
},
"1fe": Object {
"children": Object {
"1fe_metadata": Object {
Expand Down Expand Up @@ -2128,6 +2249,18 @@ Object {
],
},
},
"organization_permissions": Object {
"entry": Object {
"content": "{}",
"isDirectory": false,
"owners": Array [
"ROLE_CS_ROOT",
],
"readers": Array [
"ROLE_CS_ROOT",
],
},
},
"organization_settings": Object {
"entry": Object {
"content": "{}",
Expand All @@ -2139,6 +2272,17 @@ Object {
],
},
},
"user_roles": Object {
"entry": Object {
"isDirectory": true,
"owners": Array [
"ROLE_CS_ROOT",
],
"readers": Array [
"ROLE_USER",
],
},
},
"users": Object {
"children": Object {
"admin": Object {
Expand Down
30 changes: 21 additions & 9 deletions src/__test_resources__/legacyDashboard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { LegacyDashboardState } from "../migration.types";
import { legacyChart } from "./legacyChart";
import { legacyPageFilters } from "./legacyPageFilters";
import { legacyQuickFilter } from "./legacyQuickFilter";
import { legacyTreeTable } from "./legacyTreeTable";

/**
* The dashboardState of a legacy dashboard, useful for unit tests.
*/
export const legacyDashboard: LegacyDashboardState = {
name: "1 page, 3 widgets",
name: "1 page, 4 widgets",
type: "container",
value: {
style: {},
Expand All @@ -28,29 +29,40 @@ export const legacyDashboard: LegacyDashboardState = {
key: "3",
bookmark: legacyQuickFilter,
},
{ key: "4", bookmark: legacyPageFilters },
],
layout: {
children: {
"0": {
ck: "3",
size: 0.3,
size: 0.2,
ck: "4",
},
"1": {
size: 0.8,
children: {
"0": {
ck: "1",
size: 0.4,
ck: "3",
size: 0.3,
},
"1": {
ck: "2",
size: 0.6,
children: {
"0": {
ck: "1",
size: 0.4,
},
"1": {
ck: "2",
size: 0.6,
},
},
direction: "column",
size: 0.7,
},
},
direction: "column",
size: 0.7,
},
},
direction: "column",
direction: "row",
},
name: "Start page",
contextValues: {
Expand Down
15 changes: 15 additions & 0 deletions src/__test_resources__/legacyPageFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LegacyWidgetState } from "../migration.types";

/**
* The widgetState of a legacy Page Filters widget, useful for unit tests.
*/
export const legacyPageFilters: LegacyWidgetState = {
name: "Page filters",
value: {
containerKey: "filters",
showTitleBar: false,
body: {},
},
type: "container",
writable: false,
};
51 changes: 50 additions & 1 deletion src/__test_resources__/legacyUIFolder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ContentRecord } from "@activeviam/activeui-sdk";
import { legacySettingsFolder } from "../legacySettingsFolder";

/**
* The content of a legacy /ui folder on a Content Server, useful for unit tests.
*/
export const legacyUIFolder = {
export const legacyUIFolder: ContentRecord = {
entry: {
isDirectory: true,
owners: ["admin"],
Expand Down Expand Up @@ -488,6 +489,32 @@ export const legacyUIFolder = {
canWrite: true,
},
},
"0xb": {
entry: {
content:
'{"name":"Page filters","type":"container","value":{"style":{},"showTitleBar":true,"body":{},"containerKey":"filters"}}',
isDirectory: false,
owners: ["admin"],
readers: ["admin"],
timestamp: 1607879735685,
lastEditor: "admin",
canRead: true,
canWrite: true,
},
},
eef: {
entry: {
content:
'{"name":"1 page, 4 widgets","type":"container","value":{"style":{},"showTitleBar":false,"body":{"pages":[{"content":[{"key":"1","bookmark":{"name":"Tree table","type":"container","writable":true,"value":{"body":{"serverUrl":"http://localhost:9090","mdx":"SELECT NON EMPTY Hierarchize(DrilldownLevel([Currency].[Currency].[ALL].[AllMember])) ON ROWS, NON EMPTY [Measures].[contributors.COUNT] ON COLUMNS FROM (SELECT {[Currency].[Currency].[ALL].[AllMember].[GBP], [Currency].[Currency].[ALL].[AllMember].[JPY], [Currency].[Currency].[ALL].[AllMember].[USD]} ON COLUMNS FROM (SELECT TopCount(Filter([Geography].[City].Levels(1).Members, NOT IsEmpty([Measures].[contributors.COUNT])), 3, [Measures].[contributors.COUNT]) ON COLUMNS FROM [EquityDerivativesCube])) CELL PROPERTIES VALUE, FORMATTED_VALUE, BACK_COLOR, FORE_COLOR, FONT_FLAGS","contextValues":{"queriesTimeLimit":60,"mdx.casesensitive":true,"mdx.defaultmembers.[Geography].[City]":"[AllMember].[Berlin]"},"updateMode":"once","ranges":{"row":{"chunkSize":2000,"thresholdPercentage":0.1},"column":{"chunkSize":50,"thresholdPercentage":0.2}},"configuration":{"tabular":{"pinnedHeaderSelector":"member","sortingMode":"non-breaking","addButtonFilter":"numeric","cellRenderers":["tree-layout"],"statisticsShown":true,"columnsGroups":[{"captionProducer":"firstColumn","cellFactory":"kpi-status","selector":"kpi-status"},{"captionProducer":"firstColumn","cellFactory":"lookup","selector":"lookup"},{"captionProducer":"expiry","cellFactory":"expiry","selector":"kpi-expiry"},{"captionProducer":"columnMerge","cellFactory":{"args":{},"key":"treeCells"},"selector":"member"}],"hideAddButton":true,"defaultOptions":{},"expansion":{"automaticExpansion":true},"columns":[{"key":"c-treeCells-member","width":250}]}}},"containerKey":"pivot-table"}}},{"key":"2","bookmark":{"name":"Chart","type":"container","writable":true,"value":{"containerKey":"chart","body":{"configuration":{"type":"plotly-line-chart","plotly":{"data":{"overridesByTraceKey":{"[Measures].[pnlVega.SUM]":{"name":"Taux de marge","yaxis":"y2"}}},"layout":{"xaxis":{"showticklabels":false,"showgrid":false,"showline":false},"yaxis":{"showticklabels":true,"showline":false},"yaxis2":{"showticklabels":true,"showline":true,"side":"right","range":[-1000,1000],"overlaying":"y"},"margin":{"t":20,"l":20,"r":20,"b":20}}},"mapping":{"xAxis":["[Currency].[Currency].[Currency]"],"values":["[Measures].[pnlDelta.SUM]","[Measures].[pnlVega.SUM]"],"splitBy":[],"horizontalSubplots":[],"verticalSubplots":[]},"switchedTo":"plotly-line-chart"},"query":{"serverUrl":"http://localhost:9090","mdx":"SELECT NON EMPTY [Currency].[Currency].[Currency].Members ON ROWS, NON EMPTY {[Measures].[pnlDelta.SUM], [Measures].[pnlVega.SUM]} ON COLUMNS FROM [EquityDerivativesCube]","contextValues":{},"updateMode":"once"}}}}},{"key":"3","bookmark":{"name":"Quick filter","type":"container","writable":true,"value":{"containerKey":"quick-filter","body":{"configuration":{"displayedAsSelect":false,"multipleSelection":true},"filterKey":"explicit","levelDetails":{"cube":"EquityDerivativesCube","dimension":"Currency","hierarchy":"Currency","level":"Currency","caption":"Currency"}}}}},{"key":"4","bookmark":{"name":"Page filters","value":{"containerKey":"filters","showTitleBar":false,"body":{}},"type":"container","writable":false}}],"layout":{"children":{"0":{"size":0.2,"ck":"4"},"1":{"size":0.8,"children":{"0":{"ck":"3","size":0.3},"1":{"children":{"0":{"ck":"1","size":0.4},"1":{"ck":"2","size":0.6}},"direction":"column","size":0.7}},"direction":"column"}},"direction":"row"},"name":"Start page","contextValues":{"EquityDerivativesCube":{"mdx.lightCrossjoin":true},"EquityDerivativesCubeDist":{"mdx.aggressiveFormulaEvaluation":true}}}],"contextValues":{"EquityDerivativesCube":{"queriesTimeLimit":60,"mdx.casesensitive":true,"mdx.defaultmembers.[Geography].[City]":"[AllMember].[Berlin]"},"EquityDerivativesCubeDist":{"mdx.casesensitive":false,"mdx.defaultmembers.[Geography].[City]":"[AllMember].[Paris]"}}},"containerKey":"dashboard"},"writable":true}',
isDirectory: false,
owners: ["admin"],
readers: ["admin"],
timestamp: 1607879735685,
lastEditor: "admin",
canRead: true,
canWrite: true,
},
},
},
},
i18n: {
Expand Down Expand Up @@ -536,6 +563,28 @@ export const legacyUIFolder = {
canWrite: true,
},
children: {
"0xb": {
entry: {
isDirectory: true,
owners: ["admin"],
readers: ["admin"],
timestamp: 1607879735685,
lastEditor: "admin",
canRead: true,
canWrite: true,
},
},
eef: {
entry: {
isDirectory: true,
owners: ["admin"],
readers: ["admin"],
timestamp: 1607879735685,
lastEditor: "admin",
canRead: true,
canWrite: true,
},
},
e2b: {
entry: {
isDirectory: true,
Expand Down
10 changes: 10 additions & 0 deletions src/_getLegacyWidgetPluginKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LegacyWidgetState } from "./migration.types";

/**
* Returns the widget plugin key from an ActiveUI 4 widget state.
*/
export function _getLegacyWidgetPluginKey(
legacyWidgetState: LegacyWidgetState
): string {
return legacyWidgetState.value.containerKey;
}
Loading

0 comments on commit d8d51c4

Please sign in to comment.