Skip to content

Commit

Permalink
Merge pull request #244 from performant-software/feature/cdc60_data_e…
Browse files Browse the repository at this point in the history
…ntry_form

CDC #60 - Data Entry Form
  • Loading branch information
dleadbetter authored Jan 9, 2024
2 parents ca7f49f + d8cc222 commit 104607c
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 44 deletions.
6 changes: 3 additions & 3 deletions packages/controlled-vocabulary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/controlled-vocabulary",
"version": "1.1.0",
"version": "1.1.1",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,8 +12,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^1.1.0",
"@performant-software/shared-components": "^1.1.0",
"@performant-software/semantic-components": "^1.1.1",
"@performant-software/shared-components": "^1.1.1",
"i18next": "^21.9.2",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/geospatial/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/geospatial",
"version": "1.1.0",
"version": "1.1.1",
"description": "TODO: ADD",
"license": "MIT",
"main": "./build/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/semantic-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/semantic-components",
"version": "1.1.0",
"version": "1.1.1",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,7 +12,7 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/shared-components": "^1.1.0",
"@performant-software/shared-components": "^1.1.1",
"@react-google-maps/api": "^2.8.1",
"axios": "^0.26.1",
"i18next": "^19.4.4",
Expand Down
74 changes: 50 additions & 24 deletions packages/semantic-ui/src/components/AssociatedDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import { Timer } from '@performant-software/shared-components';
import React, { Component, type ComponentType } from 'react';
import { Button, Dropdown, Message } from 'semantic-ui-react';
import {
Button,
Dropdown,
Message,
type ButtonProps
} from 'semantic-ui-react';
import _ from 'underscore';
import EditModal from './EditModal';
import i18n from '../i18n/i18n';
Expand All @@ -16,6 +21,7 @@ type Option = {
};

type Props = {
buttons?: Array<ButtonProps>,
className?: string,
collectionName: string,
header?: ComponentType<any>,
Expand Down Expand Up @@ -45,6 +51,10 @@ type State = {
value: ?number | ?string
};

const BUTTON_ADD = 'add';
const BUTTON_CLEAR = 'clear';
const BUTTON_EDIT = 'edit';

const TIMEOUT = 500;

class AssociatedDropdown extends Component<Props, State> {
Expand Down Expand Up @@ -243,13 +253,33 @@ class AssociatedDropdown extends Component<Props, State> {
return null;
}

return this.renderButton(BUTTON_ADD, {
basic: true,
content: i18n.t('Common.buttons.add'),
icon: 'plus',
onClick: () => this.setState({ modalAdd: true }),
type: 'button'
});
}

/**
* Renders the button with the passed name using the provided props.
*
* @param name
* @param defaults
*
* @returns {JSX.Element|null}
*/
renderButton(name, defaults) {
const button = _.findWhere(this.props.buttons, { name }) || {};

if (button.accept && !button.accept()) {
return null;
}

return (
<Button
basic
content={i18n.t('Common.buttons.add')}
icon='plus'
onClick={() => this.setState({ modalAdd: true })}
type='button'
{..._.defaults(button, defaults)}
/>
);
}
Expand All @@ -264,15 +294,13 @@ class AssociatedDropdown extends Component<Props, State> {
return null;
}

return (
<Button
basic
content={i18n.t('Common.buttons.clear')}
icon='times'
onClick={this.onClear.bind(this)}
type='button'
/>
);
return this.renderButton(BUTTON_CLEAR, {
basic: true,
content: i18n.t('Common.buttons.clear'),
icon: 'times',
onClick: this.onClear.bind(this),
type: 'button'
});
}

/**
Expand All @@ -285,15 +313,13 @@ class AssociatedDropdown extends Component<Props, State> {
return null;
}

return (
<Button
basic
content={i18n.t('Common.buttons.edit')}
icon='pencil'
onClick={() => this.setState({ modalEdit: true })}
type='button'
/>
);
return this.renderButton(BUTTON_EDIT, {
basic: true,
content: i18n.t('Common.buttons.edit'),
icon: 'pencil',
onClick: () => this.setState({ modalEdit: true }),
type: 'button'
});
}

/**
Expand Down
11 changes: 9 additions & 2 deletions packages/semantic-ui/src/components/DataTableColumnSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ type Props = ListProps & {
* If a <code>render</code> callback is provided, the item will be passed to the function and the return JSX
* will display as the property value.
*/
columns: Array<Column>
columns: Array<Column>,

/**
* If <code>true</code>, columns can be shown/hidden by the user.
*/
configurable?: boolean
};

