Skip to content

Commit

Permalink
4001 - Datatable Use Datagrid - Hide taxon DropdownIndicator, Vertica…
Browse files Browse the repository at this point in the history
…lly center input disabled & Cache fix (#4193)

* 4001 - Hide Taxon DropdownIndicator

* 4001 - Vertically center disabled input cells

* 4001 - Generate data cache only for affected tables

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
yaguzmang and mergify[bot] authored Jan 2, 2025
1 parent a064006 commit 3c51c4b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/client/components/Inputs/Select/hooks/useComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { SelectProps } from 'client/components/Inputs/Select/types'
type Returned = ReactSelectProps['components']

export const useComponents = (props: SelectProps): Returned => {
const { collapsibleGroups, inputHidden, isMulti, multiLabelSummaryKey, selectableGroups } = props
const { collapsibleGroups, hideDropdownIndicator, inputHidden, isMulti, multiLabelSummaryKey, selectableGroups } =
props

return useMemo<Returned>(() => {
const components: Returned = {
Expand All @@ -41,7 +42,8 @@ export const useComponents = (props: SelectProps): Returned => {
return <originalComponents.Input {...originalInputProps} isHidden={inputHidden} />
}
}
if (hideDropdownIndicator) components.DropdownIndicator = null

return components
}, [collapsibleGroups, inputHidden, isMulti, multiLabelSummaryKey, selectableGroups])
}, [collapsibleGroups, hideDropdownIndicator, inputHidden, isMulti, multiLabelSummaryKey, selectableGroups])
}
1 change: 1 addition & 0 deletions src/client/components/Inputs/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type SelectProps = SelectBaseProps &
collapsibleGroups?: boolean
createOptionLabelKey?: string
disabled?: boolean
hideDropdownIndicator?: boolean
inputHidden?: boolean
isCreatable?: boolean
multiLabelSummaryKey?: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.table-grid__data-cell-input-number {
text-align: right;

&.input-text {
&.disabled {
align-items: center;
display: flex;
justify-content: end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Taxon: React.FC<PropsCell> = (props: PropsCell) => {
createOptionLabelKey="common.add"
createOptionPosition="first"
disabled={disabled}
hideDropdownIndicator
inputHidden={false}
inputValue={!disabled ? inputValue : null}
isClearable={false}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.table-grid__data-cell-input-text {
&.input-text {
&.disabled {
align-items: center;
display: flex;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './Text.scss'
import React from 'react'
import { useTranslation } from 'react-i18next'

Expand All @@ -19,6 +20,7 @@ const Text: React.FC<PropsCell> = (props) => {

return (
<Component
className="table-grid__data-cell-input-text"
disabled={disabled}
onChange={onChange}
onPaste={onPaste}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Objects } from 'utils/objects'
import { Promises } from 'utils/promises'

import { CountryIso } from 'meta/area'
import { AssessmentNames } from 'meta/assessment'

import { AssessmentController } from 'server/controller/assessment'
import { BaseProtocol, Schemas } from 'server/db'
import { DataRedisRepository } from 'server/repository/redis/data'
import { Logger } from 'server/utils/logger'

type TableInfo = {
cycleUuid: string
Expand Down Expand Up @@ -661,40 +667,61 @@ const _fixFraTaxonCodes = async (client: BaseProtocol) => {

const schemaAssessment = Schemas.getName(assessment)

/* eslint-disable no-useless-escape */
await Promise.all(
cycles.map((cycle) => {
cycles.map(async (cycle) => {
const schemaCycle = Schemas.getNameCycle(assessment, cycle)
return client.query(`
const updatedTables = await client.map<{ countryIso: CountryIso; tableName: string }>(
`
with nodes_to_update as (
select
n.id,
n.value,
n.country_iso,
tb.props->>'name' as table_name,
t.code as matching_taxon_code,
t.scientific_name as original_scientific_name
from ${schemaCycle}.node n
join ext_data.taxon t
on lower(trim(both ' ' from regexp_replace(n.value->>'raw', '\s+', ' ', 'g'))) = lower(t.scientific_name)
on lower(trim(both ' ' from regexp_replace(n.value->>'raw', '\\s+', ' ', 'g'))) = lower(t.scientific_name)
join ${schemaAssessment}.col c
on c.uuid = n.col_uuid and c.props->>'colType' = 'taxon'
join ${schemaAssessment}.row r
on c.row_id = r.id
join ${schemaAssessment}."table" tb
on tb.id = r.table_id
where n.value->>'taxonCode' is null
),
updated_values as (
select
id,
country_iso,
table_name,
jsonb_set(
jsonb_set(value, '{taxonCode}', to_jsonb(matching_taxon_code::text), true),
'{raw}',
to_jsonb(original_scientific_name),
true
) as new_value
from nodes_to_update
),
updated_tables as (
update ${schemaCycle}.node
set value = updated_values.new_value
from updated_values
where ${schemaCycle}.node.id = updated_values.id
returning updated_values.country_iso, updated_values.table_name
)
update ${schemaCycle}.node
set value = updated_values.new_value
from updated_values
where ${schemaCycle}.node.id = updated_values.id;
`)
select distinct country_iso, table_name from updated_tables;
`,
[],
(res) => Objects.camelize(res)
)

await Promises.each(updatedTables, ({ countryIso, tableName }) =>
DataRedisRepository.cacheCountryTable({ assessment, countryIso, cycle, force: true, tableName }, client)
)

Logger.info(`Generated cache for ${updatedTables.length} tables in ${schemaCycle}.`)
})
)
}
Expand Down Expand Up @@ -778,14 +805,6 @@ export default async (client: BaseProtocol) => {
await Promise.all(
assessments.map(async (assessment) => {
await AssessmentController.generateMetadataCache({ assessment }, client)

if (assessment.props.name === AssessmentNames.fra) {
await Promise.all(
assessment.cycles.map(async (cycle) => {
await AssessmentController.generateDataCache({ assessment, cycle }, client)
})
)
}
})
)
}

0 comments on commit 3c51c4b

Please sign in to comment.