Skip to content

Commit d03419a

Browse files
Merge branch '25_2' into 25_2_check_angular_21_in_demos_v2
2 parents 7cd6ab4 + 6d4c786 commit d03419a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+8852
-169
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import React, { useCallback, useState } from 'react';
2+
import DataGrid, {
3+
Column,
4+
Paging,
5+
Grouping,
6+
Ai,
7+
} from 'devextreme-react/data-grid';
8+
import Popup, { Position } from 'devextreme-react/popup';
9+
import { vehicles } from './data.ts';
10+
import { aiIntegration } from './service.ts';
11+
import Trademark from './Trademark.tsx';
12+
import Category from './Category.tsx';
13+
import LicenseInfo from './LicenseInfo.tsx';
14+
import { type Vehicle } from './types.ts';
15+
16+
const onAIColumnRequestCreating = (e) => {
17+
e.data = e.data.map((item) => ({
18+
ID: item.ID,
19+
TrademarkName: item.TrademarkName,
20+
Name: item.Name,
21+
Modification: item.Modification,
22+
}));
23+
};
24+
25+
export default function App() {
26+
const [currentVehicle, setCurrentVehicle] = useState<Vehicle | null>(null);
27+
28+
const showInfo = useCallback((vehicle: Vehicle) => {
29+
setCurrentVehicle(vehicle);
30+
}, []);
31+
32+
const hideInfo = useCallback(() => {
33+
setCurrentVehicle(null);
34+
}, []);
35+
36+
return (
37+
<React.Fragment>
38+
<DataGrid
39+
dataSource={vehicles}
40+
showBorders={true}
41+
keyExpr="ID"
42+
aiIntegration={aiIntegration}
43+
onAIColumnRequestCreating={onAIColumnRequestCreating}
44+
>
45+
<Paging
46+
enabled={true}
47+
pageSize={10}
48+
/>
49+
<Grouping contextMenuEnabled={false} />
50+
<Column
51+
caption="Trademark"
52+
width={200}
53+
dataField="TrademarkName"
54+
cellRender={(cellData) =>
55+
<Trademark
56+
vehicle={cellData.data}
57+
onShowInfo={showInfo}
58+
/>
59+
}
60+
/>
61+
<Column
62+
dataField="Price"
63+
alignment="left"
64+
format="currency"
65+
width={100}
66+
/>
67+
<Column
68+
caption="Category"
69+
minWidth={180}
70+
cellRender={Category}
71+
/>
72+
<Column
73+
dataField="Modification"
74+
width={180}
75+
/>
76+
<Column
77+
dataField="Horsepower"
78+
width={140}
79+
/>
80+
<Column
81+
dataField="BodyStyleName"
82+
caption="Body Style"
83+
width={180}
84+
/>
85+
<Column
86+
name="AI Column"
87+
caption="AI Column"
88+
type="ai"
89+
width={200}
90+
fixed={true}
91+
fixedPosition="right"
92+
cssClass="ai__cell"
93+
>
94+
<Ai
95+
mode="auto"
96+
noDataText="No data"
97+
prompt="Identify the country where this vehicle model is originally manufactured or developed, based on its brand, model, and specifications."
98+
/>
99+
</Column>
100+
</DataGrid>
101+
<Popup
102+
width={360}
103+
height={260}
104+
visible={Boolean(currentVehicle)}
105+
dragEnabled={false}
106+
hideOnOutsideClick={true}
107+
title="Image Info"
108+
onHiding={hideInfo}
109+
contentRender={() =>
110+
<LicenseInfo vehicle={currentVehicle} />
111+
}
112+
>
113+
<Position
114+
at="center"
115+
my="center"
116+
collision="fit"
117+
/>
118+
</Popup>
119+
</React.Fragment>
120+
);
121+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
import { type Vehicle } from './types';
3+
import { type DataGridTypes } from 'devextreme-react/data-grid';
4+
5+
export default function Category(props: DataGridTypes.ColumnCellTemplateData<Vehicle>) {
6+
return <div className="category__wrapper">{props.data.CategoryName}</div>;
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import { type Vehicle } from './types';
3+
4+
type Props = {
5+
vehicle: Vehicle | null;
6+
};
7+
8+
const LicenseInfo = ({ vehicle }: Props) => {
9+
if (!vehicle) {
10+
return null;
11+
}
12+
13+
const { LicenseName, Author, Source, Edits } = vehicle;
14+
const vehicleLink = `https://${Source}`;
15+
return (
16+
<div>
17+
<p><b>Image licensed under: </b> <span>{LicenseName}</span></p>
18+
<p><b>Author: </b> <span>{Author}</span></p>
19+
<p>
20+
<b>Source link: </b>
21+
<a
22+
href={vehicleLink}
23+
target="_blank"
24+
rel="noopener noreferrer"
25+
>
26+
{vehicleLink}
27+
</a>
28+
</p>
29+
<p><b>Edits: </b> <span>{Edits}</span></p>
30+
</div>
31+
);
32+
};
33+
34+
export default LicenseInfo;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { useCallback } from 'react';
2+
import { type Vehicle } from './types';
3+
4+
type TrademarkProps = {
5+
vehicle: Vehicle;
6+
onShowInfo: (vehicle: Vehicle) => void;
7+
};
8+
9+
export default function Trademark({ vehicle, onShowInfo }: TrademarkProps) {
10+
const { ID, TrademarkName, Name } = vehicle;
11+
12+
const onKeyDown = useCallback((event: React.KeyboardEvent<HTMLImageElement>) => {
13+
if (event.key === 'Enter') {
14+
onShowInfo(vehicle);
15+
}
16+
}, [onShowInfo, vehicle]);
17+
18+
return (
19+
<div className="trademark__wrapper">
20+
<div className="trademark__img-wrapper">
21+
<img
22+
className="trademark__img"
23+
src={`../../../../images/vehicles/image_${ID}.png`}
24+
alt={`${TrademarkName} ${Name}`}
25+
tabIndex={0}
26+
onClick={() => onShowInfo(vehicle)}
27+
role="button"
28+
onKeyDown={onKeyDown}
29+
aria-haspopup="dialog"
30+
aria-label={`${TrademarkName} ${Name} - press Enter for image info`}
31+
/>
32+
</div>
33+
<div>
34+
<div className="trademark__text trademark__text--title">{TrademarkName}</div>
35+
<div className="trademark__text trademark__text--subtitle">{Name}</div>
36+
</div>
37+
</div>
38+
);
39+
}

0 commit comments

Comments
 (0)