Skip to content

Commit

Permalink
feat: generic function to retrieve a pending form change for a user
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Mar 9, 2022
1 parent e9dd666 commit 91bacac
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/pages/cif/operators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const OperatorsQuery = graphql`
session {
...DefaultLayout_session
}
allOperators(
first: $pageSize
offset: $offset
Expand All @@ -42,6 +41,11 @@ export const OperatorsQuery = graphql`
}
}
}
pendingNewOperatorFormChange: pendingNewFormChangeForTable(
tablename: "operator"
) {
id
}
}
`;

Expand All @@ -56,10 +60,8 @@ const tableFilters = [
export function Operators({ preloadedQuery }: RelayProps<{}, operatorsQuery>) {
// const router = useRouter();

const { allOperators, session } = usePreloadedQuery(
OperatorsQuery,
preloadedQuery
);
const { allOperators, session, pendingNewOperatorFormChange } =
usePreloadedQuery(OperatorsQuery, preloadedQuery);

const addNewOperator = async () => {
// TODO Implement Create Operator
Expand All @@ -69,15 +71,17 @@ export function Operators({ preloadedQuery }: RelayProps<{}, operatorsQuery>) {
console.log("Implement Create Operator");
};

const createOrResumeButton = pendingNewOperatorFormChange ? (
<Button onClick={() => {}}>Resume Contact Creation</Button>
) : (
<Button onClick={addNewOperator}>Add an Operator</Button>
);

return (
<DefaultLayout session={session}>
<header>
<h2>CIF Operators</h2>
<section>
<Button role="button" onClick={addNewOperator}>
Add an Operator
</Button>
</section>
<section>{createOrResumeButton}</section>
</header>

<Table
Expand Down
5 changes: 5 additions & 0 deletions app/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31185,6 +31185,11 @@ type Query implements Node {
"""
pendingNewContactFormChange: FormChange

"""
returns a form_change for a table in the pending state for the current user, i.e. allows to resume the creation of any table row
"""
pendingNewFormChangeForTable(tablename: String!): FormChange

"""
returns a project_revision for a new project in the pending state for the current user, i.e. allows to resume a project creation
"""
Expand Down
27 changes: 27 additions & 0 deletions app/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -107857,6 +107857,33 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pendingNewFormChangeForTable",
"description": "returns a form_change for a table in the pending state for the current user, i.e. allows to resume the creation of any table row",
"args": [
{
"name": "tablename",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "FormChange",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pendingNewProjectRevision",
"description": "returns a project_revision for a new project in the pending state for the current user, i.e. allows to resume a project creation",
Expand Down
18 changes: 18 additions & 0 deletions schema/deploy/functions/pending_new_form_change_for_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Deploy cif:functions/pending_new_form_change_for_table to pg

begin;

create function cif.pending_new_form_change_for_table(tableName text) returns cif.form_change as
$$
select * from cif.form_change
where form_data_table_name = quote_literal($1)
and form_data_schema_name = 'cif'
and operation = 'create'
and change_status = 'pending'
and created_by = (select id from cif.cif_user where uuid = (select sub from cif.session()))
limit 1;
$$ language 'sql' stable;

comment on function cif.pending_new_form_change_for_table(text) is
'returns a form_change for a table in the pending state for the current user, i.e. allows to resume the creation of any table row';
commit;
7 changes: 7 additions & 0 deletions schema/revert/functions/pending_new_form_change_for_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert cif:functions/pending_new_form_change_for_table from pg

begin;

drop function cif.pending_new_form_change_for_table(text);

commit;
1 change: 1 addition & 0 deletions schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ types/manager_form_changes_by_label_composite_return [schemas/main] 2022-02-18T2
computed_columns/project_revision_project_manager_form_changes_by_label [tables/project_revision tables/project_manager] 2022-02-18T21:32:45Z Dylan Leard <pierre.bastianelli@gov.bc.ca> # Computed column to retrieve the set of form changes related to the project manager association by project_manager_label, within a project revision
computed_columns/project_pending_project_revision 2022-02-16T17:14:03Z Matthieu Foucault <matthieu@button.is> # add a computed column to return a pending revision for a project
computed_columns/operator_pending_form_change 2022-02-16T21:48:38Z Pierre Bastianelli <pierre.bastianelli@gov.bc.ca> # A computed column returning a potential existing form change for an operator, scoped by the current user
functions/pending_new_form_change_for_table 2022-03-05T00:09:42Z Pierre Bastianelli <pierre.bastianelli@gov.bc.ca> # a custom query that returns a pending form change for the current user for a given table name. Allows to resume an object creation
7 changes: 7 additions & 0 deletions schema/verify/functions/pending_new_form_change_for_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify cif:functions/pending_new_form_change_for_table on pg

begin;

select pg_get_functiondef('cif.pending_new_form_change_for_table(text)'::regprocedure);

rollback;

0 comments on commit 91bacac

Please sign in to comment.