@evergis/react 4.0.0 → 4.0.2
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/components/Dashboard/hooks/useDashboardHeader.d.ts +1 -2
- package/dist/components/Dashboard/hooks/useDataSources.d.ts +1 -1
- package/dist/components/Dashboard/types.d.ts +3 -0
- package/dist/index.js +69 -39
- package/dist/index.js.map +1 -1
- package/dist/react.esm.js +69 -39
- package/dist/react.esm.js.map +1 -1
- package/package.json +5 -5
package/dist/react.esm.js
CHANGED
|
@@ -3953,8 +3953,13 @@ const useFetchWithAuth = (url, transform, cleanup) => {
|
|
|
3953
3953
|
});
|
|
3954
3954
|
}, [url]);
|
|
3955
3955
|
useEffect(() => {
|
|
3956
|
-
|
|
3957
|
-
|
|
3956
|
+
if (url) {
|
|
3957
|
+
fetchData();
|
|
3958
|
+
}
|
|
3959
|
+
else {
|
|
3960
|
+
setData(null);
|
|
3961
|
+
}
|
|
3962
|
+
}, [url]);
|
|
3958
3963
|
useEffect(() => () => {
|
|
3959
3964
|
if (data !== null)
|
|
3960
3965
|
cleanupRef.current?.(data);
|
|
@@ -7777,10 +7782,9 @@ const PageTitleContainer = styled(Flex) `
|
|
|
7777
7782
|
`;
|
|
7778
7783
|
|
|
7779
7784
|
const DashboardDefaultHeader = memo(() => {
|
|
7780
|
-
const { title, pageId, image, icon, tooltip, themeName } = useDashboardHeader();
|
|
7785
|
+
const { title, pageId, image, icon, tooltip, themeName, onClickLogo } = useDashboardHeader();
|
|
7781
7786
|
const { toggleLayersVisibility, components: { ProjectPanelMenu, ProjectPagesMenu }, } = useWidgetContext();
|
|
7782
|
-
|
|
7783
|
-
return (jsxs(DefaultHeaderContainer, { image: backgroundImage ?? undefined, isDark: themeName === ThemeName.Dark, children: [!pageId && jsx(LinearProgress, {}), jsxs(Flex, { column: true, gap: "1rem", children: [jsx(FlexSpan, { children: jsxs(TopContainer, { children: [jsx(LogoContainer, { children: icon }), jsx(TopContainerButtons, { children: jsx(ProjectPanelMenu, {}) })] }) }), jsx(FlexSpan, { children: jsx(Flex, { column: true, gap: "0.25rem", children: jsx(FlexSpan, { children: jsxs(Flex, { alignItems: "center", children: [jsxs(PageTitleContainer, { children: [jsx(Tooltip$1, { arrow: true, content: tooltip, children: ref => (jsx(PageTitle, { ref: ref, onClick: toggleLayersVisibility, children: title })) }), jsx(ProjectPagesMenu, {})] }), jsx(FlexSpan, { children: jsx(Pagination, {}) })] }) }) }) })] })] }));
|
|
7787
|
+
return (jsxs(DefaultHeaderContainer, { image: image, isDark: themeName === ThemeName.Dark, children: [!pageId && jsx(LinearProgress, {}), jsxs(Flex, { column: true, gap: "1rem", children: [jsx(FlexSpan, { children: jsxs(TopContainer, { children: [jsx(LogoContainer, { onClick: onClickLogo, children: icon }), jsx(TopContainerButtons, { children: jsx(ProjectPanelMenu, {}) })] }) }), jsx(FlexSpan, { children: jsx(Flex, { column: true, gap: "0.25rem", children: jsx(FlexSpan, { children: jsxs(Flex, { alignItems: "center", children: [jsxs(PageTitleContainer, { children: [jsx(Tooltip$1, { arrow: true, content: tooltip, children: ref => (jsx(PageTitle, { ref: ref, onClick: toggleLayersVisibility, children: title })) }), jsx(ProjectPagesMenu, {})] }), jsx(FlexSpan, { children: jsx(Pagination, {}) })] }) }) }) })] })] }));
|
|
7784
7788
|
});
|
|
7785
7789
|
|
|
7786
7790
|
const HeaderFrontView = styled(Flex) `
|
|
@@ -8516,8 +8520,10 @@ const ElementIcon = memo(({ type, elementConfig }) => {
|
|
|
8516
8520
|
const { attributes } = useWidgetContext(type);
|
|
8517
8521
|
const { value, attributeName, options, style } = elementConfig || {};
|
|
8518
8522
|
const { fontSize, fontColor } = options || {};
|
|
8519
|
-
const iconValue = useMemo(() =>
|
|
8520
|
-
|
|
8523
|
+
const iconValue = useMemo(() => attributeName
|
|
8524
|
+
? attributes?.find(item => item.name === attributeName)?.value
|
|
8525
|
+
: value, [attributeName, attributes, value]);
|
|
8526
|
+
return (jsx(StyledIcon, { kind: iconValue, fontSize: fontSize, fontColor: fontColor, style: style }));
|
|
8521
8527
|
});
|
|
8522
8528
|
|
|
8523
8529
|
const ElementImage = memo(({ type, elementConfig }) => {
|
|
@@ -9106,10 +9112,10 @@ const ElementUploader = memo(({ elementConfig, type }) => {
|
|
|
9106
9112
|
const [files, setFiles] = useState([]);
|
|
9107
9113
|
const refInput = useRef();
|
|
9108
9114
|
const { id, style, options } = elementConfig || {};
|
|
9109
|
-
const { fileExtensions = DEFAULT_FILE_EXTENSIONS, multiSelect, parentResourceId, icon, title, filterName } = options || {};
|
|
9115
|
+
const { fileExtensions = DEFAULT_FILE_EXTENSIONS, multiSelect, parentResourceId, icon, title, filterName, } = options || {};
|
|
9110
9116
|
const onUpload = useCallback(async (input) => {
|
|
9111
|
-
const
|
|
9112
|
-
const response = await Promise.all(
|
|
9117
|
+
const newFiles = Array.isArray(input) ? input : [input];
|
|
9118
|
+
const response = await Promise.all(newFiles.map(file => {
|
|
9113
9119
|
return api.file.upload(file, true, parentResourceId || "", file.name);
|
|
9114
9120
|
}));
|
|
9115
9121
|
const uploadedFiles = response.map(item => ({
|
|
@@ -9117,28 +9123,29 @@ const ElementUploader = memo(({ elementConfig, type }) => {
|
|
|
9117
9123
|
id: item.resourceId,
|
|
9118
9124
|
done: true,
|
|
9119
9125
|
}));
|
|
9120
|
-
setFiles(currentFiles =>
|
|
9121
|
-
}, [parentResourceId]);
|
|
9122
|
-
const onDelete = useCallback(async (
|
|
9123
|
-
const index = files.findIndex(file => file.id ===
|
|
9126
|
+
setFiles(currentFiles => [...uploadedFiles, ...currentFiles]);
|
|
9127
|
+
}, [api.file, parentResourceId]);
|
|
9128
|
+
const onDelete = useCallback(async (deleteId) => {
|
|
9129
|
+
const index = files.findIndex(file => file.id === deleteId);
|
|
9124
9130
|
if (index === -1)
|
|
9125
9131
|
return;
|
|
9126
9132
|
const resourceId = files[index].id;
|
|
9127
9133
|
await api.file.deleteResource({ resourceId });
|
|
9128
|
-
setFiles(currentFiles => currentFiles.filter(
|
|
9129
|
-
}, [files]);
|
|
9134
|
+
setFiles(currentFiles => currentFiles.filter(file => file.id !== resourceId));
|
|
9135
|
+
}, [api.file, files]);
|
|
9130
9136
|
const renderTitle = useMemo(() => {
|
|
9131
9137
|
if (files.length)
|
|
9132
9138
|
return null;
|
|
9133
|
-
return (jsxs(UploaderTitle, { children: [jsx(Icon, { kind: icon || "upload" }), jsx("div", { children: title ??
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9139
|
+
return (jsxs(UploaderTitle, { children: [jsx(Icon, { kind: icon || "upload" }), jsx("div", { children: title ??
|
|
9140
|
+
t("uploadTitle", {
|
|
9141
|
+
ns: "dashboard",
|
|
9142
|
+
defaultValue: "Перетащите файл сюда или нажмите, чтобы выбрать",
|
|
9143
|
+
}) })] }));
|
|
9137
9144
|
}, [icon, t, title, files.length]);
|
|
9138
9145
|
useEffect(() => {
|
|
9139
9146
|
if (!filterName)
|
|
9140
9147
|
return;
|
|
9141
|
-
changeFilters({ [filterName]: { value: files.map(
|
|
9148
|
+
changeFilters({ [filterName]: { value: files.map(file => file.id) } });
|
|
9142
9149
|
}, [files]);
|
|
9143
9150
|
return (jsx(UploaderContainer, { id: id, style: style, children: jsx("div", { children: jsx(Uploader, { currentRef: refInput, title: renderTitle, accept: fileExtensions, width: "100%", fileItems: files, isMultiple: multiSelect, onUpload: onUpload, onDelete: onDelete }) }) }));
|
|
9144
9151
|
});
|
|
@@ -10580,7 +10587,7 @@ const useChartData = ({ element, type }) => {
|
|
|
10580
10587
|
const dataSource = configDataSources.find(({ name }) => name === dataSourceName);
|
|
10581
10588
|
const layerInfo = layerInfos?.find(item => item?.name === dataSource?.layerName);
|
|
10582
10589
|
const featureDataSource = getDataSource(dataSourceName, dataSources);
|
|
10583
|
-
const hasLayerInfo = !!layerInfo || !!featureDataSource?.attributeDefinition;
|
|
10590
|
+
const hasLayerInfo = !!layerInfo || !!featureDataSource?.attributeDefinition || !!featureDataSource?.features?.length;
|
|
10584
10591
|
return {
|
|
10585
10592
|
items: hasLayerInfo
|
|
10586
10593
|
? getDataFromRelatedFeatures({
|
|
@@ -10632,7 +10639,7 @@ const useChartData = ({ element, type }) => {
|
|
|
10632
10639
|
};
|
|
10633
10640
|
|
|
10634
10641
|
const useHeaderRender = (elementConfig, type = WidgetType.Dashboard) => {
|
|
10635
|
-
const { layerInfo, attributes, expandedContainers, selectedTabId, setSelectedTabId } = useWidgetContext(type);
|
|
10642
|
+
const { layerInfo, attributes, expandedContainers, selectedTabId, setSelectedTabId, } = useWidgetContext(type);
|
|
10636
10643
|
const { config } = useWidgetConfig(type);
|
|
10637
10644
|
const { pageIndex } = useWidgetPage(type);
|
|
10638
10645
|
return useMemo(() => getRenderElement({
|
|
@@ -10644,7 +10651,16 @@ const useHeaderRender = (elementConfig, type = WidgetType.Dashboard) => {
|
|
|
10644
10651
|
selectedTabId,
|
|
10645
10652
|
setSelectedTabId,
|
|
10646
10653
|
pageIndex,
|
|
10647
|
-
}), [
|
|
10654
|
+
}), [
|
|
10655
|
+
config,
|
|
10656
|
+
elementConfig,
|
|
10657
|
+
attributes,
|
|
10658
|
+
layerInfo,
|
|
10659
|
+
expandedContainers,
|
|
10660
|
+
selectedTabId,
|
|
10661
|
+
setSelectedTabId,
|
|
10662
|
+
pageIndex,
|
|
10663
|
+
]);
|
|
10648
10664
|
};
|
|
10649
10665
|
|
|
10650
10666
|
const useDashboardHeader = () => {
|
|
@@ -10653,21 +10669,30 @@ const useDashboardHeader = () => {
|
|
|
10653
10669
|
const { currentPage } = useWidgetPage();
|
|
10654
10670
|
const { alias, name } = projectInfo || {};
|
|
10655
10671
|
const { id: pageId, header } = currentPage || {};
|
|
10672
|
+
const { children, options } = header || {};
|
|
10673
|
+
const { url } = options || {};
|
|
10656
10674
|
const renderElement = useHeaderRender(header);
|
|
10657
|
-
const image = useMemo(() =>
|
|
10658
|
-
|
|
10659
|
-
|
|
10675
|
+
const image = useMemo(() => children?.some(({ id }) => id === "image")
|
|
10676
|
+
? renderElement({ id: "image", wrap: false })
|
|
10677
|
+
: null, [children, renderElement]);
|
|
10678
|
+
const icon = useMemo(() => children?.some(({ id }) => id === "icon") ? (renderElement({ id: "icon", wrap: false })) : (jsx(Icon, { kind: "logo", style: { width: "2rem", height: "2rem" } })), [children, renderElement]);
|
|
10679
|
+
const title = useMemo(() => children?.some(({ id }) => id === "title")
|
|
10680
|
+
? renderElement({ id: "title" })
|
|
10681
|
+
: currentPage?.options?.title, [children, renderElement, currentPage?.options?.title]);
|
|
10660
10682
|
const tooltip = useMemo(() => (jsxs("div", { children: [jsx("span", { children: alias || name }), jsx("span", { style: { opacity: 0.54, marginLeft: "0.5rem" }, children: title })] })), [alias, name, title]);
|
|
10661
|
-
const
|
|
10683
|
+
const onClickLogo = useCallback(() => {
|
|
10684
|
+
if (!url)
|
|
10685
|
+
return;
|
|
10686
|
+
window.open(url);
|
|
10687
|
+
}, [url]);
|
|
10662
10688
|
return {
|
|
10663
10689
|
pageId,
|
|
10664
10690
|
image,
|
|
10665
10691
|
icon,
|
|
10666
10692
|
title,
|
|
10667
10693
|
tooltip,
|
|
10668
|
-
description,
|
|
10669
10694
|
themeName,
|
|
10670
|
-
|
|
10695
|
+
onClickLogo,
|
|
10671
10696
|
};
|
|
10672
10697
|
};
|
|
10673
10698
|
|
|
@@ -10676,7 +10701,7 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
|
|
|
10676
10701
|
const { dataSources } = useWidgetContext(widgetType);
|
|
10677
10702
|
const { filters: configFilters, dataSources: configDataSources } = config || {};
|
|
10678
10703
|
const prevFilters = useRef({});
|
|
10679
|
-
const getDataSourcePromises = useCallback(async ({ ds, query, parameters, layerName, limit, condition, url, resourceId }, newFilters, offset = 0) => {
|
|
10704
|
+
const getDataSourcePromises = useCallback(async ({ ds, query, parameters, layerName, limit, condition, url, resourceId, fileName, methodName }, newFilters, offset = 0) => {
|
|
10680
10705
|
const selectedFilters = {
|
|
10681
10706
|
...(filters || {}),
|
|
10682
10707
|
...(newFilters || {}),
|
|
@@ -10689,12 +10714,14 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
|
|
|
10689
10714
|
method: "get",
|
|
10690
10715
|
resourceId,
|
|
10691
10716
|
parameters,
|
|
10717
|
+
...(fileName && { fileName }),
|
|
10718
|
+
...(methodName && { methodName }),
|
|
10692
10719
|
}
|
|
10693
10720
|
});
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10721
|
+
if (response.error) {
|
|
10722
|
+
throw new Error(response.error.message);
|
|
10723
|
+
}
|
|
10724
|
+
return response.result;
|
|
10698
10725
|
}
|
|
10699
10726
|
const newParams = applyQueryFilters({
|
|
10700
10727
|
parameters,
|
|
@@ -10774,10 +10801,12 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
|
|
|
10774
10801
|
const newDataSources = JSON.parse(JSON.stringify([...currentDataSources, ...otherDataSources]));
|
|
10775
10802
|
responses.forEach((response, index) => {
|
|
10776
10803
|
const isQueryDataSource = !isNil(currentDataSources[index].query) ||
|
|
10777
|
-
!!currentDataSources[index].url
|
|
10778
|
-
|
|
10804
|
+
!!currentDataSources[index].url;
|
|
10805
|
+
const isPythonDataSource = !!currentDataSources[index].resourceId;
|
|
10779
10806
|
newDataSources[index].layerName = currentDataSources[index].layerName;
|
|
10780
|
-
const items = response.status === "rejected"
|
|
10807
|
+
const items = response.status === "rejected"
|
|
10808
|
+
? null
|
|
10809
|
+
: response.value?.features || response.value?.items;
|
|
10781
10810
|
newDataSources[index].features =
|
|
10782
10811
|
response.status === "rejected"
|
|
10783
10812
|
? null
|
|
@@ -10785,10 +10814,11 @@ const useDataSources = ({ type: widgetType, config, attributes, filters, layerPa
|
|
|
10785
10814
|
? items?.map((item, itemIndex) => ({
|
|
10786
10815
|
id: itemIndex + 1,
|
|
10787
10816
|
attributes: item.attributes,
|
|
10817
|
+
properties: item.properties || item.attributes,
|
|
10788
10818
|
}))
|
|
10789
10819
|
: items;
|
|
10790
10820
|
newDataSources[index].attributeDefinition =
|
|
10791
|
-
response.status === "rejected" || !isQueryDataSource
|
|
10821
|
+
response.status === "rejected" || (!isQueryDataSource && !isPythonDataSource)
|
|
10792
10822
|
? null
|
|
10793
10823
|
: response.value.attributeDefinition;
|
|
10794
10824
|
});
|