@databrainhq/plugin 0.6.0 → 0.6.1

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.
@@ -11,6 +11,8 @@ export declare type MetricCardProps = {
11
11
  client: ClientType['value'];
12
12
  onMaximize: (chart: MetricChartProps) => void;
13
13
  colors?: string[];
14
+ param?: any;
15
+ companyTenancyType: string;
14
16
  };
15
17
  declare const MetricCard: React.FC<MetricCardProps>;
16
18
  export default MetricCard;
@@ -6,7 +6,7 @@ export declare type ExternalMetricListProps = {
6
6
  chartColors?: string[];
7
7
  globalFilters?: MetricCardProps['globalFilters'];
8
8
  client: ClientType['value'];
9
- isLiveMode?: string;
9
+ isLiveMode: boolean;
10
10
  isMetricListLoading?: boolean;
11
11
  breakpoint: ThemeType['breakpoint'];
12
12
  layoutCols: ThemeType['metricLayoutCols'];
@@ -38,6 +38,8 @@ export declare type ExternalMetricListProps = {
38
38
  updatedAt: any;
39
39
  };
40
40
  }[] | undefined;
41
+ params?: any;
42
+ companyTenancyType: string;
41
43
  };
42
44
  declare const _default: React.NamedExoticComponent<ExternalMetricListProps>;
43
45
  export default _default;
@@ -46,6 +46,8 @@ declare const useEmbeddedDashboard: (token: string) => {
46
46
  filters: any;
47
47
  } | undefined;
48
48
  rlsSettings: any;
49
+ companyTenancyType: any;
50
+ isAllowedToCreateMetrics: boolean;
49
51
  };
50
52
  };
51
53
  export default useEmbeddedDashboard;
package/dist/index.es.js CHANGED
@@ -94102,6 +94102,18 @@ const useGuestTokenParamsQuery = (variables, options2) => useQuery(
94102
94102
  fetcher(GuestTokenParamsDocument, variables),
94103
94103
  options2
94104
94104
  );
94105
+ const MetricCreationAccessDocument = `
94106
+ query MetricCreationAccess($companyId: uuid = "") {
94107
+ companySubsetTables(where: {companyId: {_eq: $companyId}}) {
94108
+ isAllowMetricCreation
94109
+ }
94110
+ }
94111
+ `;
94112
+ const useMetricCreationAccessQuery = (variables, options2) => useQuery(
94113
+ variables === void 0 ? ["MetricCreationAccess"] : ["MetricCreationAccess", variables],
94114
+ fetcher(MetricCreationAccessDocument, variables),
94115
+ options2
94116
+ );
94105
94117
  const PreviewTableDocument = `
94106
94118
  mutation PreviewTable($companyId: String = "", $tableName: String = "", $limit: Int = 10) {
94107
94119
  previewTable(
@@ -94124,9 +94136,9 @@ const usePreviewTableMutation = (options2) => useMutation(
94124
94136
  options2
94125
94137
  );
94126
94138
  const QueryExternalMetricDocument = `
