Compare commits
4 Commits
4a8ed46c70
...
1.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| a227c14e0a | |||
| 58df11c623 | |||
| 9771816cf9 | |||
| 7bd946ec7a |
40
.dockerignore
Normal file
40
.dockerignore
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Node modules
|
||||||
|
node_modules
|
||||||
|
**/node_modules
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
logs
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Build outputs
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
out
|
||||||
|
.next
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Environment files
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# IDE / Editor folders
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.sublime-workspace
|
||||||
|
*.sublime-project
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
*.swp
|
||||||
|
*.bak
|
||||||
|
*.tmp
|
||||||
140
.drone.yml
Normal file
140
.drone.yml
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
workspace:
|
||||||
|
path: /drone/src
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: fetch-tags
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache git
|
||||||
|
- git fetch --tags
|
||||||
|
- |
|
||||||
|
# Get latest Git tag and trim newline
|
||||||
|
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null | tr -d '\n')
|
||||||
|
echo "Latest Git tag fetched: $LATEST_TAG"
|
||||||
|
|
||||||
|
# Save to file for downstream steps
|
||||||
|
echo "$LATEST_TAG" > /drone/src/LATEST_TAG.txt
|
||||||
|
|
||||||
|
# Read back for verification
|
||||||
|
IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
echo "Image tag read from file: $IMAGE_TAG"
|
||||||
|
|
||||||
|
# Validate
|
||||||
|
if [ -z "$IMAGE_TAG" ]; then
|
||||||
|
echo "❌ No git tags found! Cannot continue."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: check-remote-image
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
|
||||||
|
- echo "Checking if apps/khata:$IMAGE_TAG exists on remote Docker..."
|
||||||
|
- echo "Existing Docker tags for apps/khata:"
|
||||||
|
- docker images --format "{{.Repository}}:{{.Tag}}" | grep "^apps/khata" || echo "(none)"
|
||||||
|
- |
|
||||||
|
if docker image inspect apps/khata:$IMAGE_TAG > /dev/null 2>&1; then
|
||||||
|
echo "✅ Docker image apps/khata:$IMAGE_TAG already exists — skipping build"
|
||||||
|
exit 78
|
||||||
|
else
|
||||||
|
echo "⚙️ Docker image apps/khata:$IMAGE_TAG not found — proceeding to build..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: build-image
|
||||||
|
image: docker:24
|
||||||
|
environment:
|
||||||
|
API_BASE_URL:
|
||||||
|
from_secret: API_BASE_URL
|
||||||
|
AUTH_BASE_URL:
|
||||||
|
from_secret: AUTH_BASE_URL
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
|
||||||
|
- echo "🔨 Building Docker image apps/khata:$IMAGE_TAG ..."
|
||||||
|
- |
|
||||||
|
docker build --network=host \
|
||||||
|
--build-arg VITE_API_BASE_URL="$API_BASE_URL" \
|
||||||
|
--build-arg VITE_AUTH_BASE_URL="$AUTH_BASE_URL" \
|
||||||
|
-t apps/khata:$IMAGE_TAG \
|
||||||
|
-t apps/khata:latest \
|
||||||
|
/drone/src
|
||||||
|
|
||||||
|
- name: push-image
|
||||||
|
image: docker:24
|
||||||
|
environment:
|
||||||
|
REGISTRY_HOST:
|
||||||
|
from_secret: REGISTRY_HOST
|
||||||
|
REGISTRY_USER:
|
||||||
|
from_secret: REGISTRY_USER
|
||||||
|
REGISTRY_PASS:
|
||||||
|
from_secret: REGISTRY_PASS
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
|
||||||
|
- echo "🔑 Logging into registry $REGISTRY_HOST ..."
|
||||||
|
- echo "$REGISTRY_PASS" | docker login $REGISTRY_HOST -u "$REGISTRY_USER" --password-stdin
|
||||||
|
- echo "🏷️ Tagging images with registry prefix..."
|
||||||
|
- docker tag apps/khata:$IMAGE_TAG $REGISTRY_HOST/apps/khata:$IMAGE_TAG
|
||||||
|
- docker tag apps/khata:$IMAGE_TAG $REGISTRY_HOST/apps/khata:latest
|
||||||
|
- echo "📤 Pushing apps/khata:$IMAGE_TAG ..."
|
||||||
|
- docker push $REGISTRY_HOST/apps/khata:$IMAGE_TAG
|
||||||
|
- echo "📤 Pushing apps/khata:latest ..."
|
||||||
|
- docker push $REGISTRY_HOST/apps/khata:latest
|
||||||
|
|
||||||
|
- name: stop-old
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- echo "🛑 Stopping old container..."
|
||||||
|
- docker rm -f khata || true
|
||||||
|
|
||||||
|
- name: run-container
|
||||||
|
image: docker:24
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
|
||||||
|
- echo "🚀 Starting container apps/khata:$IMAGE_TAG ..."
|
||||||
|
- |
|
||||||
|
docker run -d \
|
||||||
|
--name khata \
|
||||||
|
-p 3002:3000 \
|
||||||
|
-e NODE_ENV=production \
|
||||||
|
--restart always \
|
||||||
|
apps/khata:$IMAGE_TAG
|
||||||
|
|
||||||
|
# Trigger rules
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Stage 1: Build
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package.json and package-lock.json (or yarn.lock)
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy the rest of the app
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the app
|
||||||
|
ARG VITE_API_BASE_URL
|
||||||
|
ARG VITE_AUTH_BASE_URL
|
||||||
|
RUN VITE_API_BASE_URL=$VITE_API_BASE_URL VITE_AUTH_BASE_URL=$VITE_AUTH_BASE_URL npm run build
|
||||||
|
|
||||||
|
# Stage 2: Static file server (BusyBox)
|
||||||
|
FROM busybox:latest
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy only build frontend files
|
||||||
|
COPY --from=builder /app/dist /app
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Default command
|
||||||
|
CMD ["busybox", "httpd", "-f", "-p", "3000"]
|
||||||
@@ -278,19 +278,10 @@ function MobileCardRow({ row, config, onDelete, onNavigate, navigate, components
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedDisplayValue(item: any, displayField?: string | string[], enumValue?: string) {
|
function getFormattedDisplayValue(item: any, displayFormat: string) {
|
||||||
if (!item) return "";
|
if (!item) return "";
|
||||||
if (enumValue) return resolveTemplate(enumValue, item);
|
|
||||||
if (!displayField) return item.name || item.title || item.label || item.id || JSON.stringify(item);
|
|
||||||
|
|
||||||
if (Array.isArray(displayField)) {
|
return resolveTemplate(displayFormat, item);
|
||||||
return displayField
|
|
||||||
.map(key => item[key])
|
|
||||||
.filter(val => val !== undefined && val !== null)
|
|
||||||
.join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
return item[displayField] || item.id || JSON.stringify(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate, isMobile, components }: any) {
|
function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate, isMobile, components }: any) {
|
||||||
@@ -307,7 +298,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
// 1. Single Relation
|
// 1. Single Relation
|
||||||
if (field.relation && value && !Array.isArray(value)) {
|
if (field.relation && value && !Array.isArray(value)) {
|
||||||
const relationId = typeof value === 'object' ? (value.id || value._id || value.pk) : value;
|
const relationId = typeof value === 'object' ? (value.id || value._id || value.pk) : value;
|
||||||
const displayValue = getFormattedDisplayValue(value, field.displayField, field.enumOption?.value);
|
const displayValue = getFormattedDisplayValue(value, field.displayFormat);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
@@ -327,7 +318,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
// 2. Multi-Select (Array of relations or simple strings)
|
// 2. Multi-Select (Array of relations or simple strings)
|
||||||
if (field.type === 'array' && Array.isArray(value)) {
|
if (field.type === 'array' && Array.isArray(value)) {
|
||||||
const enumValue = field.enumOption?.value;
|
const enumValue = field.enumOption?.value;
|
||||||
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayField, enumValue)).join(', ');
|
const tooltipTitle = value.map((item) => getFormattedDisplayValue(item, field.displayFormat)).join(', ');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip title={tooltipTitle} arrow placement="top">
|
<Tooltip title={tooltipTitle} arrow placement="top">
|
||||||
@@ -335,7 +326,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
{value.map((item, idx) => (
|
{value.map((item, idx) => (
|
||||||
<Chip
|
<Chip
|
||||||
key={idx}
|
key={idx}
|
||||||
label={getFormattedDisplayValue(item, field.displayField, enumValue)}
|
label={getFormattedDisplayValue(item, field.displayFormat)}
|
||||||
size="small"
|
size="small"
|
||||||
variant="filled"
|
variant="filled"
|
||||||
sx={{ maxWidth: 120 }}
|
sx={{ maxWidth: 120 }}
|
||||||
@@ -355,7 +346,7 @@ function FieldRenderer({ params, field, fieldKey, config, onNavigate, navigate,
|
|||||||
|
|
||||||
// 3. Simple Objects
|
// 3. Simple Objects
|
||||||
if (field.type === 'object' && value) {
|
if (field.type === 'object' && value) {
|
||||||
return getFormattedDisplayValue(value, field.displayField, field.enumOption?.value) || (isMobile ? 'Object' : JSON.stringify(value));
|
return getFormattedDisplayValue(value, field.displayFormat) || (isMobile ? 'Object' : JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field.type === 'number' && typeof value === 'number') {
|
if (field.type === 'number' && typeof value === 'number') {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import DoneIcon from "@mui/icons-material/Done";
|
import DoneIcon from "@mui/icons-material/Done";
|
||||||
import FilterListIcon from "@mui/icons-material/FilterList";
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
||||||
import { ResourceField, ResourceMode } from "../types/config";
|
import { ResourceField, ResourceMode } from "../types/config";
|
||||||
import { FilterBarComponents } from "../types/overrides";
|
import { FilterBarComponents, FieldComponents } from "../types/overrides";
|
||||||
import { getFieldOptions, resolveTemplate } from "../utils/options";
|
import { getFieldOptions, resolveTemplate } from "../utils/options";
|
||||||
|
|
||||||
export function FilterAutocomplete({
|
export function FilterAutocomplete({
|
||||||
@@ -124,7 +124,7 @@ function extractOptions(
|
|||||||
|
|
||||||
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
||||||
|
|
||||||
// Use displayFormat if defined, otherwise fall back to displayField logic (for backward compatibility)
|
// Use displayFormat if defined
|
||||||
if (field.displayFormat) {
|
if (field.displayFormat) {
|
||||||
return resolveTemplate(field.displayFormat, item);
|
return resolveTemplate(field.displayFormat, item);
|
||||||
}
|
}
|
||||||
@@ -158,36 +158,22 @@ function renderFilterInput(
|
|||||||
value: any,
|
value: any,
|
||||||
onChange: (key: string, val: any) => void,
|
onChange: (key: string, val: any) => void,
|
||||||
components?: FilterBarComponents,
|
components?: FilterBarComponents,
|
||||||
|
fieldComponents?: FieldComponents,
|
||||||
) {
|
) {
|
||||||
const CustomInput = components?.filterInputs?.[fieldName];
|
|
||||||
if (CustomInput) {
|
|
||||||
return <CustomInput field={field} value={value} onChange={(val) => onChange("value", val)} options={options} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterType = field.filterType;
|
const filterType = field.filterType;
|
||||||
|
|
||||||
if (filterType === "number-range") {
|
if (filterType === "number-range") {
|
||||||
|
const RangeComponent = fieldComponents?.numberRange;
|
||||||
|
if (!RangeComponent) throw new Error(`Number range component not found for field ${fieldName}`);
|
||||||
const rangeVal = (value as { min?: string; max?: string }) || {};
|
const rangeVal = (value as { min?: string; max?: string }) || {};
|
||||||
return (
|
return <RangeComponent name={fieldName} field={field} value={rangeVal} onChange={(val: any) => onChange("value", val)} />;
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
|
||||||
<TextField type="number" placeholder="Min" size="small" value={rangeVal.min ?? ""}
|
|
||||||
onChange={(e) => onChange("min", e.target.value || undefined)} sx={{ width: 100 }} />
|
|
||||||
<TextField type="number" placeholder="Max" size="small" value={rangeVal.max ?? ""}
|
|
||||||
onChange={(e) => onChange("max", e.target.value || undefined)} sx={{ width: 100 }} />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filterType === "date-range") {
|
if (filterType === "date-range") {
|
||||||
|
const RangeComponent = fieldComponents?.dateRange;
|
||||||
|
if (!RangeComponent) throw new Error(`Number range component not found for field ${fieldName}`);
|
||||||
const rangeVal = (value as { start?: string; end?: string }) || {};
|
const rangeVal = (value as { start?: string; end?: string }) || {};
|
||||||
return (
|
return <RangeComponent name={fieldName} field={field} value={rangeVal} onChange={(val: any) => onChange("value", val)} />;
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
|
||||||
<TextField type="datetime-local" placeholder="From" size="small" value={rangeVal.start ?? ""}
|
|
||||||
onChange={(e) => onChange("start", e.target.value || undefined)} InputLabelProps={{ shrink: true }} sx={{ width: 170 }} />
|
|
||||||
<TextField type="datetime-local" placeholder="To" size="small" value={rangeVal.end ?? ""}
|
|
||||||
onChange={(e) => onChange("end", e.target.value || undefined)} InputLabelProps={{ shrink: true }} sx={{ width: 170 }} />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const selected = Array.isArray(value) ? value : [];
|
const selected = Array.isArray(value) ? value : [];
|
||||||
@@ -211,6 +197,7 @@ export interface FilterBarProps {
|
|||||||
onApply: (values: Record<string, any>) => void;
|
onApply: (values: Record<string, any>) => void;
|
||||||
onClear: () => void;
|
onClear: () => void;
|
||||||
components?: FilterBarComponents;
|
components?: FilterBarComponents;
|
||||||
|
fieldComponents?: FieldComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FilterBar({
|
export default function FilterBar({
|
||||||
@@ -221,6 +208,7 @@ export default function FilterBar({
|
|||||||
onApply,
|
onApply,
|
||||||
onClear,
|
onClear,
|
||||||
components: filterComponents,
|
components: filterComponents,
|
||||||
|
fieldComponents,
|
||||||
}: FilterBarProps) {
|
}: FilterBarProps) {
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
const [draft, setDraft] = React.useState<Record<string, any>>(() => ({ ...appliedValues }));
|
const [draft, setDraft] = React.useState<Record<string, any>>(() => ({ ...appliedValues }));
|
||||||
@@ -298,7 +286,7 @@ export default function FilterBar({
|
|||||||
{field.label}
|
{field.label}
|
||||||
</Box>
|
</Box>
|
||||||
{renderFilterInput(fieldName, field, options, raw, (key, val) =>
|
{renderFilterInput(fieldName, field, options, raw, (key, val) =>
|
||||||
updateDraft(fieldName, key, val), filterComponents
|
updateDraft(fieldName, key, val), filterComponents, fieldComponents
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,13 +20,8 @@ import { GridPaginationModel } from '@mui/x-data-grid';
|
|||||||
function getDisplayString(item: any, field: ResourceField): string {
|
function getDisplayString(item: any, field: ResourceField): string {
|
||||||
if (item == null || typeof item !== 'object') return String(item ?? '');
|
if (item == null || typeof item !== 'object') return String(item ?? '');
|
||||||
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
if (field.enumOption?.value) return resolveTemplate(field.enumOption.value, item);
|
||||||
const df = field.displayField;
|
if (field.displayFormat) return resolveTemplate(field.displayFormat, item);
|
||||||
if (!df) return item.name ?? item.title ?? item.label ?? item.id ?? JSON.stringify(item);
|
throw new Error('cannot get display string')
|
||||||
if (Array.isArray(df)) {
|
|
||||||
const parts = df.map((k: string) => item[k]).filter((v: any) => v != null);
|
|
||||||
return parts.length > 0 ? parts.join(' ') : '';
|
|
||||||
}
|
|
||||||
return String(item[df] ?? '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyClientFilters(
|
function applyClientFilters(
|
||||||
@@ -119,7 +114,7 @@ export default function ResourceView({ config, onNavigateToResource, fieldCompon
|
|||||||
const { useList, useRead, useCreate, useUpdate, useDelete, components } = useResource(config, { fieldComponents });
|
const { useList, useRead, useCreate, useUpdate, useDelete, components } = useResource(config, { fieldComponents });
|
||||||
|
|
||||||
const queryParams = React.useMemo(() => {
|
const queryParams = React.useMemo(() => {
|
||||||
if (!isServer) return { limit: 10 };
|
if (!isServer) return { limit: 10000 };
|
||||||
return {
|
return {
|
||||||
skip: paginationModel.page * paginationModel.pageSize,
|
skip: paginationModel.page * paginationModel.pageSize,
|
||||||
limit: paginationModel.pageSize,
|
limit: paginationModel.pageSize,
|
||||||
@@ -184,6 +179,7 @@ export default function ResourceView({ config, onNavigateToResource, fieldCompon
|
|||||||
appliedValues={appliedFilters}
|
appliedValues={appliedFilters}
|
||||||
onApply={setAppliedFilters}
|
onApply={setAppliedFilters}
|
||||||
onClear={() => setAppliedFilters({})}
|
onClear={() => setAppliedFilters({})}
|
||||||
|
fieldComponents={components}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<EnhancedTable
|
<EnhancedTable
|
||||||
|
|||||||
30
react-openapi/components/fields/DateRangeField.tsx
Normal file
30
react-openapi/components/fields/DateRangeField.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Box, TextField as MuiTextField } from '@mui/material';
|
||||||
|
import { FieldComponentProps } from '../../types/overrides';
|
||||||
|
|
||||||
|
export default function DateRangeField({ value, onChange, disabled }: FieldComponentProps) {
|
||||||
|
const rangeVal = (value as { start?: string; end?: string }) || {};
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
|
<MuiTextField
|
||||||
|
type="date"
|
||||||
|
placeholder="From"
|
||||||
|
size="small"
|
||||||
|
value={rangeVal.start ?? ""}
|
||||||
|
onChange={(e) => onChange({ ...rangeVal, start: e.target.value || undefined })}
|
||||||
|
InputLabelProps={{ shrink: true }}
|
||||||
|
sx={{ width: 170 }}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
<MuiTextField
|
||||||
|
type="date"
|
||||||
|
placeholder="To"
|
||||||
|
size="small"
|
||||||
|
value={rangeVal.end ?? ""}
|
||||||
|
onChange={(e) => onChange({ ...rangeVal, end: e.target.value || undefined })}
|
||||||
|
InputLabelProps={{ shrink: true }}
|
||||||
|
sx={{ width: 170 }}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ import EnumField from './EnumField';
|
|||||||
import RelationField from './RelationField';
|
import RelationField from './RelationField';
|
||||||
import ImageUploadField from './ImageUploadField';
|
import ImageUploadField from './ImageUploadField';
|
||||||
import FallbackField from './FallbackField';
|
import FallbackField from './FallbackField';
|
||||||
|
import DateRangeField from './DateRangeField';
|
||||||
|
import NumberRangeField from './NumberRangeField';
|
||||||
|
|
||||||
const WrappedImageUploadField = (props: FieldComponentProps) =>
|
const WrappedImageUploadField = (props: FieldComponentProps) =>
|
||||||
React.createElement(ImageUploadField, {
|
React.createElement(ImageUploadField, {
|
||||||
@@ -33,4 +35,6 @@ export const defaultFieldComponents: FieldComponents = {
|
|||||||
image: WrappedImageUploadField,
|
image: WrappedImageUploadField,
|
||||||
relation: RelationField,
|
relation: RelationField,
|
||||||
default: FallbackField,
|
default: FallbackField,
|
||||||
|
dateRange: DateRangeField,
|
||||||
|
numberRange: NumberRangeField,
|
||||||
};
|
};
|
||||||
|
|||||||
28
react-openapi/components/fields/NumberRangeField.tsx
Normal file
28
react-openapi/components/fields/NumberRangeField.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Box, TextField as MuiTextField } from '@mui/material';
|
||||||
|
import { FieldComponentProps } from '../../types/overrides';
|
||||||
|
|
||||||
|
export default function NumberRangeField({ value, onChange, disabled }: FieldComponentProps) {
|
||||||
|
const rangeVal = (value as { min?: string; max?: string }) || {};
|
||||||
|
return (
|
||||||
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
|
<MuiTextField
|
||||||
|
type="number"
|
||||||
|
placeholder="Min"
|
||||||
|
size="small"
|
||||||
|
value={rangeVal.min ?? ""}
|
||||||
|
onChange={(e) => onChange({ ...rangeVal, min: e.target.value || undefined })}
|
||||||
|
sx={{ width: 100 }}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
<MuiTextField
|
||||||
|
type="number"
|
||||||
|
placeholder="Max"
|
||||||
|
size="small"
|
||||||
|
value={rangeVal.max ?? ""}
|
||||||
|
onChange={(e) => onChange({ ...rangeVal, max: e.target.value || undefined })}
|
||||||
|
sx={{ width: 100 }}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,5 +8,7 @@ export { default as EnumField } from './EnumField';
|
|||||||
export { default as RelationField } from './RelationField';
|
export { default as RelationField } from './RelationField';
|
||||||
export { default as ObjectField } from './ObjectField';
|
export { default as ObjectField } from './ObjectField';
|
||||||
export { default as FallbackField } from './FallbackField';
|
export { default as FallbackField } from './FallbackField';
|
||||||
|
export { default as DateRangeField } from './DateRangeField';
|
||||||
|
export { default as NumberRangeField } from './NumberRangeField';
|
||||||
export { defaultFieldComponents } from './DefaultFieldComponents';
|
export { defaultFieldComponents } from './DefaultFieldComponents';
|
||||||
export type { ObjectFieldProps } from './ObjectField';
|
export type { ObjectFieldProps } from './ObjectField';
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ export type FieldComponents = Partial<Record<FieldType, FieldComponent>> & {
|
|||||||
relation?: FieldComponent;
|
relation?: FieldComponent;
|
||||||
image?: FieldComponent;
|
image?: FieldComponent;
|
||||||
default?: FieldComponent;
|
default?: FieldComponent;
|
||||||
|
dateRange?: FieldComponent;
|
||||||
|
numberRange?: FieldComponent;
|
||||||
|
FormField?: React.ComponentType<any>;
|
||||||
|
GenericForm?: React.ComponentType<any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface CellRendererProps {
|
export interface CellRendererProps {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function getFieldOptions(field: ResourceField, relationData?: any[]): Sel
|
|||||||
}
|
}
|
||||||
|
|
||||||
return data.map(item => ({
|
return data.map(item => ({
|
||||||
key: String(item[enumOption.key] ?? ''),
|
key: String(item[enumOption.key]),
|
||||||
value: resolveTemplate(enumOption.value, item),
|
value: resolveTemplate(enumOption.value, item),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
Container,
|
Container,
|
||||||
Paper,
|
Paper,
|
||||||
Typography,
|
Typography,
|
||||||
TextField,
|
|
||||||
Button,
|
Button,
|
||||||
IconButton,
|
IconButton,
|
||||||
CircularProgress,
|
CircularProgress,
|
||||||
@@ -15,8 +14,6 @@ import {
|
|||||||
DialogContent,
|
DialogContent,
|
||||||
DialogContentText,
|
DialogContentText,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
Switch,
|
|
||||||
FormControlLabel,
|
|
||||||
Chip,
|
Chip,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
@@ -125,22 +122,17 @@ export default function ReportSnapshots() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box sx={{ display: "flex", flexDirection: "column", gap: 2 }}>
|
<Box sx={{ display: "flex", flexDirection: "column", gap: 2 }}>
|
||||||
{ignoreSelfField && components?.FormField ? (
|
{ignoreSelfField && components?.FormField && (
|
||||||
<components.FormField
|
<components.FormField
|
||||||
name="ignore_self"
|
name="ignore_self"
|
||||||
field={ignoreSelfField}
|
field={ignoreSelfField}
|
||||||
value={ignoreSelf}
|
value={ignoreSelf}
|
||||||
onChange={(val: boolean) => setIgnoreSelf(val)}
|
onChange={(val: boolean) => setIgnoreSelf(val)}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<FormControlLabel
|
|
||||||
control={<Switch checked={ignoreSelf} onChange={(e) => setIgnoreSelf(e.target.checked)} />}
|
|
||||||
label="Ignore self-transfers"
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Box sx={{ display: "flex", gap: 2 }}>
|
<Box sx={{ display: "flex", gap: 2 }}>
|
||||||
{startDateField && components?.datetime ? (
|
{startDateField && components?.datetime && (
|
||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<components.datetime
|
<components.datetime
|
||||||
name="start_date"
|
name="start_date"
|
||||||
@@ -149,18 +141,8 @@ export default function ReportSnapshots() {
|
|||||||
onChange={(val: string) => setStartDate(val)}
|
onChange={(val: string) => setStartDate(val)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
|
||||||
<TextField
|
|
||||||
label="Start Date"
|
|
||||||
type="datetime-local"
|
|
||||||
value={startDate}
|
|
||||||
onChange={(e) => setStartDate(e.target.value)}
|
|
||||||
size="small"
|
|
||||||
InputLabelProps={{ shrink: true }}
|
|
||||||
sx={{ flex: 1 }}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{endDateField && components?.datetime ? (
|
{endDateField && components?.datetime && (
|
||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<components.datetime
|
<components.datetime
|
||||||
name="end_date"
|
name="end_date"
|
||||||
@@ -169,21 +151,11 @@ export default function ReportSnapshots() {
|
|||||||
onChange={(val: string) => setEndDate(val)}
|
onChange={(val: string) => setEndDate(val)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
|
||||||
<TextField
|
|
||||||
label="End Date"
|
|
||||||
type="datetime-local"
|
|
||||||
value={endDate}
|
|
||||||
onChange={(e) => setEndDate(e.target.value)}
|
|
||||||
size="small"
|
|
||||||
InputLabelProps={{ shrink: true }}
|
|
||||||
sx={{ flex: 1 }}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box sx={{ display: "flex", gap: 2 }}>
|
<Box sx={{ display: "flex", gap: 2 }}>
|
||||||
{minAmountField && components?.FormField ? (
|
{minAmountField && components?.FormField && (
|
||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<components.FormField
|
<components.FormField
|
||||||
name="min_amount"
|
name="min_amount"
|
||||||
@@ -192,17 +164,8 @@ export default function ReportSnapshots() {
|
|||||||
onChange={(val: string) => setMinAmount(val)}
|
onChange={(val: string) => setMinAmount(val)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
|
||||||
<TextField
|
|
||||||
label="Min Amount"
|
|
||||||
type="number"
|
|
||||||
value={minAmount}
|
|
||||||
onChange={(e) => setMinAmount(e.target.value)}
|
|
||||||
size="small"
|
|
||||||
sx={{ flex: 1 }}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{maxAmountField && components?.FormField ? (
|
{maxAmountField && components?.FormField && (
|
||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<components.FormField
|
<components.FormField
|
||||||
name="max_amount"
|
name="max_amount"
|
||||||
@@ -211,15 +174,6 @@ export default function ReportSnapshots() {
|
|||||||
onChange={(val: string) => setMaxAmount(val)}
|
onChange={(val: string) => setMaxAmount(val)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
|
||||||
<TextField
|
|
||||||
label="Max Amount"
|
|
||||||
type="number"
|
|
||||||
value={maxAmount}
|
|
||||||
onChange={(e) => setMaxAmount(e.target.value)}
|
|
||||||
size="small"
|
|
||||||
sx={{ flex: 1 }}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
@@ -57,12 +57,12 @@ export const configuration: Record<string, ResourceOverride> = {
|
|||||||
format: {
|
format: {
|
||||||
path: 'source.format',
|
path: 'source.format',
|
||||||
},
|
},
|
||||||
account: {
|
// account: {
|
||||||
refers: 'accounts',
|
// refers: 'accounts',
|
||||||
},
|
// },
|
||||||
tags: {
|
// tags: {
|
||||||
refers: 'tags',
|
// refers: 'tags',
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
accounts: {
|
accounts: {
|
||||||
|
|||||||
Reference in New Issue
Block a user