use ids instead of alphabets (index)

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-08-20 21:42:02 +02:00
parent a5b06c8af0
commit a6b3d341c1
9 changed files with 47 additions and 10 deletions

View File

@@ -4,7 +4,6 @@ import { ColorSquare } from '@/components/color-square';
import { AutoSizer } from '@/components/react-virtualized-auto-sizer'; import { AutoSizer } from '@/components/react-virtualized-auto-sizer';
import { Progress } from '@/components/ui/progress'; import { Progress } from '@/components/ui/progress';
import { Widget, WidgetBody } from '@/components/widget'; import { Widget, WidgetBody } from '@/components/widget';
import { pushModal } from '@/modals';
import type { RouterOutputs } from '@/trpc/client'; import type { RouterOutputs } from '@/trpc/client';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import { round } from '@/utils/math'; import { round } from '@/utils/math';
@@ -13,6 +12,7 @@ import { AlertCircleIcon } from 'lucide-react';
import { last } from 'ramda'; import { last } from 'ramda';
import { Cell, Pie, PieChart } from 'recharts'; import { Cell, Pie, PieChart } from 'recharts';
import { alphabetIds } from '@openpanel/constants';
import type { IChartInput } from '@openpanel/validation'; import type { IChartInput } from '@openpanel/validation';
import { useChartContext } from '../chart/ChartProvider'; import { useChartContext } from '../chart/ChartProvider';
@@ -109,7 +109,7 @@ export function FunnelSteps({
</Pie> </Pie>
</PieChart> </PieChart>
<div <div
className="absolute inset-0 flex items-center justify-center font-mono font-bold" className="font-mono absolute inset-0 flex items-center justify-center font-bold"
style={{ style={{
fontSize: width / 6, fontSize: width / 6,
}} }}
@@ -162,7 +162,7 @@ export function FunnelSteps({
> >
<div className="relative flex flex-1 flex-col gap-2 pl-8"> <div className="relative flex flex-1 flex-col gap-2 pl-8">
<ColorSquare className="absolute left-0 top-0.5"> <ColorSquare className="absolute left-0 top-0.5">
{step.event.id} {alphabetIds[index]}
</ColorSquare> </ColorSquare>
<div className="font-semibold capitalize"> <div className="font-semibold capitalize">
{step.event.displayName.replace(/_/g, ' ')} {step.event.displayName.replace(/_/g, ' ')}

View File

@@ -8,6 +8,7 @@ import {
startOfDay, startOfDay,
} from 'date-fns'; } from 'date-fns';
import { shortId } from '@openpanel/common';
import { import {
alphabetIds, alphabetIds,
getDefaultIntervalByDates, getDefaultIntervalByDates,
@@ -91,7 +92,7 @@ export const reportSlice = createSlice({
addEvent: (state, action: PayloadAction<Omit<IChartEvent, 'id'>>) => { addEvent: (state, action: PayloadAction<Omit<IChartEvent, 'id'>>) => {
state.dirty = true; state.dirty = true;
state.events.push({ state.events.push({
id: alphabetIds[state.events.length]!, id: shortId(),
...action.payload, ...action.payload,
}); });
}, },
@@ -129,7 +130,7 @@ export const reportSlice = createSlice({
) => { ) => {
state.dirty = true; state.dirty = true;
state.breakdowns.push({ state.breakdowns.push({
id: alphabetIds[state.breakdowns.length]!, id: shortId(),
...action.payload, ...action.payload,
}); });
}, },

View File

@@ -11,6 +11,7 @@ import { useEventNames } from '@/hooks/useEventNames';
import { useDispatch, useSelector } from '@/redux'; import { useDispatch, useSelector } from '@/redux';
import { GanttChart, GanttChartIcon, Users } from 'lucide-react'; import { GanttChart, GanttChartIcon, Users } from 'lucide-react';
import { alphabetIds } from '@openpanel/constants';
import type { IChartEvent } from '@openpanel/validation'; import type { IChartEvent } from '@openpanel/validation';
import { import {
@@ -57,11 +58,11 @@ export function ReportEvents() {
<div> <div>
<h3 className="mb-2 font-medium">Events</h3> <h3 className="mb-2 font-medium">Events</h3>
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
{selectedEvents.map((event) => { {selectedEvents.map((event, index) => {
return ( return (
<div key={event.id} className="rounded-lg border bg-def-100"> <div key={event.id} className="rounded-lg border bg-def-100">
<div className="flex items-center gap-2 p-2"> <div className="flex items-center gap-2 p-2">
<ColorSquare>{event.id}</ColorSquare> <ColorSquare>{alphabetIds[index]}</ColorSquare>
<Combobox <Combobox
icon={GanttChartIcon} icon={GanttChartIcon}
className="flex-1" className="flex-1"
@@ -84,7 +85,9 @@ export function ReportEvents() {
/> />
<Input <Input
placeholder={ placeholder={
event.name ? `${event.name} (${event.id})` : 'Display name' event.name
? `${event.name} (${alphabetIds[index]})`
: 'Display name'
} }
defaultValue={event.displayName} defaultValue={event.displayName}
onChange={(e) => { onChange={(e) => {

View File

@@ -4,6 +4,7 @@ import { useDispatch, useSelector } from '@/redux';
import { api } from '@/trpc/client'; import { api } from '@/trpc/client';
import { FilterIcon } from 'lucide-react'; import { FilterIcon } from 'lucide-react';
import { shortId } from '@openpanel/common';
import type { IChartEvent } from '@openpanel/validation'; import type { IChartEvent } from '@openpanel/validation';
import { changeEvent } from '../../reportSlice'; import { changeEvent } from '../../reportSlice';
@@ -48,7 +49,7 @@ export function FiltersCombobox({ event }: FiltersComboboxProps) {
filters: [ filters: [
...event.filters, ...event.filters,
{ {
id: Math.random().toString(36).substring(7), id: shortId(),
name: value, name: value,
operator: 'is', operator: 'is',
value: [], value: [],

View File

@@ -8,3 +8,4 @@ export * from './src/math';
export * from './src/slug'; export * from './src/slug';
export * from './src/fill-series'; export * from './src/fill-series';
export * from './src/url'; export * from './src/url';
export * from './src/id';

View File

@@ -11,16 +11,17 @@
"@openpanel/constants": "workspace:*", "@openpanel/constants": "workspace:*",
"date-fns": "^3.3.1", "date-fns": "^3.3.1",
"mathjs": "^12.3.2", "mathjs": "^12.3.2",
"nanoid": "^5.0.7",
"ramda": "^0.29.1", "ramda": "^0.29.1",
"slugify": "^1.6.6", "slugify": "^1.6.6",
"superjson": "^1.13.3", "superjson": "^1.13.3",
"unique-names-generator": "^4.7.1" "unique-names-generator": "^4.7.1"
}, },
"devDependencies": { "devDependencies": {
"@openpanel/validation": "workspace:*",
"@openpanel/eslint-config": "workspace:*", "@openpanel/eslint-config": "workspace:*",
"@openpanel/prettier-config": "workspace:*", "@openpanel/prettier-config": "workspace:*",
"@openpanel/tsconfig": "workspace:*", "@openpanel/tsconfig": "workspace:*",
"@openpanel/validation": "workspace:*",
"@types/node": "^18.16.0", "@types/node": "^18.16.0",
"@types/ramda": "^0.29.6", "@types/ramda": "^0.29.6",
"eslint": "^8.48.0", "eslint": "^8.48.0",

View File

@@ -0,0 +1,5 @@
import { nanoid } from 'nanoid/non-secure';
export function shortId() {
return nanoid(4);
}

View File

@@ -115,6 +115,22 @@ export const alphabetIds = [
'H', 'H',
'I', 'I',
'J', 'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
] as const; ] as const;
export const deprecated_timeRanges = { export const deprecated_timeRanges = {

9
pnpm-lock.yaml generated
View File

@@ -895,6 +895,9 @@ importers:
mathjs: mathjs:
specifier: ^12.3.2 specifier: ^12.3.2
version: 12.3.2 version: 12.3.2
nanoid:
specifier: ^5.0.7
version: 5.0.7
ramda: ramda:
specifier: ^0.29.1 specifier: ^0.29.1
version: 0.29.1 version: 0.29.1
@@ -14642,6 +14645,12 @@ packages:
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true hasBin: true
/nanoid@5.0.7:
resolution: {integrity: sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==}
engines: {node: ^18 || >=20}
hasBin: true
dev: false
/natural-compare@1.4.0: /natural-compare@1.4.0:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}