Skip to content

Commit

Permalink
getredash#6 embed query option (년/월/일 제한)
Browse files Browse the repository at this point in the history
  • Loading branch information
GunSik2 committed Feb 6, 2024
1 parent fc30b55 commit ff8be9e
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions client/app/components/DateRangeSwitchableInput.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { isArray } from "lodash";
import { has, isArray } from "lodash";
import React, { useState } from "react";
import PropTypes from "prop-types";
import { Moment } from "@/components/proptypes";
import DatePicker from "antd/lib/date-picker";
import Select from "antd/lib/select";
import "antd/lib/date-picker/style/css";
import "antd/lib/select/style/css";
import location from "@/services/location";
import qs from "query-string";

const { RangePicker } = DatePicker;
const { Option } = Select;
Expand All @@ -22,19 +24,47 @@ const DateRangeSwitchableInput = React.forwardRef(
additionalAttributes.value = value;
}

const [pickerType, setPickerType] = useState('day');

//const full_options = ["day", "week", "month", "quarter", "year"];
const full_options = ["day", "week", "month", "year"];
const optionLabels = {
day: "일",
week: "주",
month: "월",
quarter: "분기",
year: "년",
};

//const datetypeExist = has(location.search, "datetype");
//console.log('********* datetype = ' + datetypeExist)

const currentUrlParams = qs.parse(window.location.search.substring(1));
//console.log('********* params = ' + qs.stringify(currentUrlParams));

const datetype = currentUrlParams['p_datetype'];
//console.log('********* datetype = ' + datetype)

let options;
let default_option;
if (datetype && full_options.includes(datetype)) {
options = [datetype];
default_option = datetype;
} else {
options = [...full_options];
default_option = 'day'
}

const [pickerType, setPickerType] = useState(default_option);
const handlePickerTypeChange = (newPickerType) => {
setPickerType(newPickerType);
};

const options = ["day", "week", "month", "quarter", "year"];

return (
<div>
<Select value={pickerType} onChange={handlePickerTypeChange} style={{ width: 100, marginRight: 10 }}>
{options.map(optionValue => (
<Option key={optionValue} value={optionValue}>
{optionValue.charAt(0).toUpperCase() + optionValue.slice(1)}
{optionLabels[optionValue]}
</Option> )
)}
</Select>
Expand Down

0 comments on commit ff8be9e

Please sign in to comment.