diff --git a/superset-frontend/src/dashboard/components/gridComponents/Chart/index.js b/superset-frontend/src/dashboard/components/gridComponents/Chart/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Chart/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Chart/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Column/index.js b/superset-frontend/src/dashboard/components/gridComponents/Column/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Column/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Column/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Divider/index.js b/superset-frontend/src/dashboard/components/gridComponents/Divider/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Divider/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Divider/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Markdown/index.js b/superset-frontend/src/dashboard/components/gridComponents/Markdown/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Markdown/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Markdown/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tab/index.js b/superset-frontend/src/dashboard/components/gridComponents/Tab/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Tab/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Tab/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Tabs/index.js b/superset-frontend/src/dashboard/components/gridComponents/Tabs/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/Tabs/index.js rename to superset-frontend/src/dashboard/components/gridComponents/Tabs/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/index.js b/superset-frontend/src/dashboard/components/gridComponents/index.ts similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/index.js rename to superset-frontend/src/dashboard/components/gridComponents/index.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/new/NewColumn.jsx b/superset-frontend/src/dashboard/components/gridComponents/new/NewColumn.tsx similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/new/NewColumn.jsx rename to superset-frontend/src/dashboard/components/gridComponents/new/NewColumn.tsx diff --git a/superset-frontend/src/dashboard/components/gridComponents/new/NewDivider.jsx b/superset-frontend/src/dashboard/components/gridComponents/new/NewDivider.tsx similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/new/NewDivider.jsx rename to superset-frontend/src/dashboard/components/gridComponents/new/NewDivider.tsx diff --git a/superset-frontend/src/dashboard/components/gridComponents/new/NewHeader.jsx b/superset-frontend/src/dashboard/components/gridComponents/new/NewHeader.tsx similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/new/NewHeader.jsx rename to superset-frontend/src/dashboard/components/gridComponents/new/NewHeader.tsx diff --git a/superset-frontend/src/dashboard/components/gridComponents/new/NewMarkdown.jsx b/superset-frontend/src/dashboard/components/gridComponents/new/NewMarkdown.tsx similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/new/NewMarkdown.jsx rename to superset-frontend/src/dashboard/components/gridComponents/new/NewMarkdown.tsx diff --git a/superset-frontend/src/dashboard/components/gridComponents/new/NewTabs.jsx b/superset-frontend/src/dashboard/components/gridComponents/new/NewTabs.tsx similarity index 100% rename from superset-frontend/src/dashboard/components/gridComponents/new/NewTabs.jsx rename to superset-frontend/src/dashboard/components/gridComponents/new/NewTabs.tsx diff --git a/superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.js b/superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.ts similarity index 77% rename from superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.js rename to superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.ts index ac31b58aafd..2f5a5fb84ff 100644 --- a/superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.js +++ b/superset-frontend/src/dashboard/util/getChartAndLabelComponentIdFromPath.ts @@ -18,13 +18,17 @@ */ import { IN_COMPONENT_ELEMENT_TYPES } from './constants'; -export default function getChartAndLabelComponentIdFromPath(directPathToChild) { - const result = {}; +export default function getChartAndLabelComponentIdFromPath( + directPathToChild: (string | undefined)[], +): Record { + const result: Record = {}; if (directPathToChild.length > 0) { - const currentPath = directPathToChild.slice().filter(x => x !== undefined); + const currentPath = directPathToChild + .slice() + .filter((x): x is string => x !== undefined); while (currentPath.length) { - const componentId = currentPath.pop(); + const componentId = currentPath.pop()!; const componentType = componentId.split('-')[0]; result[componentType.toLowerCase()] = componentId; diff --git a/superset-frontend/src/dashboard/util/getFilterScopeParentNodes.js b/superset-frontend/src/dashboard/util/getFilterScopeParentNodes.ts similarity index 70% rename from superset-frontend/src/dashboard/util/getFilterScopeParentNodes.js rename to superset-frontend/src/dashboard/util/getFilterScopeParentNodes.ts index 8330c64cf33..0ac7747206a 100644 --- a/superset-frontend/src/dashboard/util/getFilterScopeParentNodes.js +++ b/superset-frontend/src/dashboard/util/getFilterScopeParentNodes.ts @@ -16,15 +16,28 @@ * specific language governing permissions and limitations * under the License. */ -export default function getFilterScopeParentNodes(nodes = [], depthLimit = -1) { - const parentNodes = []; - const traverse = (currentNode, depth) => { +interface FilterScopeTreeNode { + value?: string | number; + children?: FilterScopeTreeNode[]; +} + +export default function getFilterScopeParentNodes( + nodes: FilterScopeTreeNode[] = [], + depthLimit = -1, +): string[] { + const parentNodes: string[] = []; + const traverse = ( + currentNode: FilterScopeTreeNode | undefined, + depth: number, + ): void => { if (!currentNode) { return; } if (currentNode.children && (depthLimit === -1 || depth < depthLimit)) { - parentNodes.push(currentNode.value); + if (currentNode.value !== undefined) { + parentNodes.push(String(currentNode.value)); + } currentNode.children.forEach(child => traverse(child, depth + 1)); } }; diff --git a/superset-frontend/src/dashboard/util/serializeActiveFilterValues.js b/superset-frontend/src/dashboard/util/serializeActiveFilterValues.ts similarity index 59% rename from superset-frontend/src/dashboard/util/serializeActiveFilterValues.js rename to superset-frontend/src/dashboard/util/serializeActiveFilterValues.ts index 6497b107c0d..32c74458011 100644 --- a/superset-frontend/src/dashboard/util/serializeActiveFilterValues.js +++ b/superset-frontend/src/dashboard/util/serializeActiveFilterValues.ts @@ -18,19 +18,31 @@ */ import { getChartIdAndColumnFromFilterKey } from './getDashboardFilterKey'; +interface ActiveFilterEntry { + values: unknown; +} + +type ActiveFiltersInput = Record; +type SerializedFilters = Record>; + // input: { [id_column1]: values, [id_column2]: values } // output: { id: { column1: values, column2: values } } -export default function serializeActiveFilterValues(activeFilters) { - return Object.entries(activeFilters).reduce((map, entry) => { - const [filterKey, { values }] = entry; - const { chartId, column } = getChartIdAndColumnFromFilterKey(filterKey); - const entryByChartId = { - ...map[chartId], - [column]: values, - }; - return { - ...map, - [chartId]: entryByChartId, - }; - }, {}); +export default function serializeActiveFilterValues( + activeFilters: ActiveFiltersInput, +): SerializedFilters { + return Object.entries(activeFilters).reduce( + (map, entry) => { + const [filterKey, { values }] = entry; + const { chartId, column } = getChartIdAndColumnFromFilterKey(filterKey); + const entryByChartId = { + ...map[chartId], + [column]: values, + }; + return { + ...map, + [chartId]: entryByChartId, + }; + }, + {}, + ); }