-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OFA] ビューのサマリを表示する #157
Merged
Merged
[OFA] ビューのサマリを表示する #157
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5a0d6fc
One-for-All-156 WIP sumRecords.ts
Ryo-Kgym bb9da9b
One-for-All-156 WIP
Ryo-Kgym 1d76ce0
One-for-All-156
yutaka-osawa 92faf55
One-for-All-156 WIP
Ryo-Kgym fa2ff05
One-for-All-156 WIP
Ryo-Kgym 0472c78
One-for-All-156 WIP
Ryo-Kgym 30cbc00
One-for-All-156
yutaka-osawa ca278cf
One-for-All-156
yutaka-osawa 542af58
One-for-All-156
yutaka-osawa 3e9048a
One-for-All-156 Setを使えるように修正した。
Ryo-Kgym 21573db
One-for-All-156
yutaka-osawa 6517291
One-for-All-156
yutaka-osawa 5f2a04b
pnpm ci version-up
Ryo-Kgym 98c9c9a
pnpm ci version-up
Ryo-Kgym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { ShowChart } from "@pageComponents/showChart"; | ||
|
||
const Page = () => <ShowChart />; | ||
const Page = ({ params: { id } }: { params: { id: string } }) => ( | ||
<ShowChart appId={id} /> | ||
); | ||
|
||
export default Page; |
45 changes: 35 additions & 10 deletions
45
apps/web/src/pageComponents/showChart/components/ShowChartServer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
import { SummaryCriteria } from "@oneforall/domain/schema/summary/sumRecordsSchema"; | ||
import { createDataArray } from "@pageComponents/showChart/components/createDataArray"; | ||
import ShowChartClient from "@pageComponents/showChart/components/ShowChartClient"; | ||
import { fetchQuery } from "@persistence/database/server/fetchQuery"; | ||
import { parseToRecords } from "@v3/graphql/public/convert/parseToRecords"; | ||
import { GetAppDocument } from "@v3/graphql/public/type"; | ||
|
||
export const ShowChartServer = async () => { | ||
const data = [ | ||
{ name: "Group A", value: 400 }, | ||
{ name: "Group B", value: 300 }, | ||
{ name: "Group C", value: 300 }, | ||
{ name: "Group D", value: 200 }, | ||
{ name: "Group E", value: 278 }, | ||
{ name: "Group F", value: 189 }, | ||
]; | ||
export const ShowChartServer = async ({ appId }: { appId: string }) => { | ||
const { data } = await fetchQuery(GetAppDocument, { appId }); | ||
const records = parseToRecords(data?.app?.records ?? []); | ||
|
||
const criteria: SummaryCriteria = { | ||
groupingFields: { | ||
"1718289203212": { | ||
id: "1718289203212", | ||
fieldName: "値", | ||
fieldKind: "text", | ||
fieldIndex: 1, | ||
options: {}, | ||
}, | ||
}, | ||
summaryFields: { | ||
"1718289203213": { | ||
id: "1718289203213", | ||
fieldName: "数値", | ||
fieldKind: "numeric", | ||
fieldIndex: 2, | ||
options: { | ||
thousandsSeparatorPosition: 3, | ||
}, | ||
}, | ||
}, | ||
}; | ||
criteria; | ||
|
||
const dataArray = createDataArray({ records, criteria }); | ||
|
||
const colors = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; | ||
|
||
return <ShowChartClient data={data} colors={colors} />; | ||
return <ShowChartClient data={dataArray} colors={colors} />; | ||
}; |
104 changes: 104 additions & 0 deletions
104
apps/web/src/pageComponents/showChart/components/createDataArray.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Records } from "@oneforall/domain/schema/recordSchema"; | ||
import { SummaryCriteria } from "@oneforall/domain/schema/summary/sumRecordsSchema"; | ||
import { createDataArray } from "@pageComponents/showChart/components/createDataArray"; | ||
|
||
describe("createDataArray", () => { | ||
it("", () => { | ||
const criteria: SummaryCriteria = { | ||
groupingFields: { | ||
f1: { | ||
id: "f1", | ||
fieldName: "値", | ||
fieldKind: "text", | ||
fieldIndex: 1, | ||
options: {}, | ||
}, | ||
}, | ||
summaryFields: { | ||
f2: { | ||
id: "f2", | ||
fieldName: "数値", | ||
fieldKind: "numeric", | ||
fieldIndex: 2, | ||
options: { | ||
thousandsSeparatorPosition: 3, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const records: Records = { | ||
r1: { | ||
recordId: "1718289218434", | ||
isEditing: false, | ||
columns: { | ||
f1: { | ||
fieldKind: "text", | ||
value: "あああ", | ||
}, | ||
f2: { | ||
fieldKind: "numeric", | ||
value: "100", | ||
}, | ||
}, | ||
}, | ||
r2: { | ||
recordId: "1718289227545", | ||
isEditing: false, | ||
columns: { | ||
f1: { | ||
fieldKind: "text", | ||
value: "あああ", | ||
}, | ||
f2: { | ||
fieldKind: "numeric", | ||
value: "200", | ||
}, | ||
}, | ||
}, | ||
r3: { | ||
recordId: "1718289236639", | ||
isEditing: false, | ||
columns: { | ||
f1: { | ||
fieldKind: "text", | ||
value: "いいい", | ||
}, | ||
f2: { | ||
fieldKind: "numeric", | ||
value: "200", | ||
}, | ||
}, | ||
}, | ||
r4: { | ||
recordId: "1718895572486", | ||
isEditing: false, | ||
columns: { | ||
f1: { | ||
fieldKind: "text", | ||
value: "ううう", | ||
}, | ||
f2: { | ||
fieldKind: "numeric", | ||
value: "500", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
expect(createDataArray({ records, criteria })).toEqual([ | ||
{ | ||
name: "あああ", | ||
value: 300, | ||
}, | ||
{ | ||
name: "いいい", | ||
value: 200, | ||
}, | ||
{ | ||
name: "ううう", | ||
value: 500, | ||
}, | ||
]); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
apps/web/src/pageComponents/showChart/components/createDataArray.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { sumRecords } from "@oneforall/domain/convert/summary/sumRecords"; | ||
import { Records } from "@oneforall/domain/schema/recordSchema"; | ||
import { SummaryCriteria } from "@oneforall/domain/schema/summary/sumRecordsSchema"; | ||
|
||
export const createDataArray = ({ | ||
records, | ||
criteria, | ||
}: { | ||
records: Records; | ||
criteria: SummaryCriteria; | ||
}) => { | ||
return Object.values(sumRecords(records, criteria)).map((record) => { | ||
const name: string = Object.values(record.columns)[0]?.value ?? ""; | ||
const value: number = record.sum; | ||
|
||
return { name, value }; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { Records } from "../../schema/recordSchema"; | ||
import { | ||
SummaryCriteria, | ||
SumRecords, | ||
} from "../../schema/summary/sumRecordsSchema"; | ||
import { sumRecords } from "./sumRecords"; | ||
|
||
describe("sumRecords", () => { | ||
it("", () => { | ||
const records: Records = { | ||
r1: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 上記の指摘 |
||
recordId: "r1", | ||
isEditing: false, | ||
columns: { | ||
c1: { | ||
value: "grouping1", | ||
fieldKind: "text", | ||
}, | ||
c2: { | ||
value: "100", | ||
fieldKind: "numeric", | ||
}, | ||
c3: { | ||
value: "r1c3", | ||
fieldKind: "text", | ||
}, | ||
}, | ||
}, | ||
r2: { | ||
recordId: "r2", | ||
isEditing: false, | ||
columns: { | ||
c1: { | ||
value: "grouping1", | ||
fieldKind: "text", | ||
}, | ||
c2: { | ||
value: "200", | ||
fieldKind: "numeric", | ||
}, | ||
c3: { | ||
value: "r2c3", | ||
fieldKind: "text", | ||
}, | ||
}, | ||
}, | ||
r3: { | ||
recordId: "r3", | ||
isEditing: false, | ||
columns: { | ||
c1: { | ||
value: "grouping2", | ||
fieldKind: "text", | ||
}, | ||
c2: { | ||
value: "300", | ||
fieldKind: "numeric", | ||
}, | ||
c3: { | ||
value: "r3c3", | ||
fieldKind: "text", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const criteria: SummaryCriteria = { | ||
groupingFields: { | ||
c1: { | ||
id: "c1", | ||
fieldName: "c1", | ||
fieldKind: "text", | ||
fieldIndex: 1, | ||
options: {}, | ||
}, | ||
}, | ||
summaryFields: { | ||
c2: { | ||
id: "c2", | ||
fieldName: "c2", | ||
fieldKind: "numeric", | ||
fieldIndex: 2, | ||
options: { | ||
thousandsSeparatorPosition: 3, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
expect(sumRecords(records, criteria)).toEqual<SumRecords>({ | ||
0: { | ||
columns: { | ||
c1: { | ||
value: "grouping1", | ||
fieldKind: "text", | ||
}, | ||
c2: { | ||
value: "300", | ||
fieldKind: "numeric", | ||
}, | ||
}, | ||
sum: 300, | ||
average: 150, | ||
count: 2, | ||
}, | ||
1: { | ||
columns: { | ||
c1: { | ||
value: "grouping2", | ||
fieldKind: "text", | ||
}, | ||
c2: { | ||
value: "300", | ||
fieldKind: "numeric", | ||
}, | ||
}, | ||
sum: 300, | ||
average: 300, | ||
count: 1, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Records } from "../../schema/recordSchema"; | ||
import { | ||
SummaryCriteria, | ||
SumRecords, | ||
} from "../../schema/summary/sumRecordsSchema"; | ||
|
||
export const sumRecords = ( | ||
records: Records, | ||
criteria: SummaryCriteria, | ||
): SumRecords => { | ||
if ( | ||
Object.keys(criteria.groupingFields).length < 1 || | ||
Object.keys(criteria.summaryFields).length < 1 | ||
) { | ||
throw new Error("groupingFields is empty"); | ||
} | ||
|
||
const groupingFieldId = Object.values(criteria.groupingFields)[0]!.id; | ||
const sumFieldId = Object.values(criteria.summaryFields)[0]!.id; | ||
|
||
const uniqueGroupingValues = [ | ||
...new Set( | ||
Object.values(records).map((r) => r.columns[groupingFieldId]?.value), | ||
), | ||
]; | ||
|
||
const result = uniqueGroupingValues | ||
.map((groupingValue) => ({ | ||
groupingFieldId, | ||
groupingValue, | ||
sumFieldId, | ||
})) | ||
.flatMap((field) => { | ||
const motherRecords = Object.values(records).filter( | ||
(record) => | ||
record.columns[field.groupingFieldId]?.value === field.groupingValue, | ||
); | ||
|
||
const sum = motherRecords.reduce( | ||
(acc, record) => acc + Number(record.columns[field.sumFieldId]?.value), | ||
0, | ||
); | ||
|
||
return [ | ||
{ | ||
columns: { | ||
[field.groupingFieldId]: { | ||
value: field.groupingValue ?? "", | ||
fieldKind: | ||
criteria.groupingFields[field.groupingFieldId]?.fieldKind ?? | ||
"text", | ||
}, | ||
[field.sumFieldId]: { | ||
value: sum.toString(), | ||
fieldKind: | ||
criteria.summaryFields[field.sumFieldId]?.fieldKind ?? | ||
"numeric", | ||
}, | ||
}, | ||
sum, | ||
count: motherRecords.length, | ||
average: sum / motherRecords.length, | ||
}, | ||
]; | ||
}); | ||
|
||
return Object.fromEntries(result.map((res, index) => [index, res])); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
対応不要な備忘録
複数の引数がある時
a: string, b: stringだと
引数を渡す時に、間違えることがあるので、オブジェクトに包むようにしています
今回の場合は、それぞれ型がしっかりとあるので
オブジェクトで包むのは必須ではないです