Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/map
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 18, 2023
2 parents 6a8c4e5 + 41a2415 commit 8dd7cf0
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 63 deletions.
5 changes: 5 additions & 0 deletions core/survey/_survey/surveyInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const keys = {
published: ObjectUtils.keys.published,
authGroups: 'authGroups',
props: ObjectUtils.keys.props,
rdbInitialized: 'rdbInitialized',
// Props
collectUri: 'collectUri',
collectReport: 'collectReport',
Expand Down Expand Up @@ -52,6 +53,8 @@ export const status = {

export const getInfo = (survey) => (survey.info ? survey.info : survey) // backwards compatibility: survey info were associated to 'info' prop

export const isRdbInitialized = R.propOr(false, keys.rdbInitialized)

// ====== READ surveyInfo
export const { getId, getUuid, getProps, getPropsDraft, isPublished, getDescription, getDescriptions, getLabels } =
ObjectUtils
Expand Down Expand Up @@ -156,6 +159,8 @@ export const markDraft = R.assoc(keys.draft, true)

export const assocSrs = (srs) => ObjectUtils.setProp(keys.srs, srs)

export const assocRDBInitilized = R.assoc(keys.rdbInitialized)

// ====== UTILS

export const isValid = (surveyInfo) => surveyInfo && surveyInfo.id
Expand Down
4 changes: 3 additions & 1 deletion core/survey/nodeDefLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ export const getLayoutChildrenCompressed =
: // item in another row, can have the same x of the previous one
Math.min(itemPrev.x, xOriginal)

const prevYDiff = itemPrev.yOriginal - itemPrev.y

const y = sameRowOfPreviousItem
? // item can have the same y of the previous one
Math.min(itemPrev.y, yOriginal)
yOriginal - prevYDiff
: // item in another row, move it yPrev + hPrev
Math.min(itemPrev.y + itemPrev.h, yOriginal)

Expand Down
4 changes: 3 additions & 1 deletion core/survey/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const {
isDraft,
isValid,
isFromCollect,
isRdbInitialized,
getCollectUri,
getCollectReport,
getCollectNodeDefsInfoByPath,
Expand All @@ -135,7 +136,7 @@ export const {
export const { getAuthGroupByName, getAuthGroups, isAuthGroupAdmin, getAuthGroupAdmin } = SurveyInfo

// UPDATE
export const { assocAuthGroups, assocSrs, markDraft } = SurveyInfo
export const { assocAuthGroups, assocRDBInitilized, assocSrs, markDraft } = SurveyInfo

// ====== READ nodeDefs
export const {
Expand All @@ -149,6 +150,7 @@ export const {
getNodeDefChildren,
getNodeDefChildrenInOwnPage,
hasNodeDefChildrenEntities,
getNodeDefChildrenSorted,
getNodeDefChildByName,
getNodeDefSiblingByName,
getNodeDefByName,
Expand Down
45 changes: 22 additions & 23 deletions server/modules/nodeDef/repository/nodeDefRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ export const insertNodeDef = async (surveyId, nodeDef, client = DB) =>
(row) => dbTransformCallback({ row, draft: true, advanced: true }) // Always loading draft when creating or updating a nodeDef
)

export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) =>
client.tx(async (tx) => {
const schema = getSurveyDBSchema(surveyId)
await tx.batch([
nodeDefs.map((nodeDef) =>
tx.none(
`
export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => {
const schema = getSurveyDBSchema(surveyId)
return client.batch([
nodeDefs.map((nodeDef) =>
client.none(
`
INSERT INTO ${schema}.node_def (
parent_uuid,
uuid,
Expand All @@ -93,22 +92,22 @@ export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }
$4::jsonb, $5::jsonb,
$6::jsonb, $7::jsonb,
$8,$9,$10)`,
[
NodeDef.getParentUuid(nodeDef),
nodeDef.uuid,
NodeDef.getType(nodeDef),
backup ? NodeDef.getProps(nodeDef) : {},
backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef),
backup ? NodeDef.getPropsAdvanced(nodeDef) : {},
backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef),
NodeDef.getMeta(nodeDef),
NodeDef.isAnalysis(nodeDef),
NodeDef.isVirtual(nodeDef),
]
)
),
])
})
[
NodeDef.getParentUuid(nodeDef),
nodeDef.uuid,
NodeDef.getType(nodeDef),
backup ? NodeDef.getProps(nodeDef) : {},
backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef),
backup ? NodeDef.getPropsAdvanced(nodeDef) : {},
backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef),
NodeDef.getMeta(nodeDef),
NodeDef.isAnalysis(nodeDef),
NodeDef.isVirtual(nodeDef),
]
)
),
])
}

// ============== READ

Expand Down
17 changes: 14 additions & 3 deletions server/modules/survey/manager/surveyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as User from '@core/user/user'
import * as ObjectUtils from '@core/objectUtils'
import * as Validation from '@core/validation/validation'
import * as PromiseUtils from '@core/promiseUtils'
import SystemError from '@core/systemError'

import { db } from '@server/db/db'
import { DBMigrator } from '@openforis/arena-server'
Expand All @@ -32,7 +33,6 @@ import * as UserManager from '@server/modules/user/manager/userManager'
import * as UserRepository from '@server/modules/user/repository/userRepository'
import * as SurveyRepositoryUtils from '../repository/surveySchemaRepositoryUtils'
import * as SurveyRepository from '../repository/surveyRepository'
import SystemError from '@core/systemError'

const assocSurveyInfo = (survey) => survey

Expand All @@ -44,6 +44,17 @@ const _fetchAndAssocSrss = async ({ surveyInfo }, client) => {
return Survey.assocSrs(srss)(surveyInfo)
}

const _fetchAndAssocRdbInitialized = async ({ surveyInfo }, client) => {
const surveyId = Survey.getId(surveyInfo)
const rdbInitialized = await SchemaRdbRepository.selectSchemaExists(surveyId, client)
return Survey.assocRDBInitilized(rdbInitialized)(surveyInfo)
}

const _fetchAndAssocAdditionalInfo = async ({ surveyInfo }, client) => {
let surveyInfoUpdated = await _fetchAndAssocSrss({ surveyInfo }, client)
return _fetchAndAssocRdbInitialized({ surveyInfo: surveyInfoUpdated }, client)
}

// ====== VALIDATION

export const validateNewSurvey = async ({ newSurvey }) => {
Expand Down Expand Up @@ -168,7 +179,7 @@ export const importSurvey = async (params, client = db) => {
surveyInfo
)

surveyInfo = await _fetchAndAssocSrss({ surveyInfo }, t)
surveyInfo = await _fetchAndAssocAdditionalInfo({ surveyInfo }, t)

await _addUserToSurveyAdmins({ user, surveyInfo }, t)

Expand All @@ -193,7 +204,7 @@ export const fetchSurveyById = async ({ surveyId, draft = false, validate = fals
])

let surveyInfoUpdated = Survey.assocAuthGroups(authGroups)(surveyInfo)
surveyInfoUpdated = await _fetchAndAssocSrss({ surveyInfo: surveyInfoUpdated }, client)
surveyInfoUpdated = await _fetchAndAssocAdditionalInfo({ surveyInfo: surveyInfoUpdated }, client)

const validation = validate ? await validateSurveyInfo(surveyInfoUpdated) : null

Expand Down
18 changes: 15 additions & 3 deletions server/modules/surveyRdb/repository/schemaRdbRepository.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import * as SchemaRdb from '@common/surveyRdb/schemaRdb'
import { Schemata } from '@common/model/db'

import { db } from '@server/db/db'

export const dropSchema = async (surveyId, client = db) =>
client.query(`DROP SCHEMA IF EXISTS ${SchemaRdb.getName(surveyId)} CASCADE`)
client.query(`DROP SCHEMA IF EXISTS ${Schemata.getSchemaSurveyRdb(surveyId)} CASCADE`)

export const createSchema = async (surveyId, client = db) =>
client.query(`CREATE SCHEMA ${SchemaRdb.getName(surveyId)}`)
client.query(`CREATE SCHEMA ${Schemata.getSchemaSurveyRdb(surveyId)}`)

export const selectSchemaExists = async (surveyId, client = db) => {
const result = await client.one(
`
SELECT COUNT(*) = 1 AS res
FROM information_schema.schemata
WHERE schema_name = $1
`,
[Schemata.getSchemaSurveyRdb(surveyId)]
)
return result.res
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const VisibleColumnsMenu = (props) => {

return (
<ButtonMenu
className="btn-s"
closeMenuOnItemClick={false}
iconClassName="icon-cog"
items={availableColumns.map((column) => {
Expand Down
9 changes: 3 additions & 6 deletions webapp/components/expression/expressionEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import PropTypes from 'prop-types'
import * as R from 'ramda'

import * as Expression from '@core/expressionParser/expression'
import * as Survey from '@core/survey/survey'
import * as NodeDef from '@core/survey/nodeDef'
import { TestId } from '@webapp/utils/testId'
import { useI18n } from '@webapp/store/system'

import ExpressionEditorPopup from './expressionEditorPopup'
import { ExpressionEditorType } from './expressionEditorType'
import { useSurvey, useSurveyPreferredLang } from '@webapp/store/survey'
import { useNodeDefByUuid } from '@webapp/store/survey'
import { Button } from '../buttons'

const ExpressionEditor = (props) => {
Expand All @@ -33,8 +32,7 @@ const ExpressionEditor = (props) => {
} = props

const i18n = useI18n()
const survey = useSurvey()
const lang = useSurveyPreferredLang()
const nodeDefCurrent = useNodeDefByUuid(nodeDefUuidCurrent)

const [edit, setEdit] = useState(false)

Expand All @@ -54,11 +52,10 @@ const ExpressionEditor = (props) => {
const idPrefix = `expression-editor-${placeholder ? 'placeholder' : index}-${qualifier}`

const qualifierLabel = i18n.t(`expressionEditor.qualifier.${qualifier}`)
const nodeDefCurrent = Survey.getNodeDefByUuid(nodeDefUuidCurrent)(survey)
const popupHeader = nodeDefCurrent
? i18n.t('expressionEditor.header.editingExpressionForNodeDefinition', {
qualifier: qualifierLabel,
nodeDef: NodeDef.getLabel(nodeDefCurrent, lang),
nodeDef: NodeDef.getName(nodeDefCurrent),
})
: null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const SurveyDefsLoader = (props) => {
return null
}

if (!requirePublish || Survey.isPublished(surveyInfo) || Survey.isFromCollect(surveyInfo)) {
if (
!requirePublish ||
Survey.isPublished(surveyInfo) ||
(Survey.isFromCollect(surveyInfo) && Survey.isRdbInitialized(surveyInfo))
) {
return children
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './nodeDefEntitySwitch.scss'

import React from 'react'

import * as A from '@core/arena'
import * as Survey from '@core/survey/survey'
import * as NodeDef from '@core/survey/nodeDef'
import * as NodeDefLayout from '@core/survey/nodeDefLayout'
Expand All @@ -20,20 +19,20 @@ const componentsByRenderType = {
const NodeDefEntitySwitch = (props) => {
const { surveyCycleKey, nodeDef } = props

const survey = useSurvey()

const renderType = NodeDefLayout.getRenderType(surveyCycleKey)(nodeDef)
if (!renderType) {
// node def not in current cycle
return null
}

const survey = useSurvey()

const includeAnalysis = false
const childDefs = Survey.getNodeDefChildren(props.nodeDef, includeAnalysis)(survey)
const childDefs = Survey.getNodeDefChildrenSorted({ nodeDef, includeAnalysis, cycle: surveyCycleKey })(survey)

const nodeDefName = NodeDef.getName(nodeDef)
const childUuids = NodeDefLayout.getLayoutChildrenUuids(surveyCycleKey)(nodeDef)
const childNames = childUuids.map((childUuid) => A.pipe(Survey.getNodeDefByUuid(childUuid), NodeDef.getName)(survey))
const childNames = Survey.getNodeDefsByUuids(childUuids)(survey).map(NodeDef.getName)

return (
<div
Expand Down
4 changes: 1 addition & 3 deletions webapp/style/table.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import 'webapp/style/vars';

$tableHeaderHeight: 30px;
$tableHeaderHeight: 40px;
$tableFooterHeight: 30px;

.table {
Expand All @@ -10,7 +10,6 @@ $tableFooterHeight: 30px;
}

.table__header {
height: $tableHeaderHeight;
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -25,7 +24,6 @@ $tableFooterHeight: 30px;
}

.table__footer {
height: $tableFooterHeight;
display: flex;
justify-content: flex-end;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const HeaderLeft = ({ handleSearch, navigateToRecord, onRecordsUpdate, search, s
<Button
testId={TestId.records.addBtn}
onClick={() => dispatch(RecordActions.createRecord(navigate))}
className="btn-s"
iconClassName="icon-plus icon-12px icon-left"
label="common.new"
/>
Expand Down
20 changes: 13 additions & 7 deletions webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
@import 'webapp/style/vars';

$tableHeaderHeight: 40px;
$tableHeaderHeight: 30px;

.records__header-left {
display: flex;
align-items: center;
height: $tableHeaderHeight;
column-gap: 1rem;
}

.records__header-left__input-search {
padding: 0px 5px;
border: 1px solid $greyBorder;
background: white;
width: 15rem;
button,
.btn {
padding: 0.5rem 0.8rem;
}

.records__header-left__input-search {
padding: 5px 5px;
border: 1px solid $greyBorder;
background: white;
width: 15rem;
}
}
5 changes: 5 additions & 0 deletions webapp/views/App/views/Data/Records/Records.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useSurveyCycleKey, useNodeDefRootKeys } from '@webapp/store/survey'
import { appModuleUri, dataModules } from '@webapp/app/appModules'

import Table from '@webapp/components/Table'
import { LoadingBar } from '@webapp/components'
import { useOnWebSocketEvent } from '@webapp/components/hooks'

import HeaderLeft from './HeaderLeft'
Expand Down Expand Up @@ -44,6 +45,10 @@ const Records = () => {
eventHandler: onRecordsUpdate,
})

if (columns === null) {
return <LoadingBar />
}

return (
<Table
visibleColumnsSelectionEnabled
Expand Down
Loading

0 comments on commit 8dd7cf0

Please sign in to comment.