Skip to content

Commit

Permalink
feat(labels, list): Fixed labels and drag handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovicnemanja committed Oct 15, 2024
1 parent fb24b75 commit 49e3b77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
12 changes: 6 additions & 6 deletions client/components/ContentLists/Manual/ArticleItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ const ArticleItem = ({
) : null}
</span>

{item.route && item.route.name &&
{item.route?.name && (
<Label
text={item.route && item.route.name}
text={item.route.name}
type="success"
style="hollow"
/>
}
{item.status === 'new' &&
)}
{item.status && item.status !== 'published' && (
<Label
text={"Non published"}
text={item.status === 'new' ? "Non published" : item.status}
type="warning"
style="hollow"
/>
}
)}
{item.sticky && <Label text="pinned" type="alert" style="hollow" />}
</div>
</div>
Expand Down
53 changes: 25 additions & 28 deletions client/components/ContentLists/Manual/Manual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class Manual extends React.Component {
body: body_html,
title: headline,
published_at: versioncreated,
route: { name: state.replace('_', ' ') },
status: this.state.source && this.state.source.label,
// status: state.replace('_', ' '),
associations
})
);
Expand Down Expand Up @@ -333,7 +334,7 @@ class Manual extends React.Component {
}

handleSourceChange = (source) => {
if (source && (source.id === 'scheduled' || source.id === 'in_progress')) {
if (source && (source.id === 'scheduled' || source.id === 'in_progress')) {
this._querySuperdeskArticles(source.id, true);
} else {
this._queryArticles(true);
Expand Down Expand Up @@ -454,13 +455,13 @@ class Manual extends React.Component {

getIndexInList = (list, draggableId) => {
let ids = draggableId.split('_');
let id = this.state.source && this.state.source.id === 'superdesk' ?
let id = this.state.source && (this.state.source.id === 'scheduled' || this.state.source.id === 'in_progress') ?
ids[ids.length - 1] : parseInt(ids[ids.length - 1]);

return list.findIndex(item => ids.length > 2 ? item.content.id === id : item.id === id);
}

onDragEnd = async (result) => {
onDragEnd = (result) => {
const { source, destination, draggableId } = result;

// dropped outside the list
Expand All @@ -469,28 +470,7 @@ class Manual extends React.Component {
}

let list = { ...this.state.list };
if (this.state.source && (this.state.source.id === 'scheduled' || this.state.source.id === 'in_progress')) {
const item_id = draggableId.replace('draggable_', '');

list.loading = true;
this.setState({ list });

await this.publishItemFromSuperdesk(item_id).then((res) => {
let changesRecord = [...this.state.changesRecord];
changesRecord = changesRecord.map((change) => {
if (change.content_id === item_id) {
change.content_id = res.id;
}
return change;
});

list.loading = false;

this.setState({ changesRecord });
});
}

list.loading = false;
list.loading = true;

if (source.droppableId === destination.droppableId) {
let items = reorder(
Expand Down Expand Up @@ -523,6 +503,23 @@ class Manual extends React.Component {
articles,
});
}

if (this.state.source && (this.state.source.id === 'scheduled' || this.state.source.id === 'in_progress')) {
const item_id = draggableId.replace('draggable_', '');

this.publishItemFromSuperdesk(item_id).then((res) => {
let changesRecord = [...this.state.changesRecord];
changesRecord = changesRecord.map((change) => {
if (change.content_id === item_id) {
change.content_id = res.id;
}
return change;
});

list.loading = false;
this.setState({ list });
});
}
};

fixPinnedItemsPosition = (items) => {
Expand Down Expand Up @@ -772,8 +769,8 @@ class Manual extends React.Component {
/>
<SourceSelect
sources={[
{ id: 'scheduled', name: 'Scheduled Articles' },
{ id: 'in_progress', name: 'Articles in progress' },
{ id: 'scheduled', name: 'Scheduled Articles', label: 'Non published' },
{ id: 'in_progress', name: 'Articles in progress', label: 'Non published' },
]}
selectedSource={this.state.source}
setSource={(source) => {
Expand Down

0 comments on commit 49e3b77

Please sign in to comment.