@datawheel/data-explorer 1.0.10 → 1.0.11
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.
- package/dist/main.mjs +148 -141
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -4209,6 +4209,150 @@ function Toolbar({
|
|
|
4209
4209
|
return smallerThanLg ? /* @__PURE__ */ React13__default.createElement(Menu, null, /* @__PURE__ */ React13__default.createElement(Menu.Target, null, /* @__PURE__ */ React13__default.createElement(ActionIcon, null, /* @__PURE__ */ React13__default.createElement(IconSettings, null))), /* @__PURE__ */ React13__default.createElement(Menu.Dropdown, null, settings)) : settings;
|
|
4210
4210
|
}
|
|
4211
4211
|
|
|
4212
|
+
// src/context/query.tsx
|
|
4213
|
+
init_esm_shims();
|
|
4214
|
+
var QueryContext = createContext(void 0);
|
|
4215
|
+
function QueryProvider({ children, defaultCube }) {
|
|
4216
|
+
const { tesseract } = useLogicLayer();
|
|
4217
|
+
const location2 = useLocation();
|
|
4218
|
+
const { updateCurrentQuery } = useActions();
|
|
4219
|
+
const { paginationConfig, measuresActive, serverURL, defaultLocale } = useSettings();
|
|
4220
|
+
const { data: schema, isLoading: schemaLoading, isError: schemaError } = useServerSchema();
|
|
4221
|
+
const updateUrl = useUpdateUrl();
|
|
4222
|
+
const queryItem = useSelector$1(selectCurrentQueryItem);
|
|
4223
|
+
const prevLocaleRef = useRef();
|
|
4224
|
+
function fetchMembers(level, localeStr, cubeName) {
|
|
4225
|
+
return tesseract.fetchMembers({ request: { cube: cubeName || "", level, locale: localeStr } });
|
|
4226
|
+
}
|
|
4227
|
+
const {
|
|
4228
|
+
run: runFetchMembers,
|
|
4229
|
+
data: membersData,
|
|
4230
|
+
isSuccess: isMembersSuccess,
|
|
4231
|
+
isLoading: membersLoading
|
|
4232
|
+
} = useAsync();
|
|
4233
|
+
const [transintionLocaleLoading, setTransintionLocaleLoading] = React13__default.useState(false);
|
|
4234
|
+
useEffect(() => {
|
|
4235
|
+
if (schemaLoading) {
|
|
4236
|
+
setTransintionLocaleLoading(true);
|
|
4237
|
+
}
|
|
4238
|
+
const searchParams = new URLSearchParams(location2.search);
|
|
4239
|
+
const cube = searchParams.get("cube");
|
|
4240
|
+
const cubeMap = (schema == null ? void 0 : schema.cubeMap) || void 0;
|
|
4241
|
+
if (cube && cubeMap && serverURL && cubeMap[cube] && (schema == null ? void 0 : schema.online)) {
|
|
4242
|
+
let newQuery = parsePermalink(cubeMap[cube], searchParams);
|
|
4243
|
+
newQuery = isValidQuery(newQuery == null ? void 0 : newQuery.params) ? newQuery : buildQuery({ params: { cube } });
|
|
4244
|
+
newQuery.params.locale = defaultLocale || newQuery.params.locale;
|
|
4245
|
+
if (newQuery) {
|
|
4246
|
+
const promises = Object.values(newQuery.params.drilldowns).map((dd) => {
|
|
4247
|
+
const currentDrilldown = queryItem.params.drilldowns[dd.key];
|
|
4248
|
+
const localeChanged = prevLocaleRef.current !== (newQuery == null ? void 0 : newQuery.params.locale);
|
|
4249
|
+
if (currentDrilldown && currentDrilldown.members && currentDrilldown.members.length > 0 && !localeChanged) {
|
|
4250
|
+
return Promise.resolve({
|
|
4251
|
+
drilldown: currentDrilldown,
|
|
4252
|
+
cut: buildCut({ ...currentDrilldown, active: false })
|
|
4253
|
+
});
|
|
4254
|
+
} else {
|
|
4255
|
+
return fetchMembers(dd.level, newQuery == null ? void 0 : newQuery.params.locale, cube).then((levelMeta) => {
|
|
4256
|
+
const cut = buildCut({ ...dd, active: false });
|
|
4257
|
+
return {
|
|
4258
|
+
drilldown: {
|
|
4259
|
+
...dd,
|
|
4260
|
+
members: levelMeta.members
|
|
4261
|
+
},
|
|
4262
|
+
cut
|
|
4263
|
+
};
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
});
|
|
4267
|
+
runFetchMembers(Promise.all(promises)).then((data) => {
|
|
4268
|
+
setTransintionLocaleLoading(false);
|
|
4269
|
+
prevLocaleRef.current = newQuery == null ? void 0 : newQuery.params.locale;
|
|
4270
|
+
const drilldowns = data.map((item) => item.drilldown);
|
|
4271
|
+
const cuts = data.map((item) => item.cut);
|
|
4272
|
+
newQuery.params.drilldowns = keyBy(drilldowns, "key");
|
|
4273
|
+
const existingCuts = keyBy(
|
|
4274
|
+
Object.values(newQuery.params.cuts || {}).map((c) => ({ ...c, key: c.level })),
|
|
4275
|
+
"key"
|
|
4276
|
+
);
|
|
4277
|
+
const newCuts = keyBy(cuts, "key");
|
|
4278
|
+
newQuery.params.cuts = { ...newCuts, ...existingCuts };
|
|
4279
|
+
const newQueryItem = isValidQuery(newQuery.params) ? newQuery : void 0;
|
|
4280
|
+
if (newQueryItem) {
|
|
4281
|
+
updateCurrentQuery({ ...newQuery, link: serializePermalink(newQuery) });
|
|
4282
|
+
}
|
|
4283
|
+
});
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
if (!cube && cubeMap && serverURL && (schema == null ? void 0 : schema.online)) {
|
|
4287
|
+
const cubeDefault = defaultCube && hasProperty(cubeMap, defaultCube) ? defaultCube : Object.keys(cubeMap)[0];
|
|
4288
|
+
setDefaultValues(cubeMap[cubeDefault]);
|
|
4289
|
+
}
|
|
4290
|
+
}, [location2.search, runFetchMembers, schema, schemaLoading, serverURL, defaultLocale]);
|
|
4291
|
+
const onChangeCube = (table, subtopic) => {
|
|
4292
|
+
const locale = defaultLocale || queryItem.params.locale;
|
|
4293
|
+
const cubeMap = (schema == null ? void 0 : schema.cubeMap) || {};
|
|
4294
|
+
const cubeArray = getValues(cubeMap);
|
|
4295
|
+
const cube = cubeArray.find(
|
|
4296
|
+
(cube2) => cube2.name === table && getAnnotation(cube2, "subtopic", locale) === subtopic
|
|
4297
|
+
);
|
|
4298
|
+
if (cube) {
|
|
4299
|
+
setDefaultValues(cube);
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
function setDefaultValues(cube) {
|
|
4303
|
+
const drilldowns = pickDefaultDrilldowns(cube.dimensions).map(
|
|
4304
|
+
(level) => buildDrilldown({
|
|
4305
|
+
...level,
|
|
4306
|
+
key: level.name,
|
|
4307
|
+
active: true,
|
|
4308
|
+
properties: level.properties.map(
|
|
4309
|
+
(prop) => buildProperty({ level: level.name, name: prop.name })
|
|
4310
|
+
)
|
|
4311
|
+
})
|
|
4312
|
+
);
|
|
4313
|
+
const measuresLimit = typeof measuresActive !== "undefined" ? measuresActive : cube.measures.length;
|
|
4314
|
+
const measures = cube.measures.slice(0, measuresLimit).map((measure) => {
|
|
4315
|
+
return buildMeasure({
|
|
4316
|
+
active: true,
|
|
4317
|
+
key: measure.name,
|
|
4318
|
+
name: measure.name,
|
|
4319
|
+
caption: measure.caption
|
|
4320
|
+
});
|
|
4321
|
+
});
|
|
4322
|
+
const panel = queryItem.panel;
|
|
4323
|
+
const locale = defaultLocale || queryItem.params.locale;
|
|
4324
|
+
const query = buildQuery({
|
|
4325
|
+
params: {
|
|
4326
|
+
cube: cube.name,
|
|
4327
|
+
measures: keyBy(measures, (item) => item.key),
|
|
4328
|
+
drilldowns: keyBy(drilldowns, (item) => item.key),
|
|
4329
|
+
locale
|
|
4330
|
+
},
|
|
4331
|
+
panel: panel != null ? panel : "table"
|
|
4332
|
+
});
|
|
4333
|
+
updateUrl(query);
|
|
4334
|
+
}
|
|
4335
|
+
return /* @__PURE__ */ React13__default.createElement(
|
|
4336
|
+
QueryContext.Provider,
|
|
4337
|
+
{
|
|
4338
|
+
value: {
|
|
4339
|
+
onChangeCube,
|
|
4340
|
+
schemaLoading,
|
|
4341
|
+
membersLoading,
|
|
4342
|
+
transintionLocaleLoading
|
|
4343
|
+
}
|
|
4344
|
+
},
|
|
4345
|
+
children
|
|
4346
|
+
);
|
|
4347
|
+
}
|
|
4348
|
+
function useQueryItem() {
|
|
4349
|
+
const context = useContext(QueryContext);
|
|
4350
|
+
if (context === void 0) {
|
|
4351
|
+
throw new Error("useQuery must be used within a QueryProvider");
|
|
4352
|
+
}
|
|
4353
|
+
return context;
|
|
4354
|
+
}
|
|
4355
|
+
|
|
4212
4356
|
// src/components/ExplorerResults.tsx
|
|
4213
4357
|
var useStyles2 = createStyles(() => ({
|
|
4214
4358
|
container: {
|
|
@@ -4224,6 +4368,7 @@ function ExplorerResults(props) {
|
|
|
4224
4368
|
isError: schemaError,
|
|
4225
4369
|
error: schemaErrorDetail
|
|
4226
4370
|
} = useServerSchema();
|
|
4371
|
+
const { transintionLocaleLoading } = useQueryItem();
|
|
4227
4372
|
const { params } = useSelector$1(selectCurrentQueryItem);
|
|
4228
4373
|
const cubeMap = (schema == null ? void 0 : schema.cubeMap) || {};
|
|
4229
4374
|
const cube = cubeMap[params.cube];
|
|
@@ -4251,7 +4396,7 @@ function ExplorerResults(props) {
|
|
|
4251
4396
|
}
|
|
4252
4397
|
);
|
|
4253
4398
|
}
|
|
4254
|
-
if (isServerOnline == null || !cube) {
|
|
4399
|
+
if (isServerOnline == null || !cube || schemaLoading || transintionLocaleLoading) {
|
|
4255
4400
|
return /* @__PURE__ */ React13__default.createElement(
|
|
4256
4401
|
Paper,
|
|
4257
4402
|
{
|
|
@@ -4396,7 +4541,7 @@ init_esm_shims();
|
|
|
4396
4541
|
|
|
4397
4542
|
// src/utils/create-context.ts
|
|
4398
4543
|
init_esm_shims();
|
|
4399
|
-
var
|
|
4544
|
+
var createContext4 = (name4) => {
|
|
4400
4545
|
const Context = React13__default.createContext(void 0);
|
|
4401
4546
|
const useContext5 = () => {
|
|
4402
4547
|
const ctx = React13__default.useContext(Context);
|
|
@@ -4609,7 +4754,7 @@ function useCubeSearch(input, graph) {
|
|
|
4609
4754
|
}
|
|
4610
4755
|
|
|
4611
4756
|
// src/components/SideBar.tsx
|
|
4612
|
-
var [useSideBar, Provider] =
|
|
4757
|
+
var [useSideBar, Provider] = createContext4("SideBar");
|
|
4613
4758
|
function SideBarProvider(props) {
|
|
4614
4759
|
const [input, setInput] = useDebouncedState("", 200);
|
|
4615
4760
|
const [expanded, setExpanded] = useState(true);
|
|
@@ -4808,143 +4953,6 @@ init_esm_shims();
|
|
|
4808
4953
|
|
|
4809
4954
|
// src/components/Results.tsx
|
|
4810
4955
|
init_esm_shims();
|
|
4811
|
-
|
|
4812
|
-
// src/context/query.tsx
|
|
4813
|
-
init_esm_shims();
|
|
4814
|
-
var QueryContext = createContext(void 0);
|
|
4815
|
-
function QueryProvider({ children, defaultCube }) {
|
|
4816
|
-
const { tesseract } = useLogicLayer();
|
|
4817
|
-
const location2 = useLocation();
|
|
4818
|
-
const { updateCurrentQuery } = useActions();
|
|
4819
|
-
const { paginationConfig, measuresActive, serverURL, defaultLocale } = useSettings();
|
|
4820
|
-
const { data: schema, isLoading: schemaLoading, isError: schemaError } = useServerSchema();
|
|
4821
|
-
const updateUrl = useUpdateUrl();
|
|
4822
|
-
const queryItem = useSelector$1(selectCurrentQueryItem);
|
|
4823
|
-
function fetchMembers(level, localeStr, cubeName) {
|
|
4824
|
-
return tesseract.fetchMembers({ request: { cube: cubeName || "", level, locale: localeStr } });
|
|
4825
|
-
}
|
|
4826
|
-
const {
|
|
4827
|
-
run: runFetchMembers,
|
|
4828
|
-
data: membersData,
|
|
4829
|
-
isSuccess: isMembersSuccess,
|
|
4830
|
-
isLoading: membersLoading
|
|
4831
|
-
} = useAsync();
|
|
4832
|
-
useEffect(() => {
|
|
4833
|
-
const searchParams = new URLSearchParams(location2.search);
|
|
4834
|
-
const cube = searchParams.get("cube");
|
|
4835
|
-
const cubeMap = (schema == null ? void 0 : schema.cubeMap) || void 0;
|
|
4836
|
-
if (cube && cubeMap && serverURL && cubeMap[cube] && (schema == null ? void 0 : schema.online)) {
|
|
4837
|
-
let newQuery = parsePermalink(cubeMap[cube], searchParams);
|
|
4838
|
-
newQuery = isValidQuery(newQuery == null ? void 0 : newQuery.params) ? newQuery : buildQuery({ params: { cube } });
|
|
4839
|
-
newQuery.params.locale = defaultLocale || newQuery.params.locale;
|
|
4840
|
-
if (newQuery) {
|
|
4841
|
-
const promises = Object.values(newQuery.params.drilldowns).map((dd) => {
|
|
4842
|
-
const currentDrilldown = queryItem.params.drilldowns[dd.key];
|
|
4843
|
-
if (currentDrilldown && currentDrilldown.members && currentDrilldown.members.length > 0) {
|
|
4844
|
-
return Promise.resolve({
|
|
4845
|
-
drilldown: currentDrilldown,
|
|
4846
|
-
cut: buildCut({ ...currentDrilldown, active: false })
|
|
4847
|
-
});
|
|
4848
|
-
} else {
|
|
4849
|
-
return fetchMembers(dd.level, newQuery == null ? void 0 : newQuery.params.locale, cube).then((levelMeta) => {
|
|
4850
|
-
const cut = buildCut({ ...dd, active: false });
|
|
4851
|
-
return {
|
|
4852
|
-
drilldown: {
|
|
4853
|
-
...dd,
|
|
4854
|
-
members: levelMeta.members
|
|
4855
|
-
},
|
|
4856
|
-
cut
|
|
4857
|
-
};
|
|
4858
|
-
});
|
|
4859
|
-
}
|
|
4860
|
-
});
|
|
4861
|
-
runFetchMembers(Promise.all(promises)).then((data) => {
|
|
4862
|
-
const drilldowns = data.map((item) => item.drilldown);
|
|
4863
|
-
const cuts = data.map((item) => item.cut);
|
|
4864
|
-
newQuery.params.drilldowns = keyBy(drilldowns, "key");
|
|
4865
|
-
const existingCuts = keyBy(
|
|
4866
|
-
Object.values(newQuery.params.cuts || {}).map((c) => ({ ...c, key: c.level })),
|
|
4867
|
-
"key"
|
|
4868
|
-
);
|
|
4869
|
-
const newCuts = keyBy(cuts, "key");
|
|
4870
|
-
newQuery.params.cuts = { ...newCuts, ...existingCuts };
|
|
4871
|
-
const newQueryItem = isValidQuery(newQuery.params) ? newQuery : void 0;
|
|
4872
|
-
if (newQueryItem) {
|
|
4873
|
-
updateCurrentQuery({ ...newQuery, link: serializePermalink(newQuery) });
|
|
4874
|
-
}
|
|
4875
|
-
});
|
|
4876
|
-
}
|
|
4877
|
-
}
|
|
4878
|
-
if (!cube && cubeMap && serverURL && (schema == null ? void 0 : schema.online)) {
|
|
4879
|
-
const cubeDefault = defaultCube && hasProperty(cubeMap, defaultCube) ? defaultCube : Object.keys(cubeMap)[0];
|
|
4880
|
-
setDefaultValues(cubeMap[cubeDefault]);
|
|
4881
|
-
}
|
|
4882
|
-
}, [location2.search, runFetchMembers, schema, serverURL, defaultLocale]);
|
|
4883
|
-
const onChangeCube = (table, subtopic) => {
|
|
4884
|
-
const locale = defaultLocale || queryItem.params.locale;
|
|
4885
|
-
const cubeMap = (schema == null ? void 0 : schema.cubeMap) || {};
|
|
4886
|
-
const cubeArray = getValues(cubeMap);
|
|
4887
|
-
const cube = cubeArray.find(
|
|
4888
|
-
(cube2) => cube2.name === table && getAnnotation(cube2, "subtopic", locale) === subtopic
|
|
4889
|
-
);
|
|
4890
|
-
if (cube) {
|
|
4891
|
-
setDefaultValues(cube);
|
|
4892
|
-
}
|
|
4893
|
-
};
|
|
4894
|
-
function setDefaultValues(cube) {
|
|
4895
|
-
const drilldowns = pickDefaultDrilldowns(cube.dimensions).map(
|
|
4896
|
-
(level) => buildDrilldown({
|
|
4897
|
-
...level,
|
|
4898
|
-
key: level.name,
|
|
4899
|
-
active: true,
|
|
4900
|
-
properties: level.properties.map(
|
|
4901
|
-
(prop) => buildProperty({ level: level.name, name: prop.name })
|
|
4902
|
-
)
|
|
4903
|
-
})
|
|
4904
|
-
);
|
|
4905
|
-
const measuresLimit = typeof measuresActive !== "undefined" ? measuresActive : cube.measures.length;
|
|
4906
|
-
const measures = cube.measures.slice(0, measuresLimit).map((measure) => {
|
|
4907
|
-
return buildMeasure({
|
|
4908
|
-
active: true,
|
|
4909
|
-
key: measure.name,
|
|
4910
|
-
name: measure.name,
|
|
4911
|
-
caption: measure.caption
|
|
4912
|
-
});
|
|
4913
|
-
});
|
|
4914
|
-
const panel = queryItem.panel;
|
|
4915
|
-
const locale = defaultLocale || queryItem.params.locale;
|
|
4916
|
-
const query = buildQuery({
|
|
4917
|
-
params: {
|
|
4918
|
-
cube: cube.name,
|
|
4919
|
-
measures: keyBy(measures, (item) => item.key),
|
|
4920
|
-
drilldowns: keyBy(drilldowns, (item) => item.key),
|
|
4921
|
-
locale
|
|
4922
|
-
},
|
|
4923
|
-
panel: panel != null ? panel : "table"
|
|
4924
|
-
});
|
|
4925
|
-
updateUrl(query);
|
|
4926
|
-
}
|
|
4927
|
-
return /* @__PURE__ */ React13__default.createElement(
|
|
4928
|
-
QueryContext.Provider,
|
|
4929
|
-
{
|
|
4930
|
-
value: {
|
|
4931
|
-
onChangeCube,
|
|
4932
|
-
schemaLoading,
|
|
4933
|
-
membersLoading
|
|
4934
|
-
}
|
|
4935
|
-
},
|
|
4936
|
-
children
|
|
4937
|
-
);
|
|
4938
|
-
}
|
|
4939
|
-
function useQueryItem() {
|
|
4940
|
-
const context = useContext(QueryContext);
|
|
4941
|
-
if (context === void 0) {
|
|
4942
|
-
throw new Error("useQuery must be used within a QueryProvider");
|
|
4943
|
-
}
|
|
4944
|
-
return context;
|
|
4945
|
-
}
|
|
4946
|
-
|
|
4947
|
-
// src/components/Results.tsx
|
|
4948
4956
|
function Results(props) {
|
|
4949
4957
|
const { graph, selectedItem, locale, getCube: getCube2, isSelected: isSelected2, isSelectionInProgress } = props;
|
|
4950
4958
|
const { classes } = useStyles3();
|
|
@@ -5628,7 +5636,6 @@ var useStyles5 = createStyles((theme) => ({
|
|
|
5628
5636
|
function PivotView(props) {
|
|
5629
5637
|
var _a;
|
|
5630
5638
|
const { cube, params, result, isLoading, ...mantineReactTableProps } = props;
|
|
5631
|
-
console.log("PivotView", props);
|
|
5632
5639
|
const locale = params.locale;
|
|
5633
5640
|
const { translate: t } = useTranslation();
|
|
5634
5641
|
const { data: schema } = useServerSchema();
|