Skip to content
Snippets Groups Projects
Unverified Commit 3841a666 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

[MLv2] Strip question marks off of keys in JS version of display info (#35886)

parent f13a9d32
No related branches found
No related tags found
No related merge requests found
......@@ -318,7 +318,7 @@ describe("availableDrillThrus", () => {
{
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
],
},
......@@ -333,7 +333,7 @@ describe("availableDrillThrus", () => {
{
type: "drill-thru/fk-details",
objectId: ORDERS_ROW_VALUES.USER_ID as string,
"manyPks?": false,
isManyPks: false,
},
],
},
......@@ -345,7 +345,7 @@ describe("availableDrillThrus", () => {
{
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
{
type: "drill-thru/quick-filter",
......@@ -361,7 +361,7 @@ describe("availableDrillThrus", () => {
{
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
{
type: "drill-thru/quick-filter",
......@@ -507,7 +507,7 @@ describe("availableDrillThrus", () => {
// {
// type: "drill-thru/fk-details",
// objectId: AGGREGATED_ORDERS_ROW_VALUES.PRODUCT_ID as number,
// "manyPks?": false,
// isManyPks: false,
// },
// {
// rowCount: 2, // FIXME: (metabase#32108) this should return real count of rows
......@@ -1189,7 +1189,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
},
{
......@@ -1200,7 +1200,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
},
{
......@@ -1211,7 +1211,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
},
{
......@@ -1222,7 +1222,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
},
{
......@@ -1233,7 +1233,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/zoom",
objectId: ORDERS_ROW_VALUES.ID as string,
"manyPks?": false,
isManyPks: false,
},
},
// endregion
......@@ -1251,7 +1251,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/fk-details",
objectId: ORDERS_ROW_VALUES.PRODUCT_ID as string,
"manyPks?": false,
isManyPks: false,
},
},
{
......@@ -1262,7 +1262,7 @@ describe("availableDrillThrus", () => {
expectedParameters: {
type: "drill-thru/fk-details",
objectId: ORDERS_ROW_VALUES.USER_ID as string,
"manyPks?": false,
isManyPks: false,
},
},
// endregion
......
......@@ -275,7 +275,7 @@ export type QuickFilterDrillThruInfo =
type ObjectDetailsDrillThruInfo<Type extends DrillThruType> =
BaseDrillThruInfo<Type> & {
objectId: string | number;
"manyPks?": boolean; // TODO [33479]: this should be "manyPks"
isManyPks: boolean;
};
export type PKDrillThruInfo = ObjectDetailsDrillThruInfo<"drill-thru/pk">;
export type ZoomDrillThruInfo = ObjectDetailsDrillThruInfo<"drill-thru/zoom">;
......
......@@ -8,6 +8,7 @@
:exclude
[filter])
(:require
[clojure.string :as str]
[clojure.walk :as walk]
[goog.object :as gobject]
[medley.core :as m]
......@@ -146,9 +147,18 @@
;; In contrast, the CLJS -> JS conversion doesn't know about queries, so it can use `=`-based LRU caches.
(declare ^:private display-info->js)
(defn- cljs-key->js-key [cljs-key]
(let [key-str (u/qualified-name cljs-key)
;; if the key is something like `many-pks?` convert it to something that is more JS-friendly (remove the
;; question mark), `:is-many-pks`, which becomes `isManyPks`
key-str (if (str/ends-with? key-str "?")
(str "is-" (str/replace key-str #"\?$" ""))
key-str)]
(u/->camelCaseEn key-str)))
(defn- display-info-map->js* [x]
(reduce (fn [obj [cljs-key cljs-val]]
(let [js-key (-> cljs-key u/qualified-name u/->camelCaseEn)
(let [js-key (cljs-key->js-key cljs-key)
js-val (display-info->js cljs-val)] ;; Recursing through the cache
(gobject/set obj js-key js-val)
obj))
......
......@@ -133,3 +133,7 @@
(deftest ^:parallel is-column-metadata-test
(is (true? (lib.js/is-column-metadata (meta/field-metadata :venues :id))))
(is (false? (lib.js/is-column-metadata 1))))
(deftest ^:parallel cljs-key->js-key-test
(is (= "isManyPks"
(#'lib.js/cljs-key->js-key :many-pks?))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment