Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/table 2 #170

Merged
merged 98 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
bebfc08
add preview
rinrub Dec 8, 2023
1f3ef62
changelog
rinrub Dec 8, 2023
42312d4
table-hn2
rinrub Dec 21, 2023
a9ff24e
table-hn2 display, sorting
rinrub Dec 30, 2023
5a738b7
get values from datareciver as string for table
rinrub Jan 1, 2024
275a357
started on enable when
rinrub Jan 1, 2024
d7f7b7d
hn1-table
rinrub Jan 2, 2024
75e7350
table-hn1 and table-hn2
rinrub Jan 5, 2024
77ff0f8
updated changes and version in package.json
rinrub Jan 5, 2024
1fcb85f
version
rinrub Jan 5, 2024
fb9e8ed
version
rinrub Jan 5, 2024
6c1231b
fixed missing mock in tests
rinrub Jan 6, 2024
c3f48b2
Tests for table
rinrub Jan 9, 2024
f999710
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Jan 9, 2024
9678bff
Merge remote-tracking branch 'origin/feature/table' into rubenr/table…
rinrub Jan 9, 2024
bf9cd06
install
rinrub Jan 9, 2024
af32e84
table-hn2
rinrub Dec 21, 2023
b427c99
table-hn2 display, sorting
rinrub Dec 30, 2023
ae85fc8
get values from datareciver as string for table
rinrub Jan 1, 2024
999b771
started on enable when
rinrub Jan 1, 2024
73f11ff
hn1-table
rinrub Jan 2, 2024
f8997f6
table-hn1 and table-hn2
rinrub Jan 5, 2024
0e51453
updated changes and version in package.json
rinrub Jan 5, 2024
16a3810
version
rinrub Jan 5, 2024
f170f7a
version
rinrub Jan 5, 2024
4302d44
fixed missing mock in tests
rinrub Jan 6, 2024
bb941c4
Tests for table
rinrub Jan 9, 2024
dd24f79
install
rinrub Jan 9, 2024
02fde3d
gtable
rinrub Jan 10, 2024
333da51
Merge branch 'rubenr/table-hn2-v2' of https://github.com/helsenorge/r…
rinrub Jan 10, 2024
a12281a
gtable
rinrub Jan 10, 2024
cd8120d
Update utils.ts
rinrub Jan 10, 2024
ce50f03
added basic gtable functionality
rinrub Jan 10, 2024
1c8e73e
version and changes
rinrub Jan 10, 2024
7a067be
testfile and return correct answers
rinrub Jan 10, 2024
228ca70
add tests
rinrub Jan 11, 2024
8bfda86
remove todo
rinrub Jan 11, 2024
0a91aba
added functionality for table
rinrub Jan 16, 2024
79ab8b1
updated version
rinrub Jan 16, 2024
22b65e1
bump version
rinrub Jan 16, 2024
879bcfe
fix tests
rinrub Jan 16, 2024
19290f4
version
rinrub Jan 16, 2024
9e89e82
fix quantity and gtable
rinrub Jan 17, 2024
f83dee7
fixed showing different types correct and added some sugar
rinrub Jan 17, 2024
eabc740
version
rinrub Jan 17, 2024
fe2e884
changed the test to reflect changes in code
rinrub Jan 17, 2024
dc4bd62
test update
rinrub Jan 17, 2024
830cd42
create union type for response item and item
rinrub Jan 18, 2024
c699792
fix hn2-bug
rinrub Jan 18, 2024
4e7e9db
fixed date format
rinrub Jan 18, 2024
9298b59
v 13.2.4-beta06
rinrub Jan 19, 2024
42a8aae
fix-test
rinrub Jan 19, 2024
b1ab7c8
version
rinrub Jan 19, 2024
327f6f5
version
rinrub Jan 19, 2024
ae39b6c
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Jan 19, 2024
4755ad0
merged from new major version from master
rinrub Jan 19, 2024
761ba5e
sorting for standardtable
rinrub Jan 22, 2024
f8a1a6d
fix test types and move some code
rinrub Jan 22, 2024
050d5c8
update gtable
rinrub Jan 22, 2024
bf4194f
g-table
rinrub Jan 23, 2024
03ab939
sorting on gtable
rinrub Jan 24, 2024
83dfc7b
move header to its own file
rinrub Jan 24, 2024
2ff4224
added version and changelog
rinrub Jan 24, 2024
e66a379
removed extra singlequoutes from answer
rinrub Jan 25, 2024
1dc0edc
remove schema
rinrub Jan 25, 2024
ee0bd1d
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Jan 25, 2024
bce0cb2
version
rinrub Jan 25, 2024
1be2181
breakline after tables
rinrub Feb 8, 2024
dc54d67
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Feb 8, 2024
ae32138
merge
rinrub Feb 8, 2024
d7d2eb5
Merge remote-tracking branch 'origin/feature/table' into rubenr/small…
rinrub Feb 8, 2024
4232879
fix import
rinrub Feb 8, 2024
9b1db0a
Merge remote-tracking branch 'origin/feature/table' into rubenr/small…
rinrub Feb 8, 2024
fb39903
sorting gtable
rinrub Feb 9, 2024
fa5d809
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Feb 9, 2024
a0795d9
Merge remote-tracking branch 'origin/feature/table' into rubenr/small…
rinrub Feb 9, 2024
c2f3635
updated the sort function with the common function for sorting by table
rinrub Feb 9, 2024
8f21f16
fixes
rinrub Feb 11, 2024
c9695de
standard table
rinrub Feb 12, 2024
c2dacd1
fix tests
rinrub Feb 12, 2024
1a5e6fb
Merge remote-tracking branch 'origin/master' into feature/table
rinrub Feb 13, 2024
f60e56c
bump-version
rinrub Feb 13, 2024
f2b3f9e
fix calculated values in tables
rinrub Feb 14, 2024
6dcfa16
release version
rinrub Feb 14, 2024
a8aa660
added undefined checks for sorting on gtable
rinrub Feb 15, 2024
cef1dba
fix sorting of different item.type
rinrub Feb 16, 2024
eecc2d6
release-14.1.0-beta03
rinrub Feb 16, 2024
e30751a
Merge remote-tracking branch 'origin/master' into feature/table-2
rinrub Feb 20, 2024
1d76a1e
Package 14.1.0 table view
AG-83 Feb 26, 2024
15191e5
Merge remote-tracking branch 'origin/master' into feature/table-2
rinrub Feb 26, 2024
9e19892
Merge branch 'feature/table-2' of https://github.com/helsenorge/refer…
rinrub Feb 26, 2024
b6e657f
added datalables, changed the setup of th and td
rinrub Feb 27, 2024
2d0e0de
Merge remote-tracking branch 'origin/master' into feature/table-2
rinrub Feb 27, 2024
49e2b21
updated refero with new tables, aslo preview mode for development
rinrub Feb 27, 2024
4fec148
chagnes
rinrub Feb 27, 2024
ed03a0a
update changelog
rinrub Feb 27, 2024
31a318d
cleaned up the changes frile
rinrub Feb 27, 2024
cdba952
removed beta tags and cleand up
rinrub Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"titleBar.inactiveForeground": "#15202b99",
"statusBar.background": "#5dc9e2",
"statusBarItem.hoverBackground": "#32bbda",
"statusBar.foreground": "#15202b"
"statusBar.foreground": "#15202b",
"activityBar.activeBackground": "#88d7ea",
"commandCenter.border": "#15202b99",
"sash.hoverBorder": "#88d7ea",
"statusBarItem.remoteBackground": "#5dc9e2",
"statusBarItem.remoteForeground": "#15202b"
},
"peacock.color": "#5dc9e2",
"eslint.runtime": "node"
Expand Down
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 15.0.0

