mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
Fixed project tab crashing, made project writing work; fixed cache invalidation
This commit is contained in:
@@ -9,7 +9,7 @@ import { write } from './write/write'
|
||||
|
||||
export const getAllLocalities = async (onlyPublic: boolean) => {
|
||||
const where = onlyPublic ? { loc_status: false } : {}
|
||||
console.log('moi')
|
||||
|
||||
const result = await nowDb.now_loc.findMany({
|
||||
select: {
|
||||
lid: true,
|
||||
|
||||
@@ -88,7 +88,7 @@ allowedFields['now_bau'] = false
|
||||
|
||||
const dbName = 'now_test'
|
||||
|
||||
export const write: WriteFunction = async (data, tableName, oldObject) => {
|
||||
export const write: WriteFunction = async (data, tableName) => {
|
||||
debugLog('Write')
|
||||
const writeList: WriteItem[] = []
|
||||
const conn = await pool.getConnection()
|
||||
@@ -129,7 +129,6 @@ export const write: WriteFunction = async (data, tableName, oldObject) => {
|
||||
const newId = await writeTable(obj[objectField], objectField)
|
||||
relationIds[ids[objectField][1]] = newId
|
||||
debugLog(`Processed objectField ${objectField} and assigned id ${newId} to ${ids[objectField][1]}`)
|
||||
debugLog(`}`)
|
||||
}
|
||||
basicFields.push(...Object.keys(relationIds))
|
||||
debugLog(`basicFields: ${printJSON(basicFields)}`)
|
||||
@@ -216,3 +215,23 @@ export const write: WriteFunction = async (data, tableName, oldObject) => {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const test = async () => {
|
||||
console.log('testing')
|
||||
await sleep(4000)
|
||||
await write(
|
||||
{
|
||||
loc_name: 'newnewnew',
|
||||
date_meth: 'absolute',
|
||||
max_age: 123,
|
||||
min_age: 123,
|
||||
dec_lat: 1,
|
||||
dec_long: 1,
|
||||
hominin_skeletal_remains: true,
|
||||
bipedal_footprints: true,
|
||||
stone_tool_technology: true,
|
||||
stone_tool_cut_marks_on_bones: true,
|
||||
},
|
||||
'now_loc'
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Box, CircularProgress } from '@mui/material'
|
||||
import { MRT_ColumnDef } from 'material-react-table'
|
||||
|
||||
export const ProjectTab = () => {
|
||||
const { mode } = useDetailContext<LocalityDetailsType>()
|
||||
const { mode, editData, setEditData } = useDetailContext<LocalityDetailsType>()
|
||||
const { data: projectData, isError } = useGetAllProjectsQuery()
|
||||
|
||||
if (isError) return 'Error loading Projects.'
|
||||
@@ -32,10 +32,10 @@ export const ProjectTab = () => {
|
||||
accessorKey: 'proj_status',
|
||||
header: 'Status',
|
||||
},
|
||||
{
|
||||
/* {
|
||||
accessorFn: ({ proj_records }) => (proj_records ? 'Public' : 'Private'),
|
||||
header: 'Records',
|
||||
},
|
||||
}, */
|
||||
]
|
||||
|
||||
return (
|
||||
@@ -46,12 +46,24 @@ export const ProjectTab = () => {
|
||||
buttonText="Select Project"
|
||||
data={projectData}
|
||||
columns={columns}
|
||||
fieldName="projects"
|
||||
idFieldName="pid"
|
||||
fieldName="now_plr"
|
||||
editingAction={(newProject: Project) => {
|
||||
setEditData({
|
||||
...editData,
|
||||
now_plr: [
|
||||
...editData.now_plr,
|
||||
{ lid: editData.lid, pid: newProject.pid, now_proj: newProject, rowState: 'new' },
|
||||
],
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
<EditableTable<Editable<Project>, LocalityDetailsType> columns={columns} field="projects" />
|
||||
<EditableTable<Editable<Project>, LocalityDetailsType>
|
||||
columns={columns.map(c => ({ ...c, accessorKey: `now_proj.${c.accessorKey}` }))}
|
||||
field="now_plr"
|
||||
/>
|
||||
</Grouped>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RootState } from './store'
|
||||
|
||||
export const api = createApi({
|
||||
reducerPath: 'api',
|
||||
tagTypes: ['user', 'localities', 'species', 'references', 'timeunits', 'locality'],
|
||||
tagTypes: ['user', 'localities', 'species', 'references', 'timeunits', 'timeunit', 'locality'],
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: BACKEND_URL,
|
||||
prepareHeaders: (headers, { getState }) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ const localitiesApi = api.injectEndpoints({
|
||||
query: () => ({
|
||||
url: `/locality/all`,
|
||||
}),
|
||||
providesTags: result => (result ? [{ type: 'localities' }] : []),
|
||||
}),
|
||||
getLocalityDetails: builder.query<LocalityDetailsType, string>({
|
||||
query: id => ({
|
||||
@@ -20,7 +21,7 @@ const localitiesApi = api.injectEndpoints({
|
||||
method: 'PUT',
|
||||
body: { locality },
|
||||
}),
|
||||
invalidatesTags: (result, _error, { lid }) => (result ? [{ type: 'locality', id: lid }] : []),
|
||||
invalidatesTags: (result, _error, { lid }) => (result ? [{ type: 'locality', id: lid }, 'localities'] : []),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -7,11 +7,13 @@ const timeunitsApi = api.injectEndpoints({
|
||||
query: () => ({
|
||||
url: `/time-unit/all`,
|
||||
}),
|
||||
providesTags: result => (result ? [{ type: 'timeunits' }] : []),
|
||||
}),
|
||||
getTimeUnitDetails: builder.query<TimeUnitDetailsType, string>({
|
||||
query: id => ({
|
||||
url: `/time-unit/${id}`,
|
||||
}),
|
||||
providesTags: result => (result ? [{ type: 'timeunit', id: result.tu_name }] : []),
|
||||
}),
|
||||
getTimeUnitLocalities: builder.query<Locality[], string>({
|
||||
query: id => ({
|
||||
@@ -24,7 +26,8 @@ const timeunitsApi = api.injectEndpoints({
|
||||
method: 'PUT',
|
||||
body: { timeUnit },
|
||||
}),
|
||||
invalidatesTags: (result, _error, { tu_name }) => (result ? [{ type: 'timeunits', id: tu_name }] : []),
|
||||
invalidatesTags: (result, _error, { tu_name }) =>
|
||||
result ? [{ type: 'timeunit', id: tu_name }, 'timeunits'] : [],
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user