Merge pull request #840 from colouring-cities/copy-tool-enable

Enable copy tool for all fields
This commit is contained in:
Ed Chalstrey 2022-06-24 16:01:46 +01:00 committed by GitHub
commit 8fad7cead9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 9 deletions

View File

@ -16,7 +16,7 @@ interface MultiDataEntryProps extends BaseDataEntryProps, TextDataEntryInputProp
export const MultiDataEntry: React.FC<MultiDataEntryProps> = ({
editableEntries = false,
copyable = false,
copyable = true,
confirmOnEnter = true,
...props
}) => {

View File

@ -17,6 +17,7 @@ import { CopyControl } from './header-buttons/copy-control';
import { ViewEditControl } from './header-buttons/view-edit-control';
import './data-container.css';
import { dataFields } from '../config/data-fields-config'
interface DataContainerProps {
title: string;
@ -80,11 +81,31 @@ const withCopyEdit: (wc: React.ComponentType<CategoryViewProps>) => DataContaine
static getDerivedStateFromProps(props, state): DataContainerState {
const newBuildingId = props.building == undefined ? undefined : props.building.building_id;
const newBuildingRevisionId = props.building == undefined ? undefined : props.building.revision_id;
const categoryKeys = {};
const blackListedKeys = ['current_landuse_order',
'current_landuse_verified',
'planning_in_list',
'planning_list_id',
'planning_list_cat',
'planning_list_grade',
'likes_total',
'community_local_significance_total'
]
for (let key in dataFields) {
let fieldName = props.building == undefined ? undefined : props.building[key];
if (dataFields[key].category == props.cat && fieldName != null && !blackListedKeys.includes(key)){
categoryKeys[key] = true;
}
if (props.cat == 'team' && key == 'date_year' && fieldName != null && !blackListedKeys.includes(key)){
categoryKeys[key] = true;
}
}
if(newBuildingId !== state.currentBuildingId || newBuildingRevisionId > state.currentBuildingRevisionId) {
return {
error: undefined,
copying: false,
keys_to_copy: {},
keys_to_copy: categoryKeys,
buildingEdits: {},
currentBuildingId: newBuildingId,
currentBuildingRevisionId: newBuildingRevisionId

View File

@ -7,12 +7,26 @@ interface CopyProps {
copyingKey: (key: string) => boolean;
}
function initCopyProps(options?: Partial<CopyProps>): CopyProps {
const defaults = {
copying: true,
toggleCopying: undefined
};
return {
...defaults,
...options,
};
}
const defaultCopyProps: CopyProps = initCopyProps();
interface CategoryViewProps {
intro: string;
building: Building;
mode: 'view' | 'edit' | 'multi-edit';
edited: boolean;
copy: CopyProps;
copy: defaultCopyProps;
onChange: (key: string, value: any) => void;
onVerify: (slug: string, verify: boolean, x: number, y: number) => void;

View File

@ -36,6 +36,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
onChange={props.onSaveChange}
mode={props.mode}
copy={props.copy}
/>
<LogicalDataEntry
slug='community_type_worth_keeping'
@ -47,7 +48,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
onChange={props.onSaveChange}
mode={props.mode}
copy={props.copy}
/>
{
props.building.community_type_worth_keeping !== false &&
@ -64,6 +65,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
label: definition.title
}))
}
mode={props.mode}
/>
}
@ -87,7 +89,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
title={dataFields.community_activities_current.title}
tooltip={dataFields.community_activities_current.tooltip}
value={props.building.community_activities_current}
copy={props.copy}
onChange={props.onChange}
mode={props.mode}
/>
@ -96,7 +98,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
title={dataFields.community_activities.title}
tooltip={dataFields.community_activities.tooltip}
value={props.building.community_activities}
copy={props.copy}
onChange={props.onChange}
mode={props.mode}
/>
@ -105,7 +107,7 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
title={dataFields.community_activities_always.title}
tooltip={dataFields.community_activities_always.tooltip}
value={props.building.community_activities_always}
copy={props.copy}
onChange={props.onChange}
mode={props.mode}
/>
@ -150,10 +152,10 @@ const CommunityView: React.FunctionComponent<CategoryViewProps> = (props) => {
isUrl={true}
placeholder={'https://...'}
editableEntries={true}
value={props.building.community_public_ownership_sources}
onChange={props.onChange}
mode={props.mode}
copy={props.copy}
/>
<Verification
slug="community_public_ownership_sources"

View File

@ -47,6 +47,7 @@ const TeamView: React.FunctionComponent<CategoryViewProps> = (props) => {
slug="has_extension"
value={props.building.has_extension}
mode={props.mode}
copy={props.copy}
onChange={props.onChange}
tooltip={dataFields.has_extension.tooltip}
/>
@ -189,7 +190,7 @@ const TeamView: React.FunctionComponent<CategoryViewProps> = (props) => {
title={dataFields.designer_awards.title}
tooltip={dataFields.designer_awards.tooltip}
value={props.building.designer_awards}
copy={props.copy}
onChange={props.onChange}
mode={props.mode}
/>