feat: enhance device selection with code and name display, filter active devices
This commit is contained in:
@@ -21,10 +21,11 @@ const DetailTag = (props) => {
|
|||||||
tag_number: '',
|
tag_number: '',
|
||||||
data_type: '',
|
data_type: '',
|
||||||
unit: '',
|
unit: '',
|
||||||
device_name: '', // Read-only, auto-display dari device yang dipilih
|
|
||||||
is_active: true,
|
is_active: true,
|
||||||
is_alarm: false,
|
is_alarm: false,
|
||||||
device_id: null, // akan set ketika user select device dari dropdown
|
device_id: null,
|
||||||
|
device_code: '',
|
||||||
|
device_name: '',
|
||||||
sub_section_id: null,
|
sub_section_id: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -147,6 +148,8 @@ const DetailTag = (props) => {
|
|||||||
is_active: FormData.is_active,
|
is_active: FormData.is_active,
|
||||||
is_alarm: FormData.is_alarm,
|
is_alarm: FormData.is_alarm,
|
||||||
device_id: parseInt(FormData.device_id),
|
device_id: parseInt(FormData.device_id),
|
||||||
|
device_code: FormData.device_code,
|
||||||
|
device_name: FormData.device_name,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -212,7 +215,8 @@ const DetailTag = (props) => {
|
|||||||
setFormData({
|
setFormData({
|
||||||
...FormData,
|
...FormData,
|
||||||
device_id: deviceId,
|
device_id: deviceId,
|
||||||
device_name: selectedDevice ? selectedDevice.device_name : '',
|
device_code: selectedDevice?.device_code || '',
|
||||||
|
device_name: selectedDevice?.device_name || '',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -235,8 +239,14 @@ const DetailTag = (props) => {
|
|||||||
try {
|
try {
|
||||||
const params = new URLSearchParams({ limit: 1000 });
|
const params = new URLSearchParams({ limit: 1000 });
|
||||||
const response = await getAllDevice(params);
|
const response = await getAllDevice(params);
|
||||||
|
|
||||||
if (response && response.data && response.data.data) {
|
if (response && response.data && response.data.data) {
|
||||||
setDeviceList(response.data.data);
|
const devices = response.data.data;
|
||||||
|
|
||||||
|
// Filter hanya device yang active (device_status === true)
|
||||||
|
const activeDevices = devices.filter((device) => device.device_status === true);
|
||||||
|
|
||||||
|
setDeviceList(activeDevices);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading devices:', error);
|
console.error('Error loading devices:', error);
|
||||||
@@ -283,10 +293,11 @@ const DetailTag = (props) => {
|
|||||||
tag_number: props.selectedData.tag_number || '',
|
tag_number: props.selectedData.tag_number || '',
|
||||||
data_type: props.selectedData.data_type || '',
|
data_type: props.selectedData.data_type || '',
|
||||||
unit: props.selectedData.unit || '',
|
unit: props.selectedData.unit || '',
|
||||||
device_name: props.selectedData.device_name || '',
|
|
||||||
is_active: props.selectedData.is_active ?? true,
|
is_active: props.selectedData.is_active ?? true,
|
||||||
is_alarm: props.selectedData.is_alarm ?? false,
|
is_alarm: props.selectedData.is_alarm ?? false,
|
||||||
device_id: props.selectedData.device_id || null,
|
device_id: props.selectedData.device_id || null,
|
||||||
|
device_code: props.selectedData.device_code || '',
|
||||||
|
device_name: props.selectedData.device_name || '',
|
||||||
sub_section_id: props.selectedData.sub_section_id || null,
|
sub_section_id: props.selectedData.sub_section_id || null,
|
||||||
};
|
};
|
||||||
setFormData(filteredData);
|
setFormData(filteredData);
|
||||||
@@ -434,7 +445,9 @@ const DetailTag = (props) => {
|
|||||||
disabled={props.readOnly}
|
disabled={props.readOnly}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
FormData.is_alarm === true ? '#23A55A' : '#bfbfbf',
|
FormData.is_alarm === true
|
||||||
|
? '#23A55A'
|
||||||
|
: '#bfbfbf',
|
||||||
}}
|
}}
|
||||||
checked={FormData.is_alarm === true}
|
checked={FormData.is_alarm === true}
|
||||||
onChange={handleAlarmToggle}
|
onChange={handleAlarmToggle}
|
||||||
@@ -523,11 +536,11 @@ const DetailTag = (props) => {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginBottom: 12 }}>
|
<div style={{ marginBottom: 12 }}>
|
||||||
<Text strong>Device Code</Text>
|
<Text strong>Device</Text>
|
||||||
<Text style={{ color: 'red' }}> *</Text>
|
<Text style={{ color: 'red' }}> *</Text>
|
||||||
<Select
|
<Select
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
placeholder="Search device code"
|
placeholder="Search device code or name"
|
||||||
value={FormData.device_id || undefined}
|
value={FormData.device_id || undefined}
|
||||||
onChange={handleDeviceChange}
|
onChange={handleDeviceChange}
|
||||||
disabled={props.readOnly}
|
disabled={props.readOnly}
|
||||||
@@ -543,21 +556,11 @@ const DetailTag = (props) => {
|
|||||||
>
|
>
|
||||||
{deviceList.map((device) => (
|
{deviceList.map((device) => (
|
||||||
<Select.Option key={device.device_id} value={device.device_id}>
|
<Select.Option key={device.device_id} value={device.device_id}>
|
||||||
{device.device_code || ''}
|
{`${device.device_code || ''} - ${device.device_name || ''}`}
|
||||||
</Select.Option>
|
</Select.Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginBottom: 12 }}>
|
|
||||||
<Text strong>Device Name</Text>
|
|
||||||
<Input
|
|
||||||
name="device_name"
|
|
||||||
value={FormData.device_name}
|
|
||||||
placeholder="Auto-filled from selected device code"
|
|
||||||
disabled
|
|
||||||
style={{ backgroundColor: '#f5f5f5' }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{/* Device ID hidden - value dari dropdown */}
|
{/* Device ID hidden - value dari dropdown */}
|
||||||
<input type="hidden" name="device_id" value={FormData.device_id || ''} />
|
<input type="hidden" name="device_id" value={FormData.device_id || ''} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user