---

- Has possibility to display summary as table. Can support types Table, Table-HN1, Table-HN2 and GTable
- Support for ordering in GTable, Table-HN2 og Table

ruberino marked this conversation as resolved.
Show resolved Hide resolved
- Preview mode for development with vite.

## 14.0.10

---
Expand Down
2 changes: 1 addition & 1 deletion config/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"importHelpers": true
},
"include": ["../src/**/*.tsx", "../src/**/*.ts"],
"exclude": ["../**/node_modules", "../src/**/__tests__*", "../lib/**/*.*"]
"exclude": ["../**/node_modules", "../src/**/__tests__*", "../lib/**/*.*", "../src/preview"]
}
2 changes: 1 addition & 1 deletion config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"importHelpers": true
},
"include": ["../src/**/*.tsx", "../src/**/*.ts"],
"exclude": ["../**/node_modules", "../src/**/__tests__*", "../lib/**/*.*"]
"exclude": ["../**/node_modules", "../src/**/__tests__*", "../lib/**/*.*", "../src/preview"]
}
2,367 changes: 1,949 additions & 418 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helsenorge/refero",
"version": "14.0.10",
"version": "15.0.0",
"engines": {
"node": "^18.0.0",
"npm": ">=9.0.0"
Expand All @@ -22,7 +22,8 @@
"build:lib": "npm-run-all build:js build:copy-files",
"prebuild:lib": "rimraf lib",
"prepare": "npm run build:lib",
"test": "jest --config config/jest.config.js"
"test": "jest --config config/jest.config.js",
"dev": "vite"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -118,9 +119,14 @@
"rimraf": "^3.0.2",
"tabbable": "^6.2.0",
"typescript": "^4.8.3",
"vite": "^4.4.5",
"vite-plugin-require": "^1.1.13",
"vite-tsconfig-paths": "^4.2.1",
"whatwg-fetch": "^2.0.4",
"xml2js": "^0.6.2",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"@vitejs/plugin-react": "^4.2.1",
"sass": "^1.69.0"
},
"dependencies": {
"@types/react-collapse": "^5.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/formcomponents/date/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import moment, { Moment } from 'moment';
import { connect } from 'react-redux';
import { ThunkDispatch } from 'redux-thunk';


import { LanguageLocales } from '@helsenorge/core-utils/constants/languages';
import { DateRangePicker } from '@helsenorge/date-time/components/date-range-picker';
import { parseDate } from '@helsenorge/date-time/components/time-input/date-core';
Expand Down
2 changes: 1 addition & 1 deletion src/components/formcomponents/date/time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ThunkDispatch } from 'redux-thunk';

import TimeInput from '@helsenorge/date-time/components/time-input';
import { parseDate } from '@helsenorge/date-time/components/time-input/date-core';
import DateTimeConstants from '@helsenorge/date-time/constants/datetime';
import * as DateTimeConstants from '@helsenorge/date-time/constants/datetime';
import { ValidationProps } from '@helsenorge/form/components/form/validation';
import Validation from '@helsenorge/form/components/form/validation';

Expand Down
11 changes: 11 additions & 0 deletions src/components/formcomponents/group/AsPdf.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { ReactNode } from 'react';

type Props = {
pdf: boolean;
children: ReactNode;
};

const AsPdf = ({ pdf, children }: Props): JSX.Element => {
return <>{pdf ? <div>{children}</div> : children}</>;
};
export default AsPdf;
149 changes: 46 additions & 103 deletions src/components/formcomponents/group/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { ThunkDispatch } from 'redux-thunk';

import AnchorLink from '@helsenorge/designsystem-react/components/AnchorLink';

import AsPdf from './AsPdf';
import { getClassNames, getColumns, getHeaderText, getLocalRenderContextType, isDirectChildOfRenderContextOwner } from './helpers';
import { NewValueAction } from '../../../actions/newValue';
import { RenderContextType } from '../../../constants/renderContextType';
import { GlobalState } from '../../../reducers';
import { getGroupItemControl } from '../../../util/group-item-control';
import { renderPrefix, getText, getId } from '../../../util/index';
import { getText, getId } from '../../../util/index';
import { mapStateToProps, mergeProps, mapDispatchToProps } from '../../../util/map-props';
import { Path } from '../../../util/refero-core';
import { RenderContext } from '../../../util/renderContext';
Expand Down Expand Up @@ -48,7 +49,6 @@ export class Group extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
}

shouldComponentUpdate(nextProps: Props): boolean {
const responseItemHasChanged = this.props.responseItem !== nextProps.responseItem;
const helpItemHasChanged = this.props.isHelpOpen !== nextProps.isHelpOpen;
Expand All @@ -57,7 +57,6 @@ export class Group extends React.Component<Props, State> {
const resourcesHasChanged = JSON.stringify(this.props.resources) !== JSON.stringify(nextProps.resources);

const repeats = this.props.item.repeats ?? false;

return (
responseItemHasChanged ||
helpItemHasChanged ||
Expand All @@ -68,9 +67,9 @@ export class Group extends React.Component<Props, State> {
);
}

renderAllItems = (): JSX.Element => {
const { renderContext } = this.props;
const localRenderContextType = this.getLocalRenderContextType();
renderAllItems = (item: QuestionnaireItem): JSX.Element => {
const { path, renderContext } = this.props;
const localRenderContextType = getLocalRenderContextType(item);

if (localRenderContextType) {
switch (localRenderContextType) {
Expand All @@ -81,24 +80,12 @@ export class Group extends React.Component<Props, State> {

switch (renderContext.RenderContextType) {
case RenderContextType.Grid:
return this.isDirectChildOfRenderContextOwner() ? this.renderContextTypeGridRow() : this.renderGroup();
return isDirectChildOfRenderContextOwner(path, item, renderContext) ? this.renderContextTypeGridRow() : this.renderGroup();
default:
return this.renderGroup();
}
};

isDirectChildOfRenderContextOwner = (): boolean => {
const { path, item, renderContext } = this.props;

const myIndex = path.findIndex(p => p.linkId === item.linkId);
if (myIndex > 0) {
const directParentLinkId = path[myIndex - 1].linkId;
return directParentLinkId === renderContext.Owner;
}

return false;
};

renderContextTypeGridRow = (): JSX.Element => {
const { renderContext, item } = this.props;

Expand Down Expand Up @@ -136,125 +123,81 @@ export class Group extends React.Component<Props, State> {
};

renderContextTypeGrid = (): JSX.Element => {
const { item } = this.props;
const { item, renderChildrenItems, repeatButton, renderDeleteButton, id } = this.props;

const columns = this.getColumns();
const columns = getColumns(item);
const headers = columns.map(c => <th key={item.linkId + '-' + c}>{c}</th>);
headers.unshift(<th key={item.linkId + 'X'}>{item.text ? item.text : ''}</th>);

const newRenderContext = new RenderContext(RenderContextType.Grid, item.linkId, columns);
return (
<React.Fragment>
<table id={getId(this.props.id)} className="page_refero__grid">
<>
<table id={getId(id)} className="page_refero__grid">
<thead>
<tr>{headers}</tr>
</thead>
<tbody>{this.props.renderChildrenItems(newRenderContext)}</tbody>
<tbody>{renderChildrenItems(newRenderContext)}</tbody>
</table>
{this.props.renderDeleteButton('page_refero__deletebutton--margin-top')}
{this.props.repeatButton}
</React.Fragment>
{renderDeleteButton('page_refero__deletebutton--margin-top')}
{repeatButton}
</>
);
};

renderGroup = (): JSX.Element => {
const {
repeatButton,
id,
includeSkipLink,
path,
renderDeleteButton,
item,
questionnaire,
onRenderMarkdown,
resources,
renderHelpElement,
renderChildrenItems,
} = this.props;
return (
<section id={getId(this.props.id)} data-sectionname={this.getHeaderText()}>
<section id={getId(this.props.id)} data-sectionname={getHeaderText(item, questionnaire, resources, onRenderMarkdown)}>
{this.renderGroupHeader()}
{this.props.renderHelpElement()}
<div id={`${getId(this.props.id)}-navanchor`} className={this.getClassNames()}>
{this.props.renderChildrenItems(new RenderContext())}
{renderHelpElement()}
<div id={`${getId(id)}-navanchor`} className={getClassNames(item)}>
{renderChildrenItems(new RenderContext())}
</div>
{this.props.includeSkipLink && this.props.path.length === 1 && (
{includeSkipLink && path.length === 1 && (
<AnchorLink className="page_refero__skiplink" href="#navigator-button">
{this.props.resources?.skipLinkText}
{resources?.skipLinkText}
</AnchorLink>
)}
{this.props.renderDeleteButton('page_refero__deletebutton--margin-top')}
{this.props.repeatButton}
{renderDeleteButton('page_refero__deletebutton--margin-top')}
{repeatButton}
</section>
);
};

getColumns = (): Array<string> => {
const item = this.props.item;
const seenColumns = {};
const columns: Array<string> = [];
if (!item.item || item.item.length === 0) return columns;
for (const group of item.item) {
if (group.item && group.item.length > 0) {
for (const cell of group.item) {
const key = cell.text || '';
if (key in seenColumns) continue;

columns.push(key);
seenColumns[key] = 1;
}
}
}

return columns;
};

getLocalRenderContextType = (): RenderContextType => {
const coding = getGroupItemControl(this.props.item);
if (coding.length > 0) {
switch (coding[0].code) {
case 'grid':
return RenderContextType.Grid;
}
}
return RenderContextType.None;
};

getClassNames = (): string => {
const classNames = ['page_refero__component', 'page_refero__component_group'];
const coding = getGroupItemControl(this.props.item);
if (coding.length > 0) {
classNames.push('page_refero__itemControl_' + coding[0].code);
}

return classNames.join(' ');
};

getComponentToValidate = (): undefined => {
return undefined;
};

getHeaderText = (): string => {
return (
renderPrefix(this.props.item) +
' ' +
getText(this.props.item, this.props.onRenderMarkdown, this.props.questionnaire, this.props.resources)
);
};

renderGroupHeader = (): JSX.Element | null => {
if (!getText(this.props.item, this.props.onRenderMarkdown)) {
const { item, questionnaire, onRenderMarkdown, resources, headerTag, renderHelpButton } = this.props;

if (!getText(item, onRenderMarkdown)) {
return null;
}

const HeaderTag = `h${this.props.headerTag}` as 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
const headerText = DOMPurify.sanitize(this.getHeaderText(), {
const HeaderTag = `h${headerTag}` as 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
const headerText = DOMPurify.sanitize(getHeaderText(item, questionnaire, resources, onRenderMarkdown), {
RETURN_TRUSTED_TYPE: true,
ADD_ATTR: ['target'],
}) as unknown as string;
return (
<React.Fragment>
<>
<HeaderTag className={'page_refero__heading'} dangerouslySetInnerHTML={{ __html: headerText }} />
{this.props.renderHelpButton()}
</React.Fragment>
{renderHelpButton()}
</>
);
};

render(): JSX.Element | null {
const { pdf } = this.props;

if (pdf) {
return <div>{this.renderAllItems()}</div>;
}

return this.renderAllItems();
const { pdf, item } = this.props;
return <AsPdf pdf={!!pdf}>{this.renderAllItems(item)}</AsPdf>;
}
}
const withCommonFunctionsComponent = withCommonFunctions(Group);
Expand Down
Loading
Loading