type State = {
Expand Down Expand Up @@ -139,7 +144,9 @@ const useColumnSelector = (WrappedComponent: ComponentType<any>) => (
{...this.props}
className={`data-table-column-selector ${this.props.className}`}
columns={this.state.columns}
renderListHeader={this.renderHeader.bind(this)}
renderListHeader={this.props.configurable
? this.renderHeader.bind(this)
: undefined}
/>
);
}
Expand Down
11 changes: 10 additions & 1 deletion packages/semantic-ui/src/components/Items.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type Props = ListProps & {
*/
items: Array<any>,

/**
* The number of cards to display per row in the grid view.
*/
itemsPerRow?: number,

/**
* If true, the list items will be formatted as a link.
*/
Expand Down Expand Up @@ -270,6 +275,7 @@ class ItemsClass extends Component<Props, {}> {
icon={action.resolveIcon ? action.resolveIcon(item) : action.icon}
key={actionIndex}
onClick={action.onClick.bind(this, item)}
size={action.size}
/>
))}
{ this.isSelectable() && (
Expand Down Expand Up @@ -346,7 +352,9 @@ class ItemsClass extends Component<Props, {}> {
}

return (
<Card.Group>
<Card.Group
itemsPerRow={this.props.itemsPerRow}
>
{ _.map(this.props.items, this.renderCard.bind(this)) }
</Card.Group>
);
Expand Down Expand Up @@ -403,6 +411,7 @@ class ItemsClass extends Component<Props, {}> {
key={actionIndex}
icon={action.resolveIcon ? action.resolveIcon(item) : action.icon}
onClick={action.onClick.bind(this, item)}
size={action.size}
/>
))}
</Item.Content>
Expand Down
5 changes: 0 additions & 5 deletions packages/semantic-ui/src/components/ListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import useDataList, { SORT_ASCENDING, SORT_DESCENDING, type Props as DataListPro
import './ListTable.css';

type Props = DataListProps & DataTableProps & {
/**
* If true, columns can be shown/hidden by the user.
*/
configurable?: boolean,

/**
* The name of the default sort column.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/shared-components",
"version": "1.1.0",
"version": "1.1.1",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./build/index.js",
Expand Down
38 changes: 38 additions & 0 deletions packages/storybook/src/semantic-ui/AssociatedDropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,41 @@ export const FormField = () => (
</Form.Input>
</Form>
);

export const CustomButtons = () => (
<AssociatedDropdown
buttons={[{
name: 'edit',
icon: 'edit'
}, {
basic: false,
color: 'orange',
name: 'add',
icon: 'coffee'
}, {
name: 'clear',
content: 'Clear Value!'
}]}
collectionName='items'
modal={{
component: AddModal,
props: {
onInitialize: () => Promise.resolve({ })
},
onSave: () => {
action('save')();
return Promise.resolve({});
}
}}
onSearch={(search) => Api.onLoad({ items, search, sort_by: 'text' })}
onSelection={action('selection')}
placeholder={text('Placeholder', 'Search')}
renderOption={(item) => ({
key: item.id,
value: item.id,
text: item.company,
description: item.country
})}
upward={boolean('Open upward', false)}
/>
);
11 changes: 11 additions & 0 deletions packages/storybook/src/semantic-ui/EmbeddedList.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,14 @@ export const TabbedModalConfig = useDragDrop(() => {
</Container>
);
});

export const NoColumnSelector = useDragDrop(() => (
<EmbeddedList
actions={actions}
configurable={false}
onDelete={action('delete')}
columns={columns}
items={items}
showRecordCount
/>
));
25 changes: 25 additions & 0 deletions packages/storybook/src/semantic-ui/Items.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,28 @@ export const Pagination = useDragDrop(() => (
renderMeta={(item) => item.id}
/>
));

export const ItemsPerRow = useDragDrop(() => (
<Items
actions={actions}
items={items}
itemsPerRow={2}
onCopy={action('copy')}
onDelete={action('delete')}
renderImage={(item) => <Image alt={item.image_alt} src={item.image} />}
renderHeader={(item) => <Header content={item.header} />}
renderMeta={(item) => item.id}
/>
));

export const ButtonSize = useDragDrop(() => (
<Items
actions={_.map(actions, (a) => ({ ...a, size: 'mini' }))}
items={items}
onCopy={action('copy')}
onDelete={action('delete')}
renderImage={(item) => <Image alt={item.image_alt} src={item.image} />}
renderHeader={(item) => <Header content={item.header} />}
renderMeta={(item) => item.id}
/>
));
17 changes: 17 additions & 0 deletions packages/storybook/src/semantic-ui/ListTable.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,20 @@ export const SortDescending = useDragDrop(() => (
searchable={boolean('Searchable', true)}
/>
));

export const NoColumnSelector = useDragDrop(() => (
<ListTable
actions={actions}
collectionName='items'
columns={columns}
configurable={false}
onCopy={action('copy')}
onLoad={(params) => Api.onLoad(_.extend(params, {
items,
perPage: number('Per page', 10)
}))}
onDelete={action('delete')}
onSave={action('save')}
searchable={boolean('Searchable', true)}
/>
));
6 changes: 3 additions & 3 deletions packages/user-defined-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/user-defined-fields",
"version": "1.1.0",
"version": "1.1.1",
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -9,8 +9,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^1.1.0",
"@performant-software/shared-components": "^1.1.0",
"@performant-software/semantic-components": "^1.1.1",
"@performant-software/shared-components": "^1.1.1",
"i18next": "^21.9.1",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/visualize",
"version": "1.1.0",
"version": "1.1.1",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./build/index.js",
Expand Down
2 changes: 1 addition & 1 deletion react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "1.1.0"
"version": "1.1.1"
}

0 comments on commit 104607c

Please sign in to comment.