7 changed files with 1733 additions and 5 deletions
-
17src/pages/Measure.tsx
-
4src/pages/Setting.tsx
-
13src/services/apiTypes.ts
-
26src/store/features/baseData.ts
-
4src/store/index.ts
-
1642src/utils/constant.ts
-
32src/utils/helper.ts
@ -0,0 +1,26 @@ |
|||||
|
import { createSelector, createSlice } from "@reduxjs/toolkit"; |
||||
|
import { KTJOrg } from "../../services/apiTypes"; |
||||
|
import { labeledKtjOrgs } from "../../utils/helper"; |
||||
|
|
||||
|
import { ktjOrgs } from "../../utils/constant"; |
||||
|
|
||||
|
interface BaseDataState { |
||||
|
ktjOrgs: KTJOrg[]; |
||||
|
} |
||||
|
|
||||
|
const initialState: BaseDataState = { |
||||
|
ktjOrgs: ktjOrgs as KTJOrg[], |
||||
|
} |
||||
|
|
||||
|
export const baseDataSlice = createSlice({ |
||||
|
name: 'baseData', |
||||
|
initialState, |
||||
|
reducers: {} |
||||
|
}); |
||||
|
|
||||
|
export default baseDataSlice.reducer; |
||||
|
|
||||
|
export const selectKtjOrgs = (state: BaseDataState) => state.ktjOrgs |
||||
|
export const selectLabeledKtjOrgs = createSelector(selectKtjOrgs,(orgs) => { |
||||
|
return labeledKtjOrgs(orgs) |
||||
|
}) |
1642
src/utils/constant.ts
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,32 @@ |
|||||
|
import { KTJOrg } from "../services/apiTypes"; |
||||
|
|
||||
|
export type LabelKTJOrg = { |
||||
|
label: string; |
||||
|
value: string; |
||||
|
children: Array<{ |
||||
|
label: string; |
||||
|
value: string; |
||||
|
children: Array<{ |
||||
|
label: string; |
||||
|
value: string; |
||||
|
}>; |
||||
|
}>; |
||||
|
}; |
||||
|
|
||||
|
export function labeledKtjOrgs(ktjOrgs: KTJOrg[]): LabelKTJOrg[] { |
||||
|
return ktjOrgs.map((org) => { |
||||
|
const _org: LabelKTJOrg = { |
||||
|
label: org.value || org.key, |
||||
|
value: org.key, |
||||
|
children: org.gwdDicList.map((gwd) => ({ |
||||
|
label: gwd.value || gwd.key, |
||||
|
value: gwd.key, |
||||
|
children: gwd.railDicList.map((rail) => ({ |
||||
|
label: rail.value || rail.key, |
||||
|
value: rail.key, |
||||
|
})), |
||||
|
})), |
||||
|
}; |
||||
|
return _org; |
||||
|
}); |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue