|
@@ -1,5 +1,4 @@
|
|
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
-import { nanoid } from 'nanoid';
|
|
|
import { FieldType } from '../../../../services/backend/models/flowy-database/field_entities';
|
|
|
import { DateFormat, NumberFormat, SelectOptionColorPB, TimeFormat } from '../../../../services/backend';
|
|
|
|
|
@@ -9,42 +8,35 @@ export interface ISelectOption {
|
|
|
color?: SelectOptionColorPB;
|
|
|
}
|
|
|
|
|
|
-export interface IFieldOptions {
|
|
|
- selectOptions?: ISelectOption[];
|
|
|
- dateFormat?: DateFormat;
|
|
|
- timeFormat?: TimeFormat;
|
|
|
- includeTime?: boolean;
|
|
|
- numberFormat?: NumberFormat;
|
|
|
+export interface ISelectOptionType {
|
|
|
+ selectOptions: ISelectOption[];
|
|
|
+}
|
|
|
+
|
|
|
+export interface IDateType {
|
|
|
+ dateFormat: DateFormat;
|
|
|
+ timeFormat: TimeFormat;
|
|
|
+ includeTime: boolean;
|
|
|
+}
|
|
|
+
|
|
|
+export interface INumberType {
|
|
|
+ numberFormat: NumberFormat;
|
|
|
}
|
|
|
|
|
|
export interface IDatabaseField {
|
|
|
fieldId: string;
|
|
|
title: string;
|
|
|
fieldType: FieldType;
|
|
|
- fieldOptions: IFieldOptions;
|
|
|
+ fieldOptions?: ISelectOptionType | IDateType | INumberType;
|
|
|
}
|
|
|
|
|
|
export interface IDatabaseColumn {
|
|
|
fieldId: string;
|
|
|
sort: 'none' | 'asc' | 'desc';
|
|
|
- filter?: any;
|
|
|
visible: boolean;
|
|
|
}
|
|
|
|
|
|
-export interface ICellData {
|
|
|
- rowId: string;
|
|
|
- fieldId: string;
|
|
|
- cellId: string;
|
|
|
- data: string | number;
|
|
|
- optionIds?: string[];
|
|
|
-}
|
|
|
-
|
|
|
-export type DatabaseCellMap = { [keys: string]: ICellData };
|
|
|
-
|
|
|
export interface IDatabaseRow {
|
|
|
rowId: string;
|
|
|
- // key(fieldId) -> value(Cell)
|
|
|
- cells: DatabaseCellMap;
|
|
|
}
|
|
|
|
|
|
export type DatabaseFieldMap = { [keys: string]: IDatabaseField };
|
|
@@ -56,190 +48,47 @@ export interface IDatabase {
|
|
|
columns: IDatabaseColumn[];
|
|
|
}
|
|
|
|
|
|
-// key(databaseId) -> value(IDatabase)
|
|
|
const initialState: IDatabase = {
|
|
|
title: 'Database One',
|
|
|
- columns: [
|
|
|
- {
|
|
|
- visible: true,
|
|
|
- fieldId: 'field1',
|
|
|
- sort: 'none',
|
|
|
- },
|
|
|
- {
|
|
|
- visible: true,
|
|
|
- fieldId: 'field2',
|
|
|
- sort: 'none',
|
|
|
- },
|
|
|
- {
|
|
|
- visible: true,
|
|
|
- fieldId: 'field3',
|
|
|
- sort: 'none',
|
|
|
- },
|
|
|
- {
|
|
|
- visible: true,
|
|
|
- fieldId: 'field4',
|
|
|
- sort: 'none',
|
|
|
- },
|
|
|
- ],
|
|
|
- fields: {
|
|
|
- field1: {
|
|
|
- title: 'status',
|
|
|
- fieldId: 'field1',
|
|
|
- fieldType: FieldType.SingleSelect,
|
|
|
- fieldOptions: {
|
|
|
- selectOptions: [
|
|
|
- {
|
|
|
- selectOptionId: 'so1',
|
|
|
- title: 'To Do',
|
|
|
- color: SelectOptionColorPB.Orange,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'so2',
|
|
|
- title: 'In Progress',
|
|
|
- color: SelectOptionColorPB.Green,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'so3',
|
|
|
- title: 'Done',
|
|
|
- color: SelectOptionColorPB.Blue,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- },
|
|
|
- field2: {
|
|
|
- title: 'name',
|
|
|
- fieldId: 'field2',
|
|
|
- fieldType: FieldType.RichText,
|
|
|
- fieldOptions: {},
|
|
|
- },
|
|
|
- field3: {
|
|
|
- title: 'percent',
|
|
|
- fieldId: 'field3',
|
|
|
- fieldType: FieldType.Number,
|
|
|
- fieldOptions: {
|
|
|
- numberFormat: NumberFormat.Num,
|
|
|
- },
|
|
|
- },
|
|
|
- field4: {
|
|
|
- title: 'tags',
|
|
|
- fieldId: 'field4',
|
|
|
- fieldType: FieldType.MultiSelect,
|
|
|
- fieldOptions: {
|
|
|
- selectOptions: [
|
|
|
- {
|
|
|
- selectOptionId: 'f4so1',
|
|
|
- title: 'type1',
|
|
|
- color: SelectOptionColorPB.Blue,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so2',
|
|
|
- title: 'type2',
|
|
|
- color: SelectOptionColorPB.Aqua,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so3',
|
|
|
- title: 'type3',
|
|
|
- color: SelectOptionColorPB.Purple,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so4',
|
|
|
- title: 'type4',
|
|
|
- color: SelectOptionColorPB.Purple,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so5',
|
|
|
- title: 'type5',
|
|
|
- color: SelectOptionColorPB.Purple,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so6',
|
|
|
- title: 'type6',
|
|
|
- color: SelectOptionColorPB.Purple,
|
|
|
- },
|
|
|
- {
|
|
|
- selectOptionId: 'f4so7',
|
|
|
- title: 'type7',
|
|
|
- color: SelectOptionColorPB.Purple,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- rows: [
|
|
|
- {
|
|
|
- rowId: 'row1',
|
|
|
- cells: {
|
|
|
- field1: {
|
|
|
- rowId: 'row1',
|
|
|
- fieldId: 'field1',
|
|
|
- cellId: 'cell11',
|
|
|
- data: '',
|
|
|
- optionIds: ['so1'],
|
|
|
- },
|
|
|
- field2: {
|
|
|
- rowId: 'row1',
|
|
|
- fieldId: 'field2',
|
|
|
- cellId: 'cell12',
|
|
|
- data: 'Card 1',
|
|
|
- },
|
|
|
- field3: {
|
|
|
- rowId: 'row1',
|
|
|
- fieldId: 'field3',
|
|
|
- cellId: 'cell13',
|
|
|
- data: 10,
|
|
|
- },
|
|
|
- field4: {
|
|
|
- rowId: 'row1',
|
|
|
- fieldId: 'field4',
|
|
|
- cellId: 'cell14',
|
|
|
- data: '',
|
|
|
- optionIds: ['f4so2', 'f4so3', 'f4so4', 'f4so5', 'f4so6', 'f4so7'],
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- rowId: 'row2',
|
|
|
- cells: {
|
|
|
- field1: {
|
|
|
- rowId: 'row2',
|
|
|
- fieldId: 'field1',
|
|
|
- cellId: 'cell21',
|
|
|
- data: '',
|
|
|
- optionIds: ['so1'],
|
|
|
- },
|
|
|
- field2: {
|
|
|
- rowId: 'row2',
|
|
|
- fieldId: 'field2',
|
|
|
- cellId: 'cell22',
|
|
|
- data: 'Card 2',
|
|
|
- },
|
|
|
- field3: {
|
|
|
- rowId: 'row2',
|
|
|
- fieldId: 'field3',
|
|
|
- cellId: 'cell23',
|
|
|
- data: 20,
|
|
|
- },
|
|
|
- field4: {
|
|
|
- rowId: 'row2',
|
|
|
- fieldId: 'field4',
|
|
|
- cellId: 'cell24',
|
|
|
- data: '',
|
|
|
- optionIds: ['f4so1'],
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- ],
|
|
|
+ columns: [],
|
|
|
+ fields: {},
|
|
|
+ rows: [],
|
|
|
};
|
|
|
|
|
|
export const databaseSlice = createSlice({
|
|
|
name: 'database',
|
|
|
initialState: initialState,
|
|
|
reducers: {
|
|
|
+ clear: () => {
|
|
|
+ return initialState;
|
|
|
+ },
|
|
|
+
|
|
|
+ updateRows: (state, action: PayloadAction<{ rows: IDatabaseRow[] }>) => {
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ rows: action.payload.rows,
|
|
|
+ };
|
|
|
+ },
|
|
|
+
|
|
|
+ updateFields: (state, action: PayloadAction<{ fields: DatabaseFieldMap }>) => {
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ fields: action.payload.fields,
|
|
|
+ };
|
|
|
+ },
|
|
|
+
|
|
|
+ updateColumns: (state, action: PayloadAction<{ columns: IDatabaseColumn[] }>) => {
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ columns: action.payload.columns,
|
|
|
+ };
|
|
|
+ },
|
|
|
+
|
|
|
updateTitle: (state, action: PayloadAction<{ title: string }>) => {
|
|
|
state.title = action.payload.title;
|
|
|
},
|
|
|
|
|
|
- addField: (state, action: PayloadAction<{ field: IDatabaseField }>) => {
|
|
|
+ /*addField: (state, action: PayloadAction<{ field: IDatabaseField }>) => {
|
|
|
const { field } = action.payload;
|
|
|
|
|
|
state.fields[field.fieldId] = field;
|
|
@@ -253,7 +102,7 @@ export const databaseSlice = createSlice({
|
|
|
cells[field.fieldId] = {
|
|
|
rowId: r.rowId,
|
|
|
fieldId: field.fieldId,
|
|
|
- data: '',
|
|
|
+ data: [''],
|
|
|
cellId: nanoid(6),
|
|
|
};
|
|
|
return {
|
|
@@ -261,15 +110,15 @@ export const databaseSlice = createSlice({
|
|
|
cells: cells,
|
|
|
};
|
|
|
});
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
- updateField: (state, action: PayloadAction<{ field: IDatabaseField }>) => {
|
|
|
+ /*updateField: (state, action: PayloadAction<{ field: IDatabaseField }>) => {
|
|
|
const { field } = action.payload;
|
|
|
|
|
|
state.fields[field.fieldId] = field;
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
- addFieldSelectOption: (state, action: PayloadAction<{ fieldId: string; option: ISelectOption }>) => {
|
|
|
+ /*addFieldSelectOption: (state, action: PayloadAction<{ fieldId: string; option: ISelectOption }>) => {
|
|
|
const { fieldId, option } = action.payload;
|
|
|
|
|
|
const field = state.fields[fieldId];
|
|
@@ -283,9 +132,9 @@ export const databaseSlice = createSlice({
|
|
|
selectOptions: [option],
|
|
|
};
|
|
|
}
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
- updateFieldSelectOption: (state, action: PayloadAction<{ fieldId: string; option: ISelectOption }>) => {
|
|
|
+ /*updateFieldSelectOption: (state, action: PayloadAction<{ fieldId: string; option: ISelectOption }>) => {
|
|
|
const { fieldId, option } = action.payload;
|
|
|
|
|
|
const field = state.fields[fieldId];
|
|
@@ -293,16 +142,16 @@ export const databaseSlice = createSlice({
|
|
|
if (selectOptions) {
|
|
|
selectOptions[selectOptions.findIndex((o) => o.selectOptionId === option.selectOptionId)] = option;
|
|
|
}
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
- addRow: (state) => {
|
|
|
+ /*addRow: (state) => {
|
|
|
const rowId = nanoid(6);
|
|
|
const cells: { [keys: string]: ICellData } = {};
|
|
|
Object.keys(state.fields).forEach((id) => {
|
|
|
cells[id] = {
|
|
|
rowId: rowId,
|
|
|
fieldId: id,
|
|
|
- data: '',
|
|
|
+ data: [''],
|
|
|
cellId: nanoid(6),
|
|
|
};
|
|
|
});
|
|
@@ -312,15 +161,15 @@ export const databaseSlice = createSlice({
|
|
|
};
|
|
|
|
|
|
state.rows.push(newRow);
|
|
|
- },
|
|
|
+ },*/
|
|
|
|
|
|
- updateCellValue: (source, action: PayloadAction<{ cell: ICellData }>) => {
|
|
|
+ /*updateCellValue: (source, action: PayloadAction<{ cell: ICellData }>) => {
|
|
|
const { cell } = action.payload;
|
|
|
const row = source.rows.find((r) => r.rowId === cell.rowId);
|
|
|
if (row) {
|
|
|
row.cells[cell.fieldId] = cell;
|
|
|
}
|
|
|
- },
|
|
|
+ },*/
|
|
|
},
|
|
|
});
|
|
|
|