94127
- query QueryExternalMetric($id: String = "", $clientId: String = "", $globalFilters: json = "", $rlsConditions: json = []) {
94139
+ query QueryExternalMetric($id: String = "", $clientId: String = "", $globalFilters: json = "", $rlsConditions: json = [], $filterValues: json = "", $tenancyLevel: String = "") {
94128
94140
  externalMetricQuery(
94129
- input: {externalMetricId: $id, clientId: $clientId, globalFilters: $globalFilters, rlsConditions: $rlsConditions}
94141
+ input: {externalMetricId: $id, clientId: $clientId, globalFilters: $globalFilters, rlsConditions: $rlsConditions, filterValues: $filterValues, tenancyLevel: $tenancyLevel}
94130
94142
  ) {
94131
94143
  data
94132
94144
  timeTaken
@@ -97721,13 +97733,25 @@ const RlsFilters = ({
97721
97733
  });
97722
97734
  };
97723
97735
  const MetricCard = ({
97724
- globalFilters,
97736
+ globalFilters = {
97737
+ tableName: "",
97738
+ filters: []
97739
+ },
97725
97740
  metricItem,
97726
97741
  onMaximize,
97727
97742
  client,
97728
- colors: colors2
97743
+ colors: colors2,
97744
+ param,
97745
+ companyTenancyType
97729
97746
  }) => {
97730
97747
  var _a2;
97748
+ const filterValues2 = {};
97749
+ if (param == null ? void 0 : param.values) {
97750
+ for (const key in param.values) {
97751
+ const newKey = `${key}_variable`;
97752
+ filterValues2[newKey] = param.values[key];
97753
+ }
97754
+ }
97731
97755
  const [chartType2, setChartType] = useState("");
97732
97756
  const [xAxis, setXAxis] = useState("");
97733
97757
  const [yAxisList, setYAxisList] = useState([]);
@@ -97743,8 +97767,16 @@ const MetricCard = ({
97743
97767
  } = useQueryExternalMetricQuery({
97744
97768
  id: metricItem == null ? void 0 : metricItem.id,
97745
97769
  clientId: client,
97746
- rlsConditions,
97747
- globalFilters
97770
+ tenancyLevel: companyTenancyType,
97771
+ rlsConditions: companyTenancyType === "DATABASE" ? rlsConditions.map((c2) => ({
97772
+ ...c2,
97773
+ tableName: `${client}.${c2.tableName.split(".").slice(1).join(".")}`
97774
+ })) : rlsConditions,
97775
+ globalFilters: companyTenancyType === "DATABASE" ? {
97776
+ ...globalFilters,
97777
+ tableName: `${client}.${globalFilters.tableName.split(".").slice(1).join(".")}`
97778
+ } : globalFilters,
97779
+ filterValues: filterValues2
97748
97780
  });
97749
97781
  const queryData = (_a2 = metricdata == null ? void 0 : metricdata.externalMetricQuery) == null ? void 0 : _a2.data;
97750
97782
  const [margins, setMargins] = useState({
@@ -97950,11 +97982,23 @@ const MetricCard = ({
97950
97982
  });
97951
97983
  };
97952
97984
  const SingleValueCard = ({
97953
- globalFilters,
97985
+ globalFilters = {
97986
+ tableName: "",
97987
+ filters: []
97988
+ },
97954
97989
  metricItem,
97955
- client
97990
+ client,
97991
+ param,
97992
+ companyTenancyType
97956
97993
  }) => {
97957
97994
  var _a2;
97995
+ const filterValues2 = {};
97996
+ if (param == null ? void 0 : param.values) {
97997
+ for (const key in param.values) {
97998
+ const newKey = `${key}_variable`;
97999
+ filterValues2[newKey] = param.values[key];
98000
+ }
98001
+ }
97958
98002
  const [chartType2, setChartType] = useState("");
97959
98003
  const [singleValue2, setSingleValue] = useState("");
97960
98004
  const [dataDb, setData] = useState([]);
@@ -97965,8 +98009,16 @@ const SingleValueCard = ({
97965
98009
  } = useQueryExternalMetricQuery({
97966
98010
  id: metricItem == null ? void 0 : metricItem.id,
97967
98011
  clientId: client,
97968
- rlsConditions,
97969
- globalFilters
98012
+ tenancyLevel: companyTenancyType,
98013
+ rlsConditions: companyTenancyType === "DATABASE" ? rlsConditions.map((c2) => ({
98014
+ ...c2,
98015
+ tableName: `${client}.${c2.tableName.split(".").slice(1).join(".")}`
98016
+ })) : rlsConditions,
98017
+ globalFilters: companyTenancyType === "DATABASE" ? {
98018
+ ...globalFilters,
98019
+ tableName: `${client}.${globalFilters.tableName.split(".").slice(1).join(".")}`
98020
+ } : globalFilters,
98021
+ filterValues: filterValues2
97970
98022
  });
97971
98023
  const queryData = (_a2 = metricdata == null ? void 0 : metricdata.externalMetricQuery) == null ? void 0 : _a2.data;
97972
98024
  useEffect(() => {
@@ -98065,7 +98117,9 @@ const ExternalMetricList = ({
98065
98117
  externalDashboardMetrics,
98066
98118
  isMetricListLoading,
98067
98119
  breakpoint,
98068
- layoutCols
98120
+ layoutCols,
98121
+ params,
98122
+ companyTenancyType = "TABLE"
98069
98123
  }) => {
98070
98124
  const [isFullScreen, setFullScreen] = useState(false);
98071
98125
  const [fullScreenChart, setFullScreenChart] = useState();
@@ -98073,8 +98127,8 @@ const ExternalMetricList = ({
98073
98127
  const adminMetrics = metricListData == null ? void 0 : metricListData.filter((data) => !data.isCreatedByClient);
98074
98128
  const clientMetrics = metricListData == null ? void 0 : metricListData.filter((data) => data.isCreatedByClient && data.clientId === client);
98075
98129
  const metricsList = [...adminMetrics || [], ...clientMetrics || []].filter((data) => {
98076
- if (JSON.parse(isLiveMode || "")) {
98077
- return data.isLive === JSON.parse(isLiveMode || "");
98130
+ if (isLiveMode) {
98131
+ return data.isLive === isLiveMode;
98078
98132
  }
98079
98133
  return true;
98080
98134
  });
@@ -98122,7 +98176,9 @@ const ExternalMetricList = ({
98122
98176
  children: metricItem.chartOptions.chartType === "single value" ? /* @__PURE__ */ jsx(SingleValueCard, {
98123
98177
  metricItem,
98124
98178
  client,
98125
- globalFilters
98179
+ globalFilters,
98180
+ param: params == null ? void 0 : params.find((obj) => obj.metricId === metricItem.metricId),
98181
+ companyTenancyType
98126
98182
  }) : /* @__PURE__ */ jsx(MetricCard, {
98127
98183
  metricItem,
98128
98184
  onMaximize: (chart) => {
@@ -98131,7 +98187,9 @@ const ExternalMetricList = ({
98131
98187
  },
98132
98188
  client,
98133
98189
  colors: chartColors,
98134
- globalFilters
98190
+ globalFilters,
98191
+ param: params == null ? void 0 : params.find((obj) => obj.metricId === metricItem.metricId),
98192
+ companyTenancyType
98135
98193
  })
98136
98194
  }, metricItem.id))
98137
98195
  })
@@ -101868,6 +101926,7 @@ const useEmbeddedDashboard = (token) => {
101868
101926
  const clientId = tokenParams == null ? void 0 : tokenParams.clientId;
101869
101927
  const mode = (_b2 = params == null ? void 0 : params.dashboard) == null ? void 0 : _b2.isLive;
101870
101928
  const rlsSettings = params == null ? void 0 : params.rlsSettings;
101929
+ const companyTenancyType = params == null ? void 0 : params.companyTenancyType;
101871
101930
  const {
101872
101931
  data: externalDashboardMetricsData,
101873
101932
  isLoading: isExternalDashboardMetricsDataLoading
@@ -101883,15 +101942,19 @@ const useEmbeddedDashboard = (token) => {
101883
101942
  );
101884
101943
  const { data: idData, isLoading: isLoadingId } = useGetExternalDashboardIdQuery({ externalDashboardId });
101885
101944
  const externalDashboardMetrics = externalDashboardMetricsData == null ? void 0 : externalDashboardMetricsData.externalDashboardMetrics;
101945
+ const { data: accessData, isLoading: isLoadingAccessData } = useMetricCreationAccessQuery({ companyId });
101946
+ const isAllowedToCreateMetrics = (accessData == null ? void 0 : accessData.companySubsetTables.length) ? accessData == null ? void 0 : accessData.companySubsetTables[0].isAllowMetricCreation : false;
101886
101947
  return {
101887
- isLoading: isParamsLoading || isExternalDashboardMetricsDataLoading || isLoadingId,
101948
+ isLoading: isParamsLoading || isExternalDashboardMetricsDataLoading || isLoadingId || isLoadingAccessData,
101888
101949
  data: {
101889
101950
  clientId,
101890
101951
  companyId,
101891
101952
  mode,
101892
101953
  externalDashboardMetrics,
101893
101954
  externalDashboard: idData == null ? void 0 : idData.externalDashboards[0],
101894
- rlsSettings
101955
+ rlsSettings,
101956
+ companyTenancyType: companyTenancyType || "TABLE",
101957
+ isAllowedToCreateMetrics
101895
101958
  }
101896
101959
  };
101897
101960
  };
@@ -102449,7 +102512,7 @@ const EmbeddedDashboard = React__default.memo(({
102449
102512
  }) : /* @__PURE__ */ jsx(icOutlineFilterAlt, {
102450
102513
  className: styles$B.floatingFilterButtonIcon
102451
102514
  })
102452
- }) : null, !(options2 == null ? void 0 : options2.disableMetricCreation) && /* @__PURE__ */ jsx(EmbeddedMetricCreation, {
102515
+ }) : null, !(options2 == null ? void 0 : options2.disableMetricCreation) && data.isAllowedToCreateMetrics && /* @__PURE__ */ jsx(EmbeddedMetricCreation, {
102453
102516
  clientId: data.clientId,
102454
102517
  companyId: data.companyId,
102455
102518
  mode: data.mode,
@@ -102471,7 +102534,9 @@ const EmbeddedDashboard = React__default.memo(({
102471
102534
  globalFilters,
102472
102535
  breakpoint: theme2 == null ? void 0 : theme2.breakpoint,
102473
102536
  layoutCols: theme2 == null ? void 0 : theme2.metricLayoutCols,
102474
- chartColors: options2 == null ? void 0 : options2.chartColors
102537
+ chartColors: options2 == null ? void 0 : options2.chartColors,
102538
+ params: Array.isArray(data.rlsSettings) ? data.rlsSettings : [],
102539
+ companyTenancyType: data.companyTenancyType
102475
102540
  })]
102476
102541
  })]
102477
102542
  }), isLoading && /* @__PURE__ */ jsx("div", {