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

Widget state persistance #4574

Merged
merged 19 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion scripts/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const debugInfo = {
translationsLoaded: false,
};

export let authoringReactEnabledUserSelection = (JSON.parse(localStorage.getItem('auth-react') ?? 'false') as boolean);
export let authoringReactEnabledUserSelection = true;
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved

export function toggleAuthoringReact(enabled: boolean) {
localStorage.setItem('auth-react', JSON.stringify(enabled));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/* eslint-disable react/no-multi-comp */
import React from 'react';
import {IArticleSideWidget, IComment, IExtensionActivationResult, IRestApiResponse} from 'superdesk-api';
import {IArticleSideWidget, IArticleSideWidgetComponentType, IComment, IRestApiResponse} from 'superdesk-api';
import {gettext} from 'core/utils';
import CommentsWidget from '../../generic-widgets/comments/CommentsWidget';
import {httpRequestJsonLocal} from 'core/helpers/network';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Comments');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class Component extends React.PureComponent<IProps> {
class Component extends React.PureComponent<IArticleSideWidgetComponentType> {
render() {
return (
<CommentsWidget
Expand Down
8 changes: 2 additions & 6 deletions scripts/apps/authoring-react/article-widgets/demo-widget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {IArticleSideWidget, IArticle, IExtensionActivationResult} from 'superdesk-api';
import {IArticleSideWidget, IArticle, IExtensionActivationResult, IArticleSideWidgetComponentType} from 'superdesk-api';
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
import {Button} from 'superdesk-ui-framework';
import {sdApi} from 'api';
import {gettext} from 'core/utils';
Expand All @@ -9,11 +9,7 @@ import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Demo widget');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class DemoWidget extends React.PureComponent<IProps> {
class DemoWidget extends React.PureComponent<IArticleSideWidgetComponentType> {
render() {
return (
<AuthoringWidgetLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {IArticleSideWidget, IArticle, IExtensionActivationResult} from 'superdesk-api';
import {IArticleSideWidget, IArticleSideWidgetComponentType} from 'superdesk-api';
import {gettext} from 'core/utils';
import {AuthoringWidgetHeading} from 'apps/dashboard/widget-heading';
import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';
Expand All @@ -11,10 +11,6 @@ import {throttle} from 'lodash';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Find and Replace');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

interface IState {
findValue: string;
replaceValue: string;
Expand All @@ -26,13 +22,13 @@ interface IState {
*/
export const editorId = 'body_html';

class FindAndReplaceWidget extends React.PureComponent<IProps, IState> {
class FindAndReplaceWidget extends React.PureComponent<IArticleSideWidgetComponentType, IState> {
private scheduleHighlightingOfMatches: () => void;

constructor(props: IProps) {
constructor(props: IArticleSideWidgetComponentType) {
super(props);

this.state = {
this.state = this.props.initialState ?? {
findValue: '',
replaceValue: '',
caseSensitive: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
/* eslint-disable react/no-multi-comp */

import React from 'react';
import {IArticleSideWidget, IExtensionActivationResult, IArticle} from 'superdesk-api';
import {IArticleSideWidget, IExtensionActivationResult, IArticle, IArticleSideWidgetComponentType} from 'superdesk-api';
import {gettext} from 'core/utils';
import {InlineCommentsWidget} from '../generic-widgets/inline-comments';

// Can't call `gettext` in the top level
const getLabel = () => gettext('Inline comments');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class InlineCommentsWidgetWrapper extends React.PureComponent<IProps> {
class InlineCommentsWidgetWrapper extends React.PureComponent<IArticleSideWidgetComponentType> {
render() {
return (
<InlineCommentsWidget<IArticle>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Fragment} from 'react';
import {IArticleSideWidget, IExtensionActivationResult, IVocabularyItem} from 'superdesk-api';
import {IArticleSideWidget, IArticleSideWidgetComponentType} from 'superdesk-api';
import {gettext} from 'core/utils';
import {AuthoringWidgetHeading} from 'apps/dashboard/widget-heading';
import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';
Expand All @@ -18,16 +18,12 @@ import {AnnotationsPreview} from './AnnotationsPreview';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Metadata');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

interface IState {
languages: Array<ILanguage>;
}

class MetadataWidget extends React.PureComponent<IProps, IState> {
constructor(props: IProps) {
class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType, IState> {
constructor(props: IArticleSideWidgetComponentType) {
super(props);

this.state = {
Expand Down
10 changes: 3 additions & 7 deletions scripts/apps/authoring-react/article-widgets/suggestions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/no-multi-comp */

import React from 'react';
import {IArticleSideWidget, IExtensionActivationResult, IUser, IEditor3ValueOperational} from 'superdesk-api';
import {IArticleSideWidget, IUser, IEditor3ValueOperational, IArticleSideWidgetComponentType} from 'superdesk-api';
import {gettext} from 'core/utils';
import {AuthoringWidgetHeading} from 'apps/dashboard/widget-heading';
import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';
Expand All @@ -17,10 +17,6 @@ import {getLocalizedTypeText} from 'apps/authoring/track-changes/suggestions';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Resolved suggestions');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

interface ISuggestion {
resolutionInfo: {
accepted: boolean;
Expand Down Expand Up @@ -139,8 +135,8 @@ class Suggestion extends React.PureComponent<{suggestion: ISuggestion}> {
}
}

class SuggestionsWidget extends React.PureComponent<IProps> {
constructor(props: IProps) {
class SuggestionsWidget extends React.PureComponent<IArticleSideWidgetComponentType> {
constructor(props: IArticleSideWidgetComponentType) {
super(props);

this.getEditor3Fields = this.getEditor3Fields.bind(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import {RelativeDate} from 'core/datetime/relativeDate';
import {state as State} from 'apps/search/components/fields/state';
import {IArticle, IArticleSideWidget, IExtensionActivationResult} from 'superdesk-api';
import {IArticle, IArticleSideWidget, IArticleSideWidgetComponentType, IExtensionActivationResult} from 'superdesk-api';
import {gettext} from 'core/utils';
import {openArticle} from 'core/get-superdesk-api-implementation';
import {AuthoringWidgetLayout} from 'apps/dashboard/widget-layout';
Expand All @@ -13,11 +13,7 @@ import {TranslationsBody} from './TranslationsBody';

const getLabel = () => gettext('Translations');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

class Translations extends React.Component<IProps> {
class Translations extends React.Component<IArticleSideWidgetComponentType> {
render() {
return (
<AuthoringWidgetLayout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {
IArticleSideWidget,
IArticleSideWidgetComponentType,
IExtensionActivationResult,
} from 'superdesk-api';
import {gettext} from 'core/utils';
Expand All @@ -14,16 +15,12 @@ import {VersionsTab} from './versions-tab';
// Can't call `gettext` in the top level
const getLabel = () => gettext('Versions and item history');

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

interface IState {
selectedTab: 'versions' | 'history';
}

class VersionsAndItemHistoryWidget extends React.PureComponent<IProps, IState> {
constructor(props: IProps) {
class VersionsAndItemHistoryWidget extends React.PureComponent<IArticleSideWidgetComponentType, IState> {
constructor(props: IArticleSideWidgetComponentType) {
super(props);

this.state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IRestApiResponse,
IDesk,
IStage,
IArticleSideWidgetComponentType,
} from 'superdesk-api';
import {gettext, getArticleLabel} from 'core/utils';
import {httpRequestJsonLocal} from 'core/helpers/network';
Expand All @@ -32,19 +33,15 @@ const loadingState: IState = {
selectedForComparison: {from: null, to: null},
};

type IProps = React.ComponentProps<
IExtensionActivationResult['contributions']['authoringSideWidgets'][0]['component']
>;

interface IState {
versions: Array<IArticle> | 'loading';
desks: Map<string, IDesk>;
stages: Map<string, IStage>;
selectedForComparison?: {from: IArticle; to: IArticle};
}

export class VersionsTab extends React.PureComponent<IProps, IState> {
constructor(props: IProps) {
export class VersionsTab extends React.PureComponent<IArticleSideWidgetComponentType, IState> {
constructor(props: IArticleSideWidgetComponentType) {
super(props);

this.state = loadingState;
Expand Down
Loading
Loading