Browse Source

update

master
cyril.tsui 1 month ago
parent
commit
f3af4a6f60
3 changed files with 51 additions and 25 deletions
  1. +3
    -2
      src/app/api/scheduling/actions.ts
  2. +44
    -21
      src/components/DetailedSchedule/DetailedScheduleSearchView.tsx
  3. +4
    -2
      src/components/RoughSchedule/RoughSchedileSearchView.tsx

+ 3
- 2
src/app/api/scheduling/actions.ts View File

@@ -85,9 +85,10 @@ export const testRoughSchedule = cache(async () => {
); );
}); });


export const testDetailedSchedule = cache(async () => {
export const testDetailedSchedule = cache(async (date?: string) => {
const queryStr = convertObjToURLSearchParams({genDate: date})
return serverFetchJson( return serverFetchJson(
`${BASE_API_URL}/productionSchedule/testDetailedSchedule`,
`${BASE_API_URL}/productionSchedule/testDetailedSchedule?${queryStr}`,
{ {
method: "GET", method: "GET",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },


+ 44
- 21
src/components/DetailedSchedule/DetailedScheduleSearchView.tsx View File

@@ -11,11 +11,13 @@ import {
ProdScheduleResult, ProdScheduleResult,
SearchProdSchedule, SearchProdSchedule,
fetchProdSchedules, fetchProdSchedules,
testDetailedSchedule,
} from "@/app/api/scheduling/actions"; } from "@/app/api/scheduling/actions";
import { defaultPagingController } from "../SearchResults/SearchResults"; import { defaultPagingController } from "../SearchResults/SearchResults";
import { arrayToDateString, decimalFormatter } from "@/app/utils/formatUtil"; import { arrayToDateString, decimalFormatter } from "@/app/utils/formatUtil";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { uniqBy } from "lodash";
import { orderBy, uniqBy } from "lodash";
import { Button, Stack } from "@mui/material";


// may need move to "index" or "actions" // may need move to "index" or "actions"
// type RecordStructure = { // type RecordStructure = {
@@ -63,12 +65,12 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {


const searchCriteria: Criterion<SearchParamNames>[] = useMemo(() => { const searchCriteria: Criterion<SearchParamNames>[] = useMemo(() => {
const searchCriteria: Criterion<SearchParamNames>[] = [ const searchCriteria: Criterion<SearchParamNames>[] = [
{
label: t("Schedule Period"),
label2: t("Schedule Period To"),
paramName: "schedulePeriod",
type: "dateRange",
},
// {
// label: t("Schedule Period"),
// label2: t("Schedule Period To"),
// paramName: "schedulePeriod",
// type: "dateRange",
// },
{ label: t("Production Date"), paramName: "scheduleAt", type: "date" }, { label: t("Production Date"), paramName: "scheduleAt", type: "date" },
{ {
label: t("Product Count"), label: t("Product Count"),
@@ -110,15 +112,15 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
onClick: (record) => onDetailClick(record), onClick: (record) => onDetailClick(record),
buttonIcon: <EditNote />, buttonIcon: <EditNote />,
}, },
{
name: "schedulePeriod",
label: t("Demand Forecast Period"),
renderCell: (params) => {
return `${arrayToDateString(
params.schedulePeriod,
)} - ${arrayToDateString(params.schedulePeriodTo)}`;
},
},
// {
// name: "schedulePeriod",
// label: t("Demand Forecast Period"),
// renderCell: (params) => {
// return `${arrayToDateString(
// params.schedulePeriod,
// )} - ${arrayToDateString(params.schedulePeriodTo)}`;
// },
// },
{ {
name: "scheduleAt", name: "scheduleAt",
label: t("Production Date"), label: t("Production Date"),
@@ -169,8 +171,6 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
: query.types : query.types
) as ScheduleType[]; ) as ScheduleType[];


console.log(convertedTypes);
console.log(query.types);
const params: SearchProdSchedule = { const params: SearchProdSchedule = {
scheduleAt: dayjs(query?.scheduleAt).isValid() scheduleAt: dayjs(query?.scheduleAt).isValid()
? query?.scheduleAt ? query?.scheduleAt
@@ -200,8 +200,9 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
break; break;
case "paging": case "paging":
setFilteredSchedules((fs) => setFilteredSchedules((fs) =>
orderBy(
uniqBy([...fs, ...response.records], "id"), uniqBy([...fs, ...response.records], "id"),
);
["id"], ["desc"]));
break; break;
} }
} }
@@ -278,8 +279,30 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
refetchData(inputs, "reset"); refetchData(inputs, "reset");
}, []); }, []);


const testDetailedScheduleClick = useCallback(async () => {
console.log(inputs.scheduleAt)
const response = await testDetailedSchedule(inputs.scheduleAt)

if (response) {
refetchData(inputs, "paging");
}
}, [])

return ( return (
<> <>
<Stack
direction="row"
justifyContent="flex-end"
flexWrap="wrap"
rowGap={2}
>
<Button
variant="contained"
onClick={testDetailedScheduleClick}
>
{t("Test Detailed Schedule")}
</Button>
</Stack>
<SearchBox <SearchBox
criteria={searchCriteria} criteria={searchCriteria}
onSearch={(query) => { onSearch={(query) => {
@@ -300,8 +323,8 @@ const DSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
setPagingController={setPagingController} setPagingController={setPagingController}
pagingController={pagingController} pagingController={pagingController}
totalCount={totalCount} totalCount={totalCount}
// isAutoPaging={false}
// hasCollapse={false}
// isAutoPaging={false}
// hasCollapse={false}
/> />
</> </>
); );


+ 4
- 2
src/components/RoughSchedule/RoughSchedileSearchView.tsx View File

@@ -23,7 +23,7 @@ import {
testRoughSchedule, testRoughSchedule,
} from "@/app/api/scheduling/actions"; } from "@/app/api/scheduling/actions";
import { arrayToDateString, decimalFormatter } from "@/app/utils/formatUtil"; import { arrayToDateString, decimalFormatter } from "@/app/utils/formatUtil";
import { isEqual, uniqBy } from "lodash";
import { isEqual, orderBy, sortBy, uniqBy } from "lodash";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { defaultPagingController } from "../SearchResults/SearchResults"; import { defaultPagingController } from "../SearchResults/SearchResults";
import { ScheduleType } from "@/app/api/scheduling"; import { ScheduleType } from "@/app/api/scheduling";
@@ -178,7 +178,9 @@ const RSOverview: React.FC<Props> = ({ type, defaultInputs }) => {
break; break;
case "paging": case "paging":
setFilteredSchedules((fs) => setFilteredSchedules((fs) =>
uniqBy([...fs, ...response.records], "id"),
orderBy(
uniqBy([...fs, ...response.records], "id")
, ["id"], ["desc"]),
); );
break; break;
} }


Loading…
Cancel